@240xu/dsh-message-ops 0.11.0 → 0.11.2

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/src/client.js CHANGED
@@ -30,6 +30,24 @@ window.__ModuleLoader__.load({
30
30
  const MSG_COALESCE_MS = 1000
31
31
  var __messagesMemo = { url: null, at: 0, p: null, settled: false }
32
32
  var invalidateMessagesMemo = () => { __messagesMemo = { url: null, at: 0, p: null, settled: false } }
33
+ const SYNTHETIC_TURN_STYLE_ID = 'dsh-message-ops-synthetic-turn-hide'
34
+ const syncSyntheticTurnStyle = (messages) => {
35
+ if (typeof document === 'undefined' || !document.head) return
36
+ const turns = new Set()
37
+ for (const m of messages || []) {
38
+ if (m && m.syntheticTurn === true && Number.isSafeInteger(m.turn)) turns.add(m.turn)
39
+ }
40
+ let tag = document.getElementById(SYNTHETIC_TURN_STYLE_ID)
41
+ if (turns.size === 0) { if (tag) tag.remove(); return }
42
+ if (!tag) {
43
+ tag = document.createElement('style')
44
+ tag.id = SYNTHETIC_TURN_STYLE_ID
45
+ document.head.appendChild(tag)
46
+ }
47
+ tag.textContent = Array.from(turns).map((turn) =>
48
+ '[data-chat-flow-kind="turn-process"][data-chat-turn="' + turn + '"]{display:none!important}'
49
+ ).join('\n')
50
+ }
33
51
  const emitChanged = () => {
34
52
  // 数据变了:连同本地缓存一起作废(否则 8s TTL 会让 openSession 后的
35
53
  // scan 拿旧 payload 重算隐藏 = 「回滚了但界面没变」)。
@@ -149,6 +167,16 @@ window.__ModuleLoader__.load({
149
167
  'panel.running': '会话正在运行:回滚、删除、分支需先停止。',
150
168
  'panel.revert': '回滚到此条',
151
169
  'panel.revertHint': '包含此条及其后的可见消息',
170
+ 'panel.revertConfirmTitle': '回滚到 #{seq}?',
171
+ 'panel.revertConfirmBody': '将遮蔽 #{start}–#{end} 的 {n} 条消息,其中可见 {v} 条;日志仍保留,可恢复。',
172
+ 'panel.deleteConfirmTitle': '仅删除 #{seq}?',
173
+ 'panel.deleteConfirmBody': '将遮蔽这 1 条消息,其他内容不动;日志仍保留,可恢复。',
174
+ 'panel.confirmRevert': '确认回滚',
175
+ 'panel.confirmDeleteOne': '确认删除',
176
+ 'panel.retry': '重试',
177
+ 'panel.searching': '搜索中…',
178
+ 'panel.deleteSessionImpact': '共 {n} 条消息;移入回收站后 7 天内可恢复。',
179
+ 'panel.deleteUnavailable': '会话信息尚未就绪,暂不能删除。',
152
180
  'panel.delete': '仅删除此条',
153
181
  'panel.deleteHint': '只遮蔽这一条,其他消息不动',
154
182
  'panel.branch': '从此条分支',
@@ -253,6 +281,16 @@ window.__ModuleLoader__.load({
253
281
  'panel.running': 'Session is running: stop it before revert, delete, or branch.',
254
282
  'panel.revert': 'Revert to here',
255
283
  'panel.revertHint': 'Includes this message and all visible messages after it',
284
+ 'panel.revertConfirmTitle': 'Revert to #{seq}?',
285
+ 'panel.revertConfirmBody': 'This shadows {n} messages (#{start}–#{end}), including {v} visible. The log stays append-only and can be restored.',
286
+ 'panel.deleteConfirmTitle': 'Delete only #{seq}?',
287
+ 'panel.deleteConfirmBody': 'This shadows this one message; everything else stays. The log stays append-only and can be restored.',
288
+ 'panel.confirmRevert': 'Confirm revert',
289
+ 'panel.confirmDeleteOne': 'Confirm delete',
290
+ 'panel.retry': 'Retry',
291
+ 'panel.searching': 'Searching…',
292
+ 'panel.deleteSessionImpact': 'Total {n} messages; recoverable from trash for 7 days.',
293
+ 'panel.deleteUnavailable': 'Session details are not ready yet; deletion is disabled.',
256
294
  'panel.delete': 'Delete only this',
257
295
  'panel.deleteHint': 'Shadows only this message',
258
296
  'panel.branch': 'Branch from here',
@@ -699,6 +737,15 @@ window.__ModuleLoader__.load({
699
737
  return 'S'
700
738
  }
701
739
 
740
+ function focusablesIn(root) {
741
+ if (!root || typeof root.querySelectorAll !== 'function') return []
742
+ const selector = 'button:not([disabled]),[href],input:not([disabled]),select:not([disabled]),textarea:not([disabled]),[tabindex]:not([tabindex="-1"])'
743
+ return Array.prototype.slice.call(root.querySelectorAll(selector)).filter((el) => {
744
+ if (el.getAttribute('aria-hidden') === 'true') return false
745
+ return el.offsetWidth > 0 || el.offsetHeight > 0 || el.getClientRects().length > 0
746
+ })
747
+ }
748
+
702
749
  function ensurePanelStyle() {
703
750
  try {
704
751
  if (document.getElementById('dsh-message-ops-panel-style')) return
@@ -727,7 +774,8 @@ window.__ModuleLoader__.load({
727
774
  '.mopsToggle{display:inline-flex;align-items:center;gap:5px;font-size:11px;color:var(--dsw-alias-label-secondary,#6b6b70);margin-left:auto;cursor:pointer}',
728
775
  '.mopsToggle input{accent-color:var(--dsw-alias-brand-primary,#4d6bfe)}',
729
776
  '.mopsList{flex:1;min-height:0;overflow-y:auto;position:relative;border-top:1px solid var(--dsw-alias-border-l1,#efefef)}',
730
- '.mopsRow{position:absolute;left:0;right:0;display:grid;grid-template-columns:44px 26px minmax(0,1fr) 48px;align-items:center;gap:8px;width:100%;border:0;border-bottom:1px solid var(--dsw-alias-border-l1,#f0f0f0);background:transparent;text-align:left;cursor:pointer;padding:0 12px 0 18px;color:inherit}',
777
+ '.mopsList:focus-visible{outline:2px solid var(--dsw-alias-brand-primary,#4d6bfe);outline-offset:-2px}',
778
+ '.mopsRow{position:absolute;left:0;right:0;display:grid;grid-template-columns:44px 26px minmax(0,1fr) 48px;align-items:center;gap:8px;width:100%;border:0;border-bottom:1px solid var(--dsw-alias-border-l1,#f0f0f0);background:transparent;text-align:left;cursor:pointer;padding:0 12px 0 18px;color:inherit;font:inherit}',
731
779
  '.mopsRow:hover{background:var(--dsw-alias-interactive-bg-hover,rgba(15,17,21,.045))}',
732
780
  '.mopsRow.on{background:rgba(77,107,254,.08);box-shadow:inset 2px 0 0 var(--dsw-alias-brand-primary,#4d6bfe)}',
733
781
  '.mopsRow.shadowed{opacity:.42}',
@@ -736,11 +784,16 @@ window.__ModuleLoader__.load({
736
784
  '.mopsSnippet{overflow:hidden;text-overflow:ellipsis;white-space:nowrap;font-size:12px}',
737
785
  '.mopsClock{font-size:10px;color:var(--dsw-alias-label-tertiary,#9a9aa0);text-align:right;font-variant-numeric:tabular-nums}',
738
786
  '.mopsEmpty{padding:28px 18px;color:var(--dsw-alias-label-tertiary,#8a8a8e);font-size:12px}',
787
+ '.mopsErrorState{display:flex;align-items:flex-start;gap:10px;flex-wrap:wrap;color:var(--dsw-alias-state-error-primary,#c63b32)}',
788
+ '.mopsErrorState .mopsAction{flex:none}',
739
789
  '.mopsDetail{flex:none;max-height:37%;overflow-y:auto;border-top:1px solid var(--dsw-alias-border-l2,#e6e6e6);padding:12px 18px 10px;background:var(--dsw-alias-bg-secondary,#fafafa)}',
740
790
  '.mopsDetailMeta{display:flex;gap:8px;align-items:center;font-size:10px;color:var(--dsw-alias-label-tertiary,#8a8a8e);margin-bottom:6px}',
741
791
  '.mopsDetailText{margin:0;white-space:pre-wrap;word-break:break-word;max-height:108px;overflow:auto;font-family:inherit;font-size:12px;line-height:1.55;color:var(--dsw-alias-label-primary,#0f1115)}',
742
792
  '.mopsDetailHint{padding:10px 0 14px;color:var(--dsw-alias-label-tertiary,#8a8a8e);font-size:12px}',
743
793
  '.mopsActions{display:flex;gap:6px;flex-wrap:wrap;margin-top:10px}',
794
+ '.mopsActionConfirm{display:flex;flex-direction:column;gap:7px;margin-top:10px;padding:10px;border:1px solid var(--dsw-alias-border-l2,#e6e6e6);background:var(--dsw-alias-bg-primary,#fff)}',
795
+ '.mopsImpactTitle{font-size:12px;font-weight:600}',
796
+ '.mopsImpact{font-size:11px;line-height:1.5;color:var(--dsw-alias-label-secondary,#6b6b70)}',
744
797
  '.mopsAction{height:30px;padding:0 10px;border:1px solid var(--dsw-alias-border-l2,#cfcfcf);background:transparent;cursor:pointer;font-size:11px}',
745
798
  '.mopsAction:hover:not(:disabled){border-color:var(--dsw-alias-label-primary,#0f1115)}',
746
799
  '.mopsAction.primary{border-color:var(--dsw-alias-label-primary,#0f1115);background:var(--dsw-alias-label-primary,#0f1115);color:var(--dsw-alias-bg-primary,#fff)}',
@@ -757,7 +810,10 @@ window.__ModuleLoader__.load({
757
810
  '.mopsConfirm{position:absolute;inset:0;z-index:2;background:var(--dsw-alias-bg-primary,#fff);display:flex;flex-direction:column;justify-content:center;padding:28px 24px;gap:10px}',
758
811
  '.mopsConfirm h3{margin:0;font-size:15px}',
759
812
  '.mopsConfirm p{margin:0;font-size:12px;color:var(--dsw-alias-label-secondary,#6b6b70)}',
813
+ '.mopsConfirm p.mopsImpact{font-size:11px}',
814
+ '.mopsConfirm .mopsBanner{margin:0 -24px;border-top:1px solid var(--dsw-alias-border-l1,#efefef);border-bottom:1px solid var(--dsw-alias-border-l1,#efefef)}',
760
815
  '.mopsConfirm input{height:34px;border:1px solid var(--dsw-alias-border-l2,#d8d8d8);background:transparent;color:inherit;padding:0 9px;font:inherit;font-size:13px}',
816
+ '.mopsConfirm input:disabled{opacity:.5}',
761
817
  '.mopsConfirmRow{display:flex;gap:8px;margin-top:4px}',
762
818
  '.mopsTrashItem{display:flex;align-items:center;gap:10px;padding:11px 18px;border-bottom:1px solid var(--dsw-alias-border-l1,#f0f0f0)}',
763
819
  '.mopsTrashMain{flex:1;min-width:0}',
@@ -775,6 +831,7 @@ window.__ModuleLoader__.load({
775
831
  const [open, setOpen] = useState(false)
776
832
  const [target, setTarget] = useState(null)
777
833
  const [state, setState] = useState('idle')
834
+ const [loadError, setLoadError] = useState(null)
778
835
  const [messages, setMessages] = useState([])
779
836
  const [query, setQuery] = useState('')
780
837
  const [role, setRole] = useState('all')
@@ -787,8 +844,11 @@ window.__ModuleLoader__.load({
787
844
  const [searching, setSearching] = useState(false)
788
845
  const [trash, setTrash] = useState([])
789
846
  const [trashState, setTrashState] = useState('idle')
847
+ const [trashError, setTrashError] = useState(null)
790
848
  const [confirmDelete, setConfirmDelete] = useState(false)
791
849
  const [confirmTitle, setConfirmTitle] = useState('')
850
+ const [deleteError, setDeleteError] = useState(null)
851
+ const [confirmAction, setConfirmAction] = useState(null)
792
852
  const [purgeId, setPurgeId] = useState(null)
793
853
  const [childId, setChildId] = useState(null)
794
854
  const [busy, setBusy] = useState('')
@@ -798,16 +858,36 @@ window.__ModuleLoader__.load({
798
858
  const [viewport, setViewport] = useState(480)
799
859
  const listRef = useRef(null)
800
860
  const searchRef = useRef(null)
861
+ const panelRef = useRef(null)
862
+ const scrimRef = useRef(null)
863
+ const confirmRef = useRef(null)
864
+ const actionConfirmRef = useRef(null)
865
+ const triggerRef = useRef(null)
866
+ const deleteBtnRef = useRef(null)
867
+ const revertBtnRef = useRef(null)
868
+ const deleteOneBtnRef = useRef(null)
801
869
  const detailReq = useRef(0)
870
+ const loadSeqRef = useRef(0)
871
+ const trashSeqRef = useRef(0)
872
+ const openRef = useRef(false)
873
+ const sessionRef = useRef(null)
874
+ openRef.current = open
875
+ sessionRef.current = target && target.sessionId ? target.sessionId : null
802
876
 
803
877
  useEffect(() => {
804
878
  ensurePanelStyle()
805
879
  const handler = (e) => {
806
880
  const d = e && e.detail ? e.detail : {}
807
881
  if (!d.sessionId) return
882
+ const active = document.activeElement
883
+ if (!panelRef.current || !panelRef.current.contains(active)) triggerRef.current = active
884
+ loadSeqRef.current += 1
885
+ trashSeqRef.current += 1
886
+ detailReq.current += 1
808
887
  setTarget({ sessionId: d.sessionId, title: d.title || null, running: d.running === true })
809
888
  setOpen(true)
810
889
  setState('loading')
890
+ setLoadError(null)
811
891
  setMessages([])
812
892
  setHits(null)
813
893
  setQuery('')
@@ -815,10 +895,15 @@ window.__ModuleLoader__.load({
815
895
  setIncludeShadowed(false)
816
896
  setPicked(null)
817
897
  setDetail('')
898
+ setDetailState('idle')
818
899
  setTab('messages')
819
900
  setTrash([])
901
+ setTrashState('idle')
902
+ setTrashError(null)
820
903
  setConfirmDelete(false)
821
904
  setConfirmTitle('')
905
+ setDeleteError(null)
906
+ setConfirmAction(null)
822
907
  setPurgeId(null)
823
908
  setChildId(null)
824
909
  setError(null)
@@ -833,20 +918,27 @@ window.__ModuleLoader__.load({
833
918
 
834
919
  const loadMessages = useCallback(async (quiet) => {
835
920
  if (!sid) return
836
- if (!quiet) setState('loading')
921
+ const requestId = ++loadSeqRef.current
922
+ const requestSid = sid
923
+ if (!quiet) { setState('loading'); setLoadError(null) }
837
924
  try {
838
- const data = await fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(sid) + '&view=compact')
925
+ const data = await fetchMessagesJson('/api/message-ops/messages?sessionId=' + encodeURIComponent(requestSid) + '&view=compact')
926
+ if (requestId !== loadSeqRef.current) return
839
927
  setMessages(Array.isArray(data.messages) ? data.messages : [])
840
- setTarget((prev) => prev ? {
928
+ setTarget((prev) => prev && prev.sessionId === requestSid ? {
841
929
  ...prev,
842
930
  running: data.running === true,
843
931
  title: prev.title || (data.session && data.session.title) || null,
844
932
  expectedTitle: (data.session && data.session.confirmTitle) || prev.expectedTitle || prev.title || prev.sessionId,
845
933
  } : prev)
934
+ setLoadError(null)
935
+ setError(null)
846
936
  setState('ready')
847
937
  } catch (reason) {
848
- setError(t('panel.loadFail') + (reason && reason.message ? reason.message : String(reason)))
849
- setState('ready')
938
+ if (requestId !== loadSeqRef.current) return
939
+ const message = t('panel.loadFail') + (reason && reason.message ? reason.message : String(reason))
940
+ if (quiet) setError(message)
941
+ else { setLoadError(message); setState('error') }
850
942
  }
851
943
  }, [sid, t])
852
944
 
@@ -859,9 +951,10 @@ window.__ModuleLoader__.load({
859
951
  if (!open || tab !== 'messages') return
860
952
  const q = query.trim()
861
953
  if (!q) { setHits(null); setSearching(false); return }
954
+ setSearching(true)
862
955
  let cancelled = false
863
956
  const timer = setTimeout(() => {
864
- setSearching(true)
957
+ setError(null)
865
958
  const url = '/api/message-ops/search?sessionId=' + encodeURIComponent(sid)
866
959
  + '&q=' + encodeURIComponent(q)
867
960
  + (role !== 'all' ? '&role=' + encodeURIComponent(role) : '')
@@ -872,6 +965,7 @@ window.__ModuleLoader__.load({
872
965
  if (cancelled) return
873
966
  if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || ('HTTP ' + res.status))
874
967
  setHits(Array.isArray(data.results) ? data.results : [])
968
+ setError(null)
875
969
  })
876
970
  .catch((reason) => {
877
971
  if (!cancelled) setError(t('panel.searchFail') + (reason && reason.message ? reason.message : String(reason)))
@@ -882,16 +976,21 @@ window.__ModuleLoader__.load({
882
976
  }, [open, tab, sid, query, role, t])
883
977
 
884
978
  const loadTrash = useCallback(async () => {
979
+ const requestId = ++trashSeqRef.current
885
980
  setTrashState('loading')
981
+ setTrashError(null)
886
982
  try {
887
983
  const res = await fetch('/api/message-ops/session/trash')
888
984
  const data = await res.json().catch(() => null)
985
+ if (requestId !== trashSeqRef.current) return
889
986
  if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || ('HTTP ' + res.status))
890
987
  setTrash(Array.isArray(data.entries) ? data.entries : [])
988
+ setTrashError(null)
891
989
  setTrashState('ready')
892
990
  } catch (reason) {
893
- setError(t('panel.loadFail') + (reason && reason.message ? reason.message : String(reason)))
894
- setTrashState('ready')
991
+ if (requestId !== trashSeqRef.current) return
992
+ setTrashError(t('panel.loadFail') + (reason && reason.message ? reason.message : String(reason)))
993
+ setTrashState('error')
895
994
  }
896
995
  }, [t])
897
996
 
@@ -901,27 +1000,138 @@ window.__ModuleLoader__.load({
901
1000
 
902
1001
  const close = useCallback(() => {
903
1002
  if (busy) return
1003
+ loadSeqRef.current += 1
1004
+ trashSeqRef.current += 1
1005
+ detailReq.current += 1
904
1006
  setOpen(false)
905
1007
  setTarget(null)
906
1008
  setPicked(null)
907
1009
  setConfirmDelete(false)
1010
+ setConfirmAction(null)
1011
+ setDeleteError(null)
1012
+ setLoadError(null)
1013
+ setTrashError(null)
1014
+ }, [busy])
1015
+
1016
+ const closeConfirm = useCallback(() => {
1017
+ if (busy === 'session-delete') return
1018
+ setConfirmDelete(false)
1019
+ setConfirmTitle('')
1020
+ setDeleteError(null)
1021
+ setTimeout(() => {
1022
+ const el = deleteBtnRef.current
1023
+ if (el && !el.disabled) el.focus()
1024
+ else if (panelRef.current) panelRef.current.focus()
1025
+ }, 0)
908
1026
  }, [busy])
909
1027
 
1028
+ const cancelAction = useCallback(() => {
1029
+ if (busy) return
1030
+ const mode = confirmAction
1031
+ setConfirmAction(null)
1032
+ setTimeout(() => {
1033
+ const targetRef = mode === 'revert' ? revertBtnRef.current : deleteOneBtnRef.current
1034
+ if (targetRef && !targetRef.disabled) targetRef.focus()
1035
+ else if (panelRef.current) panelRef.current.focus()
1036
+ }, 0)
1037
+ }, [busy, confirmAction])
1038
+
910
1039
  useEffect(() => {
911
1040
  if (!open) return undefined
912
1041
  const onKey = (e) => {
913
1042
  if (e.key === 'Escape') {
914
1043
  if (busy) return
915
- if (confirmDelete) setConfirmDelete(false)
1044
+ if (confirmDelete) closeConfirm()
1045
+ else if (confirmAction) cancelAction()
916
1046
  else close()
917
- } else if (e.key === '/' && e.target && e.target.tagName !== 'INPUT') {
1047
+ } else if (e.key === '/') {
1048
+ if (confirmDelete || confirmAction) return
1049
+ const el = e.target
1050
+ const tag = el && el.tagName
1051
+ if (el && (tag === 'INPUT' || tag === 'TEXTAREA' || el.isContentEditable)) return
918
1052
  e.preventDefault()
919
1053
  if (searchRef.current) searchRef.current.focus()
920
1054
  }
921
1055
  }
922
1056
  window.addEventListener('keydown', onKey)
923
1057
  return () => window.removeEventListener('keydown', onKey)
924
- }, [open, busy, confirmDelete, close])
1058
+ }, [open, busy, confirmDelete, confirmAction, close, closeConfirm, cancelAction])
1059
+
1060
+ useEffect(() => {
1061
+ if (!open) return undefined
1062
+ if (!triggerRef.current) triggerRef.current = document.activeElement
1063
+ const timer = setTimeout(() => {
1064
+ if (searchRef.current) searchRef.current.focus()
1065
+ else if (panelRef.current) panelRef.current.focus()
1066
+ }, 0)
1067
+ const scrim = scrimRef.current
1068
+ const parent = scrim && scrim.parentElement
1069
+ const hidden = []
1070
+ if (parent) {
1071
+ for (const child of Array.from(parent.children)) {
1072
+ if (child === scrim || child.tagName === 'SCRIPT' || child.tagName === 'STYLE') continue
1073
+ hidden.push({ child, inert: child.hasAttribute('inert'), aria: child.getAttribute('aria-hidden') })
1074
+ child.setAttribute('inert', '')
1075
+ child.setAttribute('aria-hidden', 'true')
1076
+ }
1077
+ }
1078
+ return () => {
1079
+ clearTimeout(timer)
1080
+ for (const item of hidden) {
1081
+ if (!item.inert) item.child.removeAttribute('inert')
1082
+ if (item.aria === null) item.child.removeAttribute('aria-hidden')
1083
+ else item.child.setAttribute('aria-hidden', item.aria)
1084
+ }
1085
+ if (openRef.current) return
1086
+ const trigger = triggerRef.current
1087
+ triggerRef.current = null
1088
+ if (trigger && typeof trigger.focus === 'function') {
1089
+ setTimeout(() => { try { trigger.focus() } catch { /* detached trigger */ } }, 0)
1090
+ }
1091
+ }
1092
+ }, [open, sid])
1093
+
1094
+ useEffect(() => {
1095
+ if (!open) return undefined
1096
+ const onKeyDown = (e) => {
1097
+ if (e.key !== 'Tab') return
1098
+ const scope = confirmDelete ? confirmRef.current : (confirmAction ? actionConfirmRef.current : panelRef.current)
1099
+ if (!scope) return
1100
+ const nodes = focusablesIn(scope)
1101
+ if (!nodes.length) {
1102
+ e.preventDefault()
1103
+ scope.focus()
1104
+ return
1105
+ }
1106
+ const first = nodes[0]
1107
+ const last = nodes[nodes.length - 1]
1108
+ const active = document.activeElement
1109
+ if (active === scope || !scope.contains(active)) {
1110
+ e.preventDefault()
1111
+ const fallback = e.shiftKey ? last : first
1112
+ fallback.focus()
1113
+ } else if (e.shiftKey && active === first) {
1114
+ e.preventDefault()
1115
+ last.focus()
1116
+ } else if (!e.shiftKey && active === last) {
1117
+ e.preventDefault()
1118
+ first.focus()
1119
+ }
1120
+ }
1121
+ document.addEventListener('keydown', onKeyDown, true)
1122
+ return () => document.removeEventListener('keydown', onKeyDown, true)
1123
+ }, [open, confirmDelete, confirmAction])
1124
+
1125
+ useEffect(() => {
1126
+ if (!open) return
1127
+ if (confirmDelete) {
1128
+ const input = confirmRef.current && confirmRef.current.querySelector('input')
1129
+ if (input) input.focus()
1130
+ } else if (confirmAction) {
1131
+ const first = actionConfirmRef.current && actionConfirmRef.current.querySelector('button')
1132
+ if (first) first.focus()
1133
+ }
1134
+ }, [open, confirmDelete, confirmAction])
925
1135
 
926
1136
  const baseRows = query.trim() ? (hits || []) : messages
927
1137
  const rows = baseRows
@@ -929,6 +1139,64 @@ window.__ModuleLoader__.load({
929
1139
  && (role === 'all' || m.role === role)
930
1140
  && (includeShadowed || !m.shadowed))
931
1141
  .sort((a, b) => b.seq - a.seq)
1142
+ const activeIndex = picked ? rows.findIndex((m) => m.seq === picked.seq) : -1
1143
+
1144
+ const clearPick = () => {
1145
+ detailReq.current += 1
1146
+ setPicked(null)
1147
+ setDetail('')
1148
+ setDetailState('idle')
1149
+ setConfirmAction(null)
1150
+ }
1151
+
1152
+ const previewRow = (m) => {
1153
+ if (!m) return
1154
+ detailReq.current += 1
1155
+ setPicked(m)
1156
+ setDetail(m.snippet || '')
1157
+ setDetailState('ready')
1158
+ setConfirmAction(null)
1159
+ setDone('')
1160
+ }
1161
+
1162
+ const scrollRowIntoView = (index) => {
1163
+ const el = listRef.current
1164
+ if (!el) return
1165
+ const top = index * PANEL_ROW_H
1166
+ const view = el.clientHeight || viewport
1167
+ let next = el.scrollTop
1168
+ if (top < next) next = top
1169
+ else if (top + PANEL_ROW_H > next + view) next = top + PANEL_ROW_H - view
1170
+ if (next !== el.scrollTop) {
1171
+ el.scrollTop = next
1172
+ setScrollTop(next)
1173
+ }
1174
+ }
1175
+
1176
+ const handleListKeyDown = (e) => {
1177
+ if (!rows.length) return
1178
+ const page = Math.max(1, Math.floor((listRef.current && listRef.current.clientHeight || viewport) / PANEL_ROW_H) - 1)
1179
+ let next = activeIndex
1180
+ if (e.key === 'ArrowDown') next = activeIndex < 0 ? 0 : Math.min(rows.length - 1, activeIndex + 1)
1181
+ else if (e.key === 'ArrowUp') next = activeIndex < 0 ? rows.length - 1 : Math.max(0, activeIndex - 1)
1182
+ else if (e.key === 'Home') next = 0
1183
+ else if (e.key === 'End') next = rows.length - 1
1184
+ else if (e.key === 'PageDown') next = activeIndex < 0 ? 0 : Math.min(rows.length - 1, activeIndex + page)
1185
+ else if (e.key === 'PageUp') next = activeIndex < 0 ? rows.length - 1 : Math.max(0, activeIndex - page)
1186
+ else if (e.key === 'Enter' || e.key === ' ') {
1187
+ e.preventDefault()
1188
+ const row = rows[activeIndex >= 0 ? activeIndex : 0]
1189
+ if (row) { pick(row); if (listRef.current) listRef.current.focus() }
1190
+ return
1191
+ } else {
1192
+ return
1193
+ }
1194
+ e.preventDefault()
1195
+ const row = rows[next]
1196
+ if (!row) return
1197
+ previewRow(row)
1198
+ scrollRowIntoView(next)
1199
+ }
932
1200
 
933
1201
  useEffect(() => {
934
1202
  if (!open || tab !== 'messages') return undefined
@@ -942,8 +1210,20 @@ window.__ModuleLoader__.load({
942
1210
  return () => ro.disconnect()
943
1211
  }, [open, tab, rows.length])
944
1212
 
1213
+ useEffect(() => {
1214
+ if (!open || tab !== 'messages') return
1215
+ const el = listRef.current
1216
+ if (!el) return
1217
+ const max = Math.max(0, rows.length * PANEL_ROW_H - (el.clientHeight || viewport))
1218
+ if (el.scrollTop > max) {
1219
+ el.scrollTop = max
1220
+ setScrollTop(max)
1221
+ }
1222
+ }, [open, tab, rows.length, viewport])
1223
+
945
1224
  const pick = useCallback((m) => {
946
1225
  if (!m || busy) return
1226
+ setConfirmAction(null)
947
1227
  setPicked(m)
948
1228
  setDetail(m.snippet || '')
949
1229
  setDetailState('loading')
@@ -964,9 +1244,11 @@ window.__ModuleLoader__.load({
964
1244
  })
965
1245
  }, [busy, sid])
966
1246
 
967
- const runAction = useCallback(async (mode) => {
1247
+ const runAction = useCallback(async (mode, confirmed) => {
968
1248
  if (!target || !picked || busy) return
969
1249
  if (target.running && mode !== 'branch') return
1250
+ if ((mode === 'revert' || mode === 'delete') && confirmed !== true) return
1251
+ const actionSid = target.sessionId
970
1252
  setBusy(mode)
971
1253
  setError(null)
972
1254
  setDone('')
@@ -975,6 +1257,7 @@ window.__ModuleLoader__.load({
975
1257
  const forkPath = pickForkPath(__sessionsSvc)
976
1258
  if (forkPath.kind !== 'official') throw new Error(t('fork.unavailable'))
977
1259
  const created = await forkPath.fork({ sessionId: target.sessionId, atSeq: picked.seq, increaseTitle: true })
1260
+ if (sessionRef.current !== actionSid) return
978
1261
  setChildId(created || null)
979
1262
  setDone(t('panel.branchDone', { id: String(created || '') }))
980
1263
  notifyDone(t('panel.branchDone', { id: String(created || '') }))
@@ -986,7 +1269,11 @@ window.__ModuleLoader__.load({
986
1269
  body: JSON.stringify({ sessionId: target.sessionId, seq: picked.seq }),
987
1270
  })
988
1271
  const data = await res.json().catch(() => null)
989
- if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || ('HTTP ' + res.status))
1272
+ if (sessionRef.current !== actionSid) return
1273
+ if (!res.ok || !data || data.ok !== true) {
1274
+ if (res.status === 409) setTarget((prev) => prev ? { ...prev, running: true } : prev)
1275
+ throw new Error((data && data.error) || ('HTTP ' + res.status))
1276
+ }
990
1277
  if (mode === 'revert') {
991
1278
  setMessages((prev) => prev.map((m) => (m.seq >= picked.seq ? { ...m, shadowed: true, visible: false } : m)))
992
1279
  if (picked.role === 'user') {
@@ -997,6 +1284,8 @@ window.__ModuleLoader__.load({
997
1284
  }
998
1285
  const msg = t(mode === 'revert' ? 'panel.revertDone' : 'panel.deleteDone')
999
1286
  setDone(msg)
1287
+ setConfirmAction(null)
1288
+ setTimeout(() => { if (listRef.current) listRef.current.focus() }, 0)
1000
1289
  notifyDone(msg)
1001
1290
  emitChanged()
1002
1291
  try {
@@ -1004,6 +1293,7 @@ window.__ModuleLoader__.load({
1004
1293
  } catch { /* view rebuild is best effort */ }
1005
1294
  setTimeout(() => { loadMessages(true).catch(() => {}) }, 650)
1006
1295
  } catch (reason) {
1296
+ if (sessionRef.current !== actionSid) return
1007
1297
  setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
1008
1298
  } finally {
1009
1299
  setBusy('')
@@ -1011,9 +1301,12 @@ window.__ModuleLoader__.load({
1011
1301
  }, [target, picked, busy, t, loadMessages])
1012
1302
 
1013
1303
  const deleteSession = useCallback(async () => {
1014
- if (!target || busy) return
1304
+ if (!target || busy || target.running) return
1305
+ const expected = target.expectedTitle || ''
1306
+ if (!expected || confirmTitle.trim() !== expected) return
1307
+ const actionSid = target.sessionId
1015
1308
  setBusy('session-delete')
1016
- setError(null)
1309
+ setDeleteError(null)
1017
1310
  setDone('')
1018
1311
  try {
1019
1312
  const res = await fetch('/api/message-ops/session/delete', {
@@ -1022,13 +1315,19 @@ window.__ModuleLoader__.load({
1022
1315
  body: JSON.stringify({ sessionId: target.sessionId, confirmTitle: confirmTitle }),
1023
1316
  })
1024
1317
  const data = await res.json().catch(() => null)
1025
- if (!res.ok || !data || data.ok !== true) throw new Error((data && data.error) || ('HTTP ' + res.status))
1318
+ if (sessionRef.current !== actionSid) return
1319
+ if (!res.ok || !data || data.ok !== true) {
1320
+ if (res.status === 409) setTarget((prev) => prev ? { ...prev, running: true } : prev)
1321
+ throw new Error((data && data.error) || ('HTTP ' + res.status))
1322
+ }
1323
+ setConfirmDelete(false)
1026
1324
  setDone(t('panel.deleted'))
1027
1325
  notifyDone(t('panel.deleted'))
1028
1326
  emitChanged()
1029
1327
  setTimeout(() => { try { window.location.reload() } catch { /* non-browser guard */ } }, 700)
1030
1328
  } catch (reason) {
1031
- setError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
1329
+ if (sessionRef.current !== actionSid) return
1330
+ setDeleteError(t('errorPrefix') + (reason && reason.message ? reason.message : String(reason)))
1032
1331
  } finally {
1033
1332
  setBusy('')
1034
1333
  }
@@ -1091,39 +1390,55 @@ window.__ModuleLoader__.load({
1091
1390
  const visibleCount = messages.filter((m) => m.role !== 'system' && m.visible && !m.shadowed).length
1092
1391
  const shadowedCount = messages.filter((m) => m.role !== 'system' && m.shadowed).length
1093
1392
  const totalCount = messages.filter((m) => m.role !== 'system').length
1094
- const revertCount = pickedLive
1095
- ? messages.filter((m) => m.role !== 'system' && !m.shadowed && m.seq >= pickedLive.seq).length
1096
- : 0
1097
- const start = Math.max(0, Math.floor(scrollTop / PANEL_ROW_H) - 6)
1393
+ const revertImpact = pickedLive
1394
+ ? messages.filter((m) => m.role !== 'system' && !m.shadowed && m.seq >= pickedLive.seq)
1395
+ : []
1396
+ const revertCount = revertImpact.length
1397
+ const revertVisibleCount = revertImpact.filter((m) => m.visible).length
1398
+ const revertEnd = revertImpact.reduce((max, m) => Math.max(max, m.seq), pickedLive ? pickedLive.seq : 0)
1399
+ const expectedDeleteTitle = target.expectedTitle || ''
1400
+ const deleteBlockedReason = target.running
1401
+ ? t('panel.running')
1402
+ : state !== 'ready'
1403
+ ? (state === 'error' ? t('panel.loadFail') : t('panel.loading'))
1404
+ : !expectedDeleteTitle ? t('panel.deleteUnavailable') : ''
1405
+ const canConfirmDelete = !busy && state === 'ready' && !target.running && !!expectedDeleteTitle
1406
+ && confirmTitle.trim() === expectedDeleteTitle
1407
+ const start = Math.min(Math.max(0, rows.length - 1), Math.max(0, Math.floor(scrollTop / PANEL_ROW_H) - 6))
1098
1408
  const end = Math.min(rows.length, start + Math.ceil(viewport / PANEL_ROW_H) + 12)
1099
1409
  const windowRows = rows.slice(start, end)
1410
+ const activeRendered = picked && windowRows.some((m) => m.seq === picked.seq)
1100
1411
  const showSearchLoading = searching && query.trim().length > 0
1101
1412
 
1102
1413
  return React.createElement('div', {
1103
- className: 'mopsPanelScrim', role: 'presentation',
1414
+ className: 'mopsPanelScrim', role: 'presentation', ref: scrimRef,
1104
1415
  onMouseDown: (e) => { if (e.target === e.currentTarget) close() },
1105
1416
  },
1106
1417
  React.createElement('section', {
1107
- className: 'mopsPanel', role: 'dialog', 'aria-modal': 'true', 'aria-label': t('dialog.title'),
1418
+ className: 'mopsPanel', role: 'dialog', 'aria-modal': 'true',
1419
+ 'aria-labelledby': 'mops-panel-title', 'aria-describedby': 'mops-panel-session',
1420
+ 'aria-busy': busy || state === 'loading' ? 'true' : undefined,
1421
+ tabIndex: -1, ref: panelRef,
1108
1422
  style: { position: 'relative' },
1109
1423
  },
1110
1424
  React.createElement('header', { className: 'mopsPanelHead' },
1111
1425
  React.createElement('div', { style: { minWidth: 0 } },
1112
1426
  React.createElement('div', { className: 'mopsPanelKicker' }, t('dialog.title')),
1113
- React.createElement('div', { className: 'mopsPanelTitle' }, target.title || target.expectedTitle || target.sessionId),
1114
- React.createElement('div', { className: 'mopsPanelSub' }, target.sessionId)),
1427
+ React.createElement('div', { className: 'mopsPanelTitle', id: 'mops-panel-title' }, target.title || target.expectedTitle || target.sessionId),
1428
+ React.createElement('div', { className: 'mopsPanelSub', id: 'mops-panel-session' }, target.sessionId)),
1115
1429
  React.createElement('button', {
1116
1430
  type: 'button', className: 'mopsPanelClose', title: t('dialog.cancel'),
1431
+ 'aria-label': t('dialog.cancel'),
1117
1432
  onClick: close, disabled: !!busy,
1118
1433
  }, '×')),
1119
1434
  React.createElement('div', { className: 'mopsTabs' },
1120
1435
  React.createElement('button', {
1121
1436
  type: 'button', className: 'mopsTab' + (tab === 'messages' ? ' on' : ''),
1122
- onClick: () => { setTab('messages'); setConfirmDelete(false) },
1437
+ onClick: () => { setTab('messages'); setConfirmDelete(false); setConfirmAction(null); setDeleteError(null) },
1123
1438
  }, t('panel.messages') + ' ' + totalCount),
1124
1439
  React.createElement('button', {
1125
1440
  type: 'button', className: 'mopsTab' + (tab === 'trash' ? ' on' : ''),
1126
- onClick: () => { setTab('trash'); setConfirmDelete(false) },
1441
+ onClick: () => { setTab('trash'); setConfirmDelete(false); setConfirmAction(null); setDeleteError(null) },
1127
1442
  }, t('panel.trash') + (trash.length ? ' ' + trash.length : ''))),
1128
1443
  target.running && tab === 'messages'
1129
1444
  ? React.createElement('div', { className: 'mopsBanner warn' }, t('panel.running')) : null,
@@ -1139,36 +1454,55 @@ window.__ModuleLoader__.load({
1139
1454
  React.createElement('input', {
1140
1455
  ref: searchRef, className: 'mopsSearch', value: query,
1141
1456
  placeholder: t('panel.searchHint'), 'aria-label': t('panel.search'),
1142
- onChange: (e) => { setQuery(e.target.value); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
1457
+ onChange: (e) => { setQuery(e.target.value); clearPick(); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
1143
1458
  })),
1144
1459
  React.createElement('div', { className: 'mopsChips' },
1145
1460
  ['all', 'user', 'assistant', 'tool'].map((key) => React.createElement('button', {
1146
1461
  key, type: 'button', className: 'mopsChip' + (role === key ? ' on' : ''),
1147
- onClick: () => { setRole(key); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
1462
+ onClick: () => { setRole(key); clearPick(); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
1148
1463
  }, t('panel.' + key))),
1149
1464
  React.createElement('label', { className: 'mopsToggle' },
1150
1465
  React.createElement('input', {
1151
1466
  type: 'checkbox', checked: includeShadowed,
1152
- onChange: (e) => { setIncludeShadowed(e.target.checked); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
1467
+ onChange: (e) => { setIncludeShadowed(e.target.checked); clearPick(); setScrollTop(0); if (listRef.current) listRef.current.scrollTop = 0 },
1153
1468
  }), t('panel.includeShadowed'))),
1154
1469
  React.createElement('div', {
1155
1470
  className: 'mopsList', ref: listRef,
1471
+ role: state === 'ready' && rows.length ? 'listbox' : 'region',
1472
+ tabIndex: state === 'ready' && rows.length ? 0 : -1,
1473
+ 'aria-label': t('panel.messages'),
1474
+ 'aria-busy': state === 'loading' || showSearchLoading ? 'true' : undefined,
1475
+ 'aria-activedescendant': state === 'ready' && activeRendered ? 'mops-opt-' + picked.seq : undefined,
1476
+ onKeyDown: handleListKeyDown,
1156
1477
  onScroll: (e) => setScrollTop(e.currentTarget.scrollTop),
1157
1478
  },
1158
- rows.length === 0
1159
- ? React.createElement('div', { className: 'mopsEmpty' }, showSearchLoading ? t('panel.loading') : (query.trim() ? t('panel.noMatch') : t('panel.empty')))
1160
- : React.createElement('div', { style: { height: rows.length * PANEL_ROW_H, position: 'relative' } },
1161
- windowRows.map((m, i) => React.createElement('button', {
1162
- key: m.seq, type: 'button',
1163
- className: 'mopsRow' + (pickedLive && pickedLive.seq === m.seq ? ' on' : '') + (m.shadowed ? ' shadowed' : ''),
1164
- style: { top: (start + i) * PANEL_ROW_H, height: PANEL_ROW_H },
1165
- onClick: () => pick(m),
1166
- title: '#' + m.seq + ' ' + (m.role || '') + ' · ' + (m.snippet || ''),
1167
- },
1168
- React.createElement('span', { className: 'mopsSeq' }, '#' + m.seq),
1169
- React.createElement('span', { className: 'mopsRole' }, roleCode(m.role)),
1170
- React.createElement('span', { className: 'mopsSnippet' }, m.snippet || '—'),
1171
- React.createElement('span', { className: 'mopsClock' }, fmtClock(m.time)))))),
1479
+ state === 'loading' || state === 'idle'
1480
+ ? React.createElement('div', { className: 'mopsEmpty', role: 'status', 'aria-live': 'polite' }, t('panel.loading'))
1481
+ : state === 'error'
1482
+ ? React.createElement('div', { className: 'mopsEmpty mopsErrorState', role: 'alert' },
1483
+ React.createElement('span', null, loadError || t('panel.loadFail')),
1484
+ React.createElement('button', {
1485
+ type: 'button', className: 'mopsAction',
1486
+ onClick: () => { loadMessages(false); setTimeout(() => { if (searchRef.current) searchRef.current.focus() }, 0) },
1487
+ }, t('panel.retry')))
1488
+ : rows.length === 0
1489
+ ? React.createElement('div', { className: 'mopsEmpty', role: 'status', 'aria-live': 'polite' }, showSearchLoading ? t('panel.searching') : (query.trim() ? t('panel.noMatch') : t('panel.empty')))
1490
+ : React.createElement('div', { style: { height: rows.length * PANEL_ROW_H, position: 'relative' } },
1491
+ windowRows.map((m, i) => React.createElement('div', {
1492
+ key: m.seq, id: 'mops-opt-' + m.seq, role: 'option',
1493
+ 'aria-selected': pickedLive && pickedLive.seq === m.seq,
1494
+ 'aria-setsize': rows.length, 'aria-posinset': start + i + 1,
1495
+ tabIndex: -1,
1496
+ className: 'mopsRow' + (pickedLive && pickedLive.seq === m.seq ? ' on' : '') + (m.shadowed ? ' shadowed' : ''),
1497
+ style: { top: (start + i) * PANEL_ROW_H, height: PANEL_ROW_H },
1498
+ onClick: () => { pick(m); if (listRef.current) listRef.current.focus() },
1499
+ title: '#' + m.seq + ' ' + (m.role || '') + ' · ' + (m.snippet || ''),
1500
+ 'aria-label': '#' + m.seq + ' ' + (m.role || '') + (m.shadowed ? ' ' + t('panel.shadowed') : '') + ' · ' + (m.snippet || '') + (m.time ? ' · ' + fmtClock(m.time) : ''),
1501
+ },
1502
+ React.createElement('span', { className: 'mopsSeq' }, '#' + m.seq),
1503
+ React.createElement('span', { className: 'mopsRole' }, roleCode(m.role)),
1504
+ React.createElement('span', { className: 'mopsSnippet' }, m.snippet || '—'),
1505
+ React.createElement('span', { className: 'mopsClock' }, fmtClock(m.time)))))),
1172
1506
  React.createElement('div', { className: 'mopsDetail' },
1173
1507
  pickedLive
1174
1508
  ? React.createElement(React.Fragment, null,
@@ -1181,48 +1515,113 @@ window.__ModuleLoader__.load({
1181
1515
  detailState === 'loading' ? t('panel.detailLoading') : (detail || pickedLive.snippet || '—')),
1182
1516
  React.createElement('div', { className: 'mopsActions' },
1183
1517
  React.createElement('button', {
1184
- type: 'button', className: 'mopsAction primary', disabled: !canAct,
1185
- onClick: () => runAction('revert'),
1518
+ type: 'button', className: 'mopsAction primary', disabled: !canAct || !!confirmAction,
1519
+ ref: revertBtnRef,
1520
+ onClick: () => setConfirmAction('revert'),
1186
1521
  title: t('panel.revertHint'),
1187
1522
  }, t('panel.revert') + (revertCount ? ' · ' + revertCount : '')),
1188
1523
  React.createElement('button', {
1189
- type: 'button', className: 'mopsAction danger', disabled: !canAct,
1190
- onClick: () => runAction('delete'), title: t('panel.deleteHint'),
1524
+ type: 'button', className: 'mopsAction danger', disabled: !canAct || !!confirmAction,
1525
+ ref: deleteOneBtnRef,
1526
+ onClick: () => setConfirmAction('delete'), title: t('panel.deleteHint'),
1191
1527
  }, t('panel.delete')),
1192
1528
  React.createElement('button', {
1193
- type: 'button', className: 'mopsAction', disabled: !canAct,
1529
+ type: 'button', className: 'mopsAction', disabled: !canAct || !!confirmAction,
1194
1530
  onClick: () => runAction('branch'), title: t('panel.branchHint'),
1195
- }, t('panel.branch'))))
1531
+ }, t('panel.branch'))),
1532
+ confirmAction
1533
+ ? React.createElement('div', {
1534
+ className: 'mopsActionConfirm', ref: actionConfirmRef, role: 'group', tabIndex: -1,
1535
+ 'aria-labelledby': 'mops-action-confirm-title',
1536
+ },
1537
+ React.createElement('div', { className: 'mopsImpactTitle', id: 'mops-action-confirm-title' },
1538
+ t(confirmAction === 'revert' ? 'panel.revertConfirmTitle' : 'panel.deleteConfirmTitle', { seq: String(pickedLive.seq) })),
1539
+ React.createElement('div', { className: 'mopsImpact' },
1540
+ confirmAction === 'revert'
1541
+ ? t('panel.revertConfirmBody', {
1542
+ start: String(pickedLive.seq), end: String(revertEnd),
1543
+ n: String(revertCount), v: String(revertVisibleCount),
1544
+ })
1545
+ : t('panel.deleteConfirmBody')),
1546
+ React.createElement('div', { className: 'mopsConfirmRow' },
1547
+ React.createElement('button', {
1548
+ type: 'button', className: 'mopsAction', onClick: cancelAction, disabled: !!busy,
1549
+ }, t('panel.cancel')),
1550
+ React.createElement('button', {
1551
+ type: 'button', className: 'mopsAction danger',
1552
+ onClick: () => runAction(confirmAction, true),
1553
+ disabled: !!busy || !canAct,
1554
+ }, busy === confirmAction ? t('panel.busy') : t(confirmAction === 'revert' ? 'panel.confirmRevert' : 'panel.confirmDeleteOne'))))
1555
+ : null)
1196
1556
  : React.createElement('div', { className: 'mopsDetailHint' }, t('panel.selectHint'))),
1197
1557
  React.createElement('footer', { className: 'mopsPanelFoot' },
1198
1558
  React.createElement('span', { className: 'mopsCount' },
1199
1559
  t('panel.count', { n: String(totalCount), v: String(visibleCount), s: String(shadowedCount) })),
1200
1560
  React.createElement('button', {
1201
- type: 'button', className: 'mopsDanger', disabled: !!busy,
1202
- onClick: () => { setConfirmTitle(''); setConfirmDelete(true) },
1561
+ type: 'button', className: 'mopsDanger', ref: deleteBtnRef,
1562
+ disabled: !!busy || !!deleteBlockedReason,
1563
+ title: deleteBlockedReason || undefined,
1564
+ onClick: () => {
1565
+ setConfirmTitle('')
1566
+ setDeleteError(null)
1567
+ setConfirmAction(null)
1568
+ setConfirmDelete(true)
1569
+ },
1203
1570
  }, t('panel.deleteSession'))),
1204
1571
  confirmDelete
1205
- ? React.createElement('div', { className: 'mopsConfirm' },
1206
- React.createElement('h3', null, t('panel.deleteSession')),
1207
- React.createElement('p', null, t('panel.deleteSessionHint')),
1572
+ ? React.createElement('div', {
1573
+ className: 'mopsConfirm', ref: confirmRef, role: 'alertdialog', 'aria-modal': 'true',
1574
+ 'aria-labelledby': 'mops-delete-title', 'aria-describedby': 'mops-delete-hint mops-delete-impact',
1575
+ tabIndex: -1,
1576
+ },
1577
+ React.createElement('h3', { id: 'mops-delete-title' }, t('panel.deleteSession')),
1578
+ React.createElement('p', { id: 'mops-delete-hint' }, t('panel.deleteSessionHint')),
1579
+ React.createElement('p', { className: 'mopsImpact', id: 'mops-delete-impact' },
1580
+ t('panel.deleteSessionImpact', { n: String(totalCount) })),
1581
+ target.running ? React.createElement('div', { className: 'mopsBanner warn', role: 'status' }, t('panel.running')) : null,
1582
+ deleteError ? React.createElement('div', { className: 'mopsBanner err', role: 'alert' }, deleteError) : null,
1208
1583
  React.createElement('input', {
1209
- value: confirmTitle, autoFocus: true,
1210
- placeholder: target.expectedTitle || target.title || target.sessionId,
1584
+ id: 'mops-delete-title-input', value: confirmTitle, autoFocus: true,
1585
+ 'aria-label': t('panel.deleteSessionHint'),
1586
+ 'aria-describedby': 'mops-delete-hint',
1587
+ placeholder: expectedDeleteTitle || target.title || target.sessionId,
1588
+ disabled: !!busy || target.running || !expectedDeleteTitle,
1211
1589
  onChange: (e) => setConfirmTitle(e.target.value),
1590
+ onKeyDown: (e) => {
1591
+ if (e.key === 'Enter') {
1592
+ e.preventDefault()
1593
+ if (canConfirmDelete) deleteSession()
1594
+ } else if (e.key === 'Escape') {
1595
+ e.preventDefault()
1596
+ e.stopPropagation()
1597
+ closeConfirm()
1598
+ }
1599
+ },
1212
1600
  }),
1213
1601
  React.createElement('div', { className: 'mopsConfirmRow' },
1214
- React.createElement('button', { type: 'button', className: 'mopsAction', onClick: () => setConfirmDelete(false), disabled: !!busy }, t('panel.cancel')),
1215
1602
  React.createElement('button', {
1216
- type: 'button', className: 'mopsAction danger', disabled: !!busy || confirmTitle.trim() !== (target.expectedTitle || target.title || target.sessionId),
1603
+ type: 'button', className: 'mopsAction',
1604
+ onClick: closeConfirm, disabled: busy === 'session-delete',
1605
+ }, t('panel.cancel')),
1606
+ React.createElement('button', {
1607
+ type: 'button', className: 'mopsAction danger',
1608
+ disabled: !canConfirmDelete,
1217
1609
  onClick: deleteSession,
1218
1610
  }, busy === 'session-delete' ? t('panel.deleting') : t('panel.confirmDelete'))))
1219
1611
  : null)
1220
- : React.createElement('div', { className: 'mopsList', style: { borderTop: 0 } },
1221
- trashState === 'loading'
1222
- ? React.createElement('div', { className: 'mopsEmpty' }, t('panel.loading'))
1223
- : trash.length === 0
1224
- ? React.createElement('div', { className: 'mopsEmpty' }, t('panel.trashEmpty'))
1225
- : trash.map((item) => React.createElement('div', { className: 'mopsTrashItem', key: item.trashId },
1612
+ : React.createElement('div', { className: 'mopsList', style: { borderTop: 0 }, 'aria-busy': trashState === 'loading' ? 'true' : undefined },
1613
+ trashState === 'loading' || trashState === 'idle'
1614
+ ? React.createElement('div', { className: 'mopsEmpty', role: 'status', 'aria-live': 'polite' }, t('panel.loading'))
1615
+ : trashState === 'error'
1616
+ ? React.createElement('div', { className: 'mopsEmpty mopsErrorState', role: 'alert' },
1617
+ React.createElement('span', null, trashError || t('panel.loadFail')),
1618
+ React.createElement('button', {
1619
+ type: 'button', className: 'mopsAction',
1620
+ onClick: () => { loadTrash(); setTimeout(() => { if (panelRef.current) panelRef.current.focus() }, 0) },
1621
+ }, t('panel.retry')))
1622
+ : trash.length === 0
1623
+ ? React.createElement('div', { className: 'mopsEmpty' }, t('panel.trashEmpty'))
1624
+ : trash.map((item) => React.createElement('div', { className: 'mopsTrashItem', key: item.trashId },
1226
1625
  React.createElement('div', { className: 'mopsTrashMain' },
1227
1626
  React.createElement('div', { className: 'mopsTrashTitle' }, item.title || t('panel.untitled')),
1228
1627
  React.createElement('div', { className: 'mopsTrashMeta' },
@@ -1565,6 +1964,7 @@ window.__ModuleLoader__.load({
1565
1964
  }, [styleInjected])
1566
1965
 
1567
1966
  useEffect(() => {
1967
+ syncSyntheticTurnStyle([])
1568
1968
  let alive = true
1569
1969
  const onChange = () => load()
1570
1970
  window.addEventListener(CHANGED_EVENT, onChange)
@@ -1586,6 +1986,7 @@ window.__ModuleLoader__.load({
1586
1986
  if (reqSeq !== reqSeqRef.current || reqSeq <= landedSeqRef.current) return
1587
1987
  landedSeqRef.current = reqSeq
1588
1988
  const msgs = data.messages || []
1989
+ syncSyntheticTurnStyle(msgs)
1589
1990
  const act = activeMarkers(msgs)
1590
1991
  setMarkers(act)
1591
1992
  // 0.5.2(P2):标题口径 = 标记 range 内 visible=false 的去重 seq 数
@@ -1619,6 +2020,7 @@ window.__ModuleLoader__.load({
1619
2020
  return () => {
1620
2021
  alive = false
1621
2022
  loadRef.current = () => {}
2023
+ syncSyntheticTurnStyle([])
1622
2024
  window.removeEventListener(CHANGED_EVENT, onChange)
1623
2025
  }
1624
2026
  }, [sessionId])