dsh-learn-space 1.0.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/client.js CHANGED
@@ -6,7 +6,7 @@ window.__ModuleLoader__.load({
6
6
  id: 'dsh-learn-space',
7
7
  factory(require) {
8
8
  const React = require('react')
9
- const { useEffect, useState, useCallback, useRef } = React
9
+ const { useEffect, useState, useCallback, useMemo, useRef } = React
10
10
  const h = React.createElement
11
11
 
12
12
  const STATUS_COLOR = {
@@ -17,6 +17,243 @@ window.__ModuleLoader__.load({
17
17
  }
18
18
  const STATUS_LABEL = { done: '已确认', doing: '进行中', warn: '待修复', todo: '未学' }
19
19
 
20
+ // ── 轻量 toast:模块级队列 + 右下角栈,不引第三方运行时 ──
21
+ const toastStore = { items: [], listeners: new Set() }
22
+ let toastSeq = 0
23
+ const emitToasts = () => { for (const l of toastStore.listeners) l(toastStore.items) }
24
+ const dismissToast = id => {
25
+ const t = toastStore.items.find(x => x.id === id)
26
+ if (!t || t.leaving) return
27
+ toastStore.items = toastStore.items.map(x => x.id === id ? { ...x, leaving: true } : x)
28
+ emitToasts()
29
+ setTimeout(() => {
30
+ toastStore.items = toastStore.items.filter(x => x.id !== id)
31
+ emitToasts()
32
+ }, 180)
33
+ }
34
+ const pushToast = (type, title, desc) => {
35
+ const id = ++toastSeq
36
+ toastStore.items = [...toastStore.items, { id, type, title, desc }].slice(-3)
37
+ emitToasts()
38
+ setTimeout(() => dismissToast(id), 3200)
39
+ return id
40
+ }
41
+ const toast = {
42
+ success: (title, desc) => pushToast('success', title, desc),
43
+ error: (title, desc) => pushToast('error', title, desc),
44
+ warning: (title, desc) => pushToast('warning', title, desc),
45
+ info: (title, desc) => pushToast('info', title, desc),
46
+ loading: (title, desc) => pushToast('loading', title, desc),
47
+ }
48
+
49
+ function ToastGlyph({ type }) {
50
+ if (type === 'loading') {
51
+ return h('svg', {
52
+ className: 'ls-spin', viewBox: '0 0 24 24', width: 17, height: 17,
53
+ fill: 'none', stroke: 'currentColor', strokeWidth: 2.6, strokeLinecap: 'round',
54
+ },
55
+ h('circle', { cx: 12, cy: 12, r: 8, strokeOpacity: .3 }),
56
+ h('path', { d: 'M12 4a8 8 0 0 1 8 8' }))
57
+ }
58
+ const stroke = { fill: 'none', stroke: 'currentColor', strokeWidth: 3, strokeLinecap: 'round', strokeLinejoin: 'round' }
59
+ return h('svg', { viewBox: '0 0 24 24', width: 17, height: 17, ...stroke },
60
+ type === 'success' ? h('path', { d: 'M6 12.5l4 4 8-9' })
61
+ : type === 'error' ? h('path', { d: 'M7.5 7.5l9 9M16.5 7.5l-9 9' })
62
+ : type === 'warning' ? h('path', { d: 'M12 6v6.5M12 16.8v.7' })
63
+ : h('path', { d: 'M12 6.2v.7M12 10.5v7' }))
64
+ }
65
+
66
+ function ToastHost() {
67
+ const [items, setItems] = useState(toastStore.items)
68
+ useEffect(() => {
69
+ const fn = list => setItems(list)
70
+ toastStore.listeners.add(fn)
71
+ return () => { toastStore.listeners.delete(fn) }
72
+ }, [])
73
+ return h('div', { className: 'ls-toasts', 'aria-live': 'polite' },
74
+ items.map(t => h('div', { key: t.id, className: 'ls-toast' + (t.leaving ? ' leaving' : ''), 'data-type': t.type },
75
+ h('span', { className: `ls-toast-tile ${t.type}` }, h(ToastGlyph, { type: t.type })),
76
+ h('div', { className: 'ls-toast-body' },
77
+ h('div', { className: 'ls-toast-title' }, t.title),
78
+ t.desc ? h('div', { className: 'ls-toast-desc' }, t.desc) : null),
79
+ h('button', { className: 'ls-toast-x', type: 'button', 'aria-label': '关闭', onClick: () => dismissToast(t.id) }, '×'))))
80
+ }
81
+
82
+ // ── AI 状态行:闪烁文字 + 图标动画 + 秒表(AiStatus 的移植版) ──
83
+ const SPARKLE_PATH = 'M11 5Q12 12 19 13Q12 14 11 21Q10 14 3 13Q10 12 11 5Z'
84
+ const TWINKLE_PATH = 'M18 2Q18.4 4.6 21 5Q18.4 5.4 18 8Q17.6 5.4 15 5Q17.6 4.6 18 2Z'
85
+
86
+ function AiStatus({ state = 'thinking', label, detail, elapsed }) {
87
+ const busy = state === 'thinking' || state === 'tool'
88
+ const [secs, setSecs] = useState(0)
89
+ useEffect(() => {
90
+ if (!busy) return
91
+ const start = Date.now()
92
+ setSecs(0)
93
+ const id = setInterval(() => setSecs(Math.floor((Date.now() - start) / 1000)), 1000)
94
+ return () => clearInterval(id)
95
+ }, [busy])
96
+ const time = elapsed != null ? elapsed : (busy ? secs : null)
97
+ const icon = state === 'done'
98
+ ? h('svg', { viewBox: '0 0 24 24', width: 16, height: 16, fill: 'none', stroke: 'currentColor',
99
+ strokeWidth: 2.4, strokeLinecap: 'round', strokeLinejoin: 'round' },
100
+ h('path', { className: 'ls-ai-check', d: 'M5 12.5L10 17.5L19 7' }))
101
+ : state === 'tool'
102
+ ? h('svg', { viewBox: '0 0 24 24', width: 16, height: 16, fill: 'none', stroke: 'currentColor',
103
+ strokeWidth: 2.6, strokeLinecap: 'round' },
104
+ [6, 12, 18].map(x => h('line', {
105
+ key: x, className: 'ls-ai-bar', x1: x, y1: 18.5, x2: x, y2: 7.5,
106
+ style: { transformBox: 'fill-box', transformOrigin: 'center' },
107
+ })))
108
+ : h('svg', { viewBox: '0 0 24 24', width: 16, height: 16, fill: 'currentColor' },
109
+ h('path', { className: 'ls-ai-spark', d: SPARKLE_PATH }),
110
+ h('path', { className: 'ls-ai-spark2', d: TWINKLE_PATH }))
111
+ return h('div', { className: 'ls-aistatus' + (busy ? ' active' : ''), role: 'status', 'aria-busy': busy },
112
+ h('span', { className: 'ls-aistatus-icon' + (state === 'done' ? ' ls-aistatus-done' : '') }, icon),
113
+ h('span', { className: 'ls-aistatus-label' }, label || (busy ? '思考中' : '完成')),
114
+ detail ? h('span', { className: 'ls-aistatus-detail' }, detail) : null,
115
+ time != null && time > 0 ? h('span', { className: 'ls-aistatus-time' }, `${time}s`) : null)
116
+ }
117
+
118
+ // ── 课程剩余节点铃铛:数字徽标 + 换数时摆铃 + 点开列剩余节点 ──
119
+ const BELL_BODY = 'M3.5 6.5C3.5 3.46279 5.96279 1 9 1C12.0372 1 14.5 3.46279 14.5 6.5V10.75C14.5 11.4408 15.0592 12 15.75 12C16.1642 12 16.5 12.3358 16.5 12.75C16.5 13.1642 16.1642 13.5 15.75 13.5H2.25C1.83579 13.5 1.5 13.1642 1.5 12.75C1.5 12.3358 1.83579 12 2.25 12C2.94079 12 3.5 11.4408 3.5 10.75V6.5Z'
120
+ const BELL_CLAPPER = 'M10.2 15H7.80099C7.64999 15 7.50799 15.068 7.41299 15.185C7.31799 15.302 7.28099 15.456 7.31199 15.603C7.48499 16.425 8.17999 17 9.00099 17C9.82199 17 10.517 16.425 10.69 15.603C10.721 15.456 10.684 15.302 10.589 15.185C10.494 15.068 10.351 15 10.2 15Z'
121
+
122
+ function NotificationBell({ nodes }) {
123
+ const [open, setOpen] = useState(false)
124
+ const [ring, setRing] = useState(0)
125
+ const rootRef = useRef(null)
126
+ const todo = nodes.filter(n => n.status === 'todo')
127
+ const count = todo.length
128
+ const prevRef = useRef(count)
129
+ useEffect(() => {
130
+ if (count !== prevRef.current) { prevRef.current = count; setRing(r => r + 1) }
131
+ }, [count])
132
+ useEffect(() => {
133
+ if (!open) return
134
+ const onDown = e => { if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false) }
135
+ const onKey = e => { if (e.key === 'Escape') setOpen(false) }
136
+ document.addEventListener('pointerdown', onDown)
137
+ document.addEventListener('keydown', onKey)
138
+ return () => {
139
+ document.removeEventListener('pointerdown', onDown)
140
+ document.removeEventListener('keydown', onKey)
141
+ }
142
+ }, [open])
143
+ return h('div', { className: 'ls-bell-wrap', ref: rootRef },
144
+ h('button', {
145
+ className: 'ls-bell' + (open ? ' open' : ''), type: 'button',
146
+ 'aria-expanded': open, 'aria-label': count ? `剩余 ${count} 个节点未学` : '所有节点已确认',
147
+ title: count ? `剩余 ${count} 个节点未学` : '所有节点已确认',
148
+ onClick: e => { e.stopPropagation(); setOpen(v => !v) },
149
+ },
150
+ h('svg', {
151
+ key: ring, className: ring ? 'ls-bell-swing' : '', viewBox: '0 0 18 18',
152
+ width: 17, height: 17, fill: 'currentColor', 'aria-hidden': true,
153
+ },
154
+ h('path', { fillOpacity: .55, d: BELL_BODY }),
155
+ h('path', { d: BELL_CLAPPER })),
156
+ count > 0 ? h('span', { className: 'ls-bell-badge' }, count > 99 ? '99+' : count) : null),
157
+ open ? h('div', { className: 'ls-bell-pop', onClick: e => e.stopPropagation() },
158
+ h('div', { className: 'ls-bell-pop-h' }, count ? `剩余 ${count} 个节点未学` : '所有节点已确认'),
159
+ count ? h('div', { className: 'ls-bell-pop-list' }, todo.map(n =>
160
+ h('div', { key: n.label, className: 'ls-bell-pop-item' },
161
+ h('span', { className: 'ls-dot', style: { background: STATUS_COLOR.todo, flex: 'none' } }),
162
+ cleanLabel(n.label)))) : null) : null)
163
+ }
164
+
165
+ // ── 模型选择:按 provider 分组的搜索式下拉(ModelPicker 的移植版) ──
166
+ function ModelPicker({ models, value, onChange, disabled, placeholder }) {
167
+ const [open, setOpen] = useState(false)
168
+ const [q, setQ] = useState('')
169
+ const [active, setActive] = useState(0)
170
+ const [dropUp, setDropUp] = useState(false)
171
+ const rootRef = useRef(null)
172
+ const triggerRef = useRef(null)
173
+ const inputRef = useRef(null)
174
+ const listRef = useRef(null)
175
+ const selected = models.find(m => m.provider === value.provider && m.modelId === value.model)
176
+ const filtered = useMemo(() => {
177
+ const s = q.trim().toLowerCase()
178
+ return s ? models.filter(m => `${m.name} ${m.providerName}`.toLowerCase().includes(s)) : models
179
+ }, [models, q])
180
+ const sections = []
181
+ filtered.forEach((m, i) => {
182
+ const last = sections[sections.length - 1]
183
+ if (last && last.name === m.providerName) last.items.push({ m, i })
184
+ else sections.push({ name: m.providerName, items: [{ m, i }] })
185
+ })
186
+
187
+ useEffect(() => { if (disabled) setOpen(false) }, [disabled])
188
+ useEffect(() => {
189
+ if (!open) { setQ(''); return }
190
+ const rect = triggerRef.current && triggerRef.current.getBoundingClientRect()
191
+ setDropUp(!!rect && rect.bottom + 300 > window.innerHeight && rect.top > 300)
192
+ setActive(Math.max(0, models.findIndex(m => m.provider === value.provider && m.modelId === value.model)))
193
+ if (inputRef.current) inputRef.current.focus()
194
+ }, [open])
195
+ useEffect(() => {
196
+ if (!open) return
197
+ const onDown = e => { if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false) }
198
+ document.addEventListener('pointerdown', onDown)
199
+ return () => document.removeEventListener('pointerdown', onDown)
200
+ }, [open])
201
+ useEffect(() => {
202
+ if (!open || !listRef.current) return
203
+ const row = listRef.current.querySelector(`[data-i="${active}"]`)
204
+ if (row) row.scrollIntoView({ block: 'nearest' })
205
+ }, [active, open])
206
+
207
+ const pick = m => {
208
+ onChange({ provider: m.provider, model: m.modelId })
209
+ setOpen(false)
210
+ }
211
+ const onKey = e => {
212
+ if (e.key === 'ArrowDown') { e.preventDefault(); setActive(i => (i + 1) % Math.max(1, filtered.length)) }
213
+ else if (e.key === 'ArrowUp') { e.preventDefault(); setActive(i => (i - 1 + filtered.length) % Math.max(1, filtered.length)) }
214
+ else if (e.key === 'Enter') { e.preventDefault(); if (filtered[active]) pick(filtered[active]) }
215
+ else if (e.key === 'Escape') { e.preventDefault(); setOpen(false) }
216
+ }
217
+ return h('div', { className: 'ls-mp' + (open ? ' open' : ''), ref: rootRef },
218
+ h('button', {
219
+ className: 'ls-mp-trigger', type: 'button', disabled, ref: triggerRef,
220
+ 'aria-haspopup': 'listbox', 'aria-expanded': open,
221
+ onClick: () => setOpen(v => !v),
222
+ onKeyDown: e => { if (e.key === 'ArrowDown' || e.key === 'Enter') { e.preventDefault(); if (!disabled) setOpen(true) } },
223
+ },
224
+ h('span', { className: 'ls-mp-icon' }, (selected ? selected.providerName : '?').slice(0, 1)),
225
+ h('span', { className: 'ls-mp-name' }, selected ? selected.name : (placeholder || '选择模型')),
226
+ h('svg', { className: 'ls-mp-chev', viewBox: '0 0 12 12', width: 12, height: 12,
227
+ fill: 'none', stroke: 'currentColor', strokeWidth: 1.6 },
228
+ h('path', { d: 'M3 4.5L6 7.5L9 4.5', strokeLinecap: 'round', strokeLinejoin: 'round' }))),
229
+ open ? h('div', { className: 'ls-mp-panel' + (dropUp ? ' up' : ''), onKeyDown: onKey },
230
+ h('div', { className: 'ls-mp-search' },
231
+ h('svg', { viewBox: '0 0 16 16', width: 14, height: 14, fill: 'none', stroke: 'currentColor', strokeWidth: 1.6 },
232
+ h('circle', { cx: 7, cy: 7, r: 4.5 }), h('path', { d: 'M10.5 10.5L14 14', strokeLinecap: 'round' })),
233
+ h('input', {
234
+ ref: inputRef, value: q, placeholder: '搜索模型', 'aria-label': '搜索模型',
235
+ onChange: e => { setQ(e.target.value); setActive(0) },
236
+ })),
237
+ h('div', { className: 'ls-mp-list', role: 'listbox', ref: listRef },
238
+ sections.length ? sections.map(s => h('div', { key: s.name, role: 'group' },
239
+ h('div', { className: 'ls-mp-group' }, s.name),
240
+ s.items.map(({ m, i }) => {
241
+ const sel = m.provider === value.provider && m.modelId === value.model
242
+ return h('div', {
243
+ key: `${m.provider}-${m.modelId}`, role: 'option', 'aria-selected': sel,
244
+ 'data-i': i, className: 'ls-mp-item' + (i === active ? ' active' : ''),
245
+ onMouseEnter: () => setActive(i),
246
+ onMouseDown: e => e.preventDefault(),
247
+ onClick: () => pick(m),
248
+ },
249
+ h('span', { className: 'ls-mp-icon' }, m.providerName.slice(0, 1)),
250
+ h('span', { className: 'ls-mp-item-name' }, m.name),
251
+ sel ? h('svg', { className: 'ls-check', viewBox: '0 0 16 16', width: 13, height: 13,
252
+ fill: 'none', stroke: 'currentColor', strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round' },
253
+ h('path', { d: 'M3 8.5l3.2 3.2L13 4.5' })) : null)
254
+ }))) : h('div', { className: 'ls-mp-empty' }, '没有匹配的模型'))) : null)
255
+ }
256
+
20
257
  function PanelIcon() {
21
258
  return h('svg', { viewBox: '0 0 24 24', width: 22, height: 22, 'aria-hidden': true },
22
259
  h('path', {
@@ -54,7 +291,8 @@ window.__ModuleLoader__.load({
54
291
  .ls-node { display: flex; align-items: center; gap: 8px; padding: 3px 0; font-size: 13px; }
55
292
  .ls-journal-item { padding: 3px 0; font-size: 13px; color: var(--dsw-alias-label-secondary); }
56
293
  .ls-btn { font-family: inherit; font-size: 12px; padding: 3px 12px; cursor: pointer;
57
- background: var(--dsw-alias-brand-primary); color: #fff; border: none; border-radius: 4px; flex: none; }
294
+ background: var(--dsw-alias-brand-primary); color: var(--dsw-alias-label-primary-foreground, #fff);
295
+ border: none; border-radius: 4px; flex: none; }
58
296
  .ls-btn:disabled { opacity: .5; cursor: default; }
59
297
  .ls-new { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
60
298
  .ls-input { flex: 1; min-width: 120px; font-family: inherit; font-size: 13px; color: var(--dsw-alias-label-primary);
@@ -78,8 +316,10 @@ window.__ModuleLoader__.load({
78
316
  .ls-chat-title { font-size: 12px; color: var(--dsw-alias-label-secondary); }
79
317
  .ls-chat-list { max-height: 320px; overflow-y: auto; padding: 4px 2px; display: flex; flex-direction: column; gap: 8px; }
80
318
  .ls-msg { max-width: 88%; border-radius: 8px; padding: 6px 10px; font-size: 13px; }
81
- .ls-msg-user { align-self: flex-end; background: var(--dsw-alias-brand-primary); color: #fff; }
82
- .ls-msg-assistant { align-self: flex-start; background: var(--dsw-alias-bg-layer-2); }
319
+ .ls-msg-user { align-self: flex-end; background: var(--dsw-alias-brand-primary);
320
+ color: var(--dsw-alias-label-primary-foreground, #fff); }
321
+ .ls-msg-assistant { align-self: flex-start; background: var(--dsw-alias-bg-layer-2);
322
+ animation: ls-soft-in .24s ease-out; }
83
323
  .ls-msg-user .ls-md-code { background: rgba(255,255,255,.25); }
84
324
  .ls-md-p { margin: 2px 0; white-space: pre-wrap; word-break: break-word; }
85
325
  .ls-md-h { font-size: 13px; font-weight: 700; margin: 6px 0 2px; }
@@ -88,8 +328,12 @@ window.__ModuleLoader__.load({
88
328
  .ls-md-pre { margin: 4px 0; padding: 8px 10px; background: var(--dsw-alias-bg-layer-1);
89
329
  border: 1px solid var(--dsw-alias-border-l1); border-radius: 6px; overflow-x: auto; }
90
330
  .ls-md-pre code { font-family: Consolas, monospace; font-size: 12px; white-space: pre; }
331
+ .ls-math { white-space: normal; }
332
+ .ls-math-block { display: block; margin: 6px 0; padding: 2px 0; overflow-x: auto; overflow-y: hidden; text-align: center; }
333
+ .ls-math-block .katex-display { margin: 0; }
334
+ .ls-math-fallback { font-family: Consolas, monospace; font-size: 12px; white-space: pre-wrap;
335
+ color: var(--dsw-alias-state-warning-primary, #b7791f); }
91
336
  .ls-tool { align-self: flex-start; font-size: 12px; color: var(--dsw-alias-label-secondary); }
92
- .ls-thinking { align-self: flex-start; font-size: 12px; color: var(--dsw-alias-label-secondary); padding: 2px 4px; }
93
337
  .ls-chat-err { font-size: 12px; color: var(--dsw-alias-state-danger-primary, #B5432E); padding: 4px 0; }
94
338
  .ls-chat-row { display: flex; gap: 8px; margin-top: 8px; align-items: flex-end; }
95
339
  .ls-chat-input { flex: 1; resize: vertical; min-height: 34px; max-height: 120px; }
@@ -124,7 +368,7 @@ window.__ModuleLoader__.load({
124
368
  .ls-modal-body { font-size: 13px; color: var(--dsw-alias-label-secondary); line-height: 1.7; margin-bottom: 14px; }
125
369
  .ls-modal-body strong { color: var(--dsw-alias-state-danger-primary, #B5432E); }
126
370
  .ls-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
127
- .ls-btn-danger { background: #B5432E; }
371
+ .ls-btn-danger { background: #B5432E; color: #fff; }
128
372
  .ls-title-row { display: flex; align-items: center; gap: 10px; }
129
373
  .ls-title-row .ls-title { margin: 0 0 2px; }
130
374
  .ls-gear { border: 1px solid var(--dsw-alias-border-l1); background: var(--dsw-alias-bg-layer-1);
@@ -204,6 +448,140 @@ window.__ModuleLoader__.load({
204
448
  .ls-layout { grid-template-columns: 1fr; }
205
449
  .ls-side { position: static; }
206
450
  }
451
+
452
+ /* ── AI 状态行(AiStatus) ───────────────────────── */
453
+ .ls-aistatus { display: inline-flex; align-items: center; gap: 7px; align-self: flex-start;
454
+ height: 24px; font-size: 12px; color: var(--dsw-alias-label-secondary);
455
+ animation: ls-soft-in .24s ease-out; }
456
+ .ls-aistatus-icon { display: inline-grid; place-items: center; width: 16px; height: 16px; flex: none; }
457
+ .ls-aistatus-label { font-weight: 600; letter-spacing: .2px; }
458
+ .ls-aistatus.active .ls-aistatus-label {
459
+ background-image: linear-gradient(90deg,
460
+ var(--dsw-alias-label-secondary) 42%,
461
+ var(--dsw-alias-label-primary) 50%,
462
+ var(--dsw-alias-label-secondary) 58%);
463
+ background-size: 250% 100%; -webkit-background-clip: text; background-clip: text; color: transparent;
464
+ animation: ls-shimmer 1.6s linear infinite; }
465
+ .ls-aistatus-detail, .ls-aistatus-time { color: var(--dsw-alias-label-secondary); opacity: .72; font-weight: 500; }
466
+ .ls-aistatus-time { font-variant-numeric: tabular-nums; }
467
+ .ls-aistatus-done { color: var(--dsw-alias-state-success-primary); }
468
+ .ls-ai-spark { transform-origin: 11px 13px; animation: ls-spark 2.4s ease-in-out infinite; }
469
+ .ls-ai-spark2 { transform-origin: 18px 5px; animation: ls-spark2 1.2s ease-in-out infinite; }
470
+ .ls-ai-bar { animation: ls-bar .9s ease-in-out infinite; }
471
+ .ls-ai-bar:nth-child(2) { animation-delay: .15s; }
472
+ .ls-ai-bar:nth-child(3) { animation-delay: .3s; }
473
+ .ls-ai-check { stroke-dasharray: 22; stroke-dashoffset: 22; animation: ls-draw .45s ease-out .05s forwards; }
474
+ @keyframes ls-shimmer { from { background-position: 100% 0; } to { background-position: 0% 0; } }
475
+ @keyframes ls-soft-in { from { opacity: 0; transform: translateY(3px); } to { opacity: 1; transform: none; } }
476
+ @keyframes ls-spark { 0%, 100% { transform: rotate(0) scale(1); } 50% { transform: rotate(90deg) scale(.82); } }
477
+ @keyframes ls-spark2 { 0%, 100% { transform: scale(.5); opacity: .35; } 50% { transform: scale(1); opacity: 1; } }
478
+ @keyframes ls-bar { 0%, 100% { transform: scaleY(.35); } 50% { transform: scaleY(1); } }
479
+ @keyframes ls-draw { to { stroke-dashoffset: 0; } }
480
+
481
+ /* ── 剩余节点铃铛(NotificationBell) ─────────────── */
482
+ .ls-bell-wrap { position: relative; flex: none; }
483
+ .ls-bell { position: relative; display: grid; place-items: center; width: 30px; height: 30px;
484
+ padding: 0; border: 1px solid var(--dsw-alias-border-l1); border-radius: 50%;
485
+ background: var(--dsw-alias-bg-layer-1); color: var(--dsw-alias-label-secondary); cursor: pointer;
486
+ transition: border-color .15s, color .15s, transform .08s; }
487
+ .ls-bell:hover { border-color: var(--dsw-alias-border-l2); color: var(--dsw-alias-label-primary); }
488
+ .ls-bell:active { transform: scale(.94); }
489
+ .ls-bell.open { border-color: var(--dsw-alias-brand-primary); color: var(--dsw-alias-brand-primary); }
490
+ .ls-bell-badge { position: absolute; top: -4px; right: -4px; min-width: 16px; height: 16px; padding: 0 4px;
491
+ border-radius: 8px; background: #B5432E; color: #fff; font-size: 10px; font-weight: 700;
492
+ line-height: 1; display: grid; place-items: center; animation: ls-badge-pop .3s ease-out; }
493
+ .ls-bell-swing { animation: ls-bell-ring .9s ease-in-out; transform-origin: 50% 12%; }
494
+ .ls-bell-pop { position: absolute; top: calc(100% + 8px); right: 0; width: 240px; z-index: 80;
495
+ padding: 10px 12px; background: var(--dsw-alias-bg-layer-1);
496
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 10px;
497
+ box-shadow: 0 10px 30px rgba(0,0,0,.16); transform-origin: top right;
498
+ animation: ls-pop-in .22s cubic-bezier(.2,.85,.25,1); }
499
+ .ls-bell-pop-h { font-size: 12px; font-weight: 600; margin-bottom: 6px; }
500
+ .ls-bell-pop-list { display: flex; flex-direction: column; gap: 1px; max-height: 220px; overflow-y: auto; }
501
+ .ls-bell-pop-item { display: flex; align-items: center; gap: 7px; padding: 3px 0;
502
+ font-size: 12px; color: var(--dsw-alias-label-secondary); }
503
+ @keyframes ls-bell-ring {
504
+ 0% { transform: rotate(0); } 15% { transform: rotate(14deg); } 30% { transform: rotate(-12deg); }
505
+ 45% { transform: rotate(9deg); } 60% { transform: rotate(-6deg); } 80% { transform: rotate(3deg); }
506
+ 100% { transform: rotate(0); } }
507
+ @keyframes ls-badge-pop { 0% { transform: scale(.4); opacity: 0; } 60% { transform: scale(1.15); } 100% { transform: scale(1); opacity: 1; } }
508
+ @keyframes ls-pop-in { from { opacity: 0; transform: translateY(-4px) scale(.97); } to { opacity: 1; transform: none; } }
509
+
510
+ /* ── 模型选择(ModelPicker) ─────────────────────── */
511
+ .ls-mp { position: relative; }
512
+ .ls-mp-trigger { display: flex; align-items: center; gap: 8px; width: 100%; height: 34px;
513
+ padding: 0 12px 0 8px; font-family: inherit; font-size: 13px; text-align: left;
514
+ color: var(--dsw-alias-label-primary); background: var(--dsw-alias-bg-layer-1);
515
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 17px; cursor: pointer;
516
+ transition: border-color .15s; }
517
+ .ls-mp-trigger:hover:not(:disabled) { border-color: var(--dsw-alias-border-l2); }
518
+ .ls-mp-trigger:disabled { opacity: .5; cursor: default; }
519
+ .ls-mp.open .ls-mp-trigger { border-color: var(--dsw-alias-brand-primary); }
520
+ .ls-mp-icon { display: grid; place-items: center; width: 20px; height: 20px; flex: none;
521
+ border-radius: 6px; background: var(--dsw-alias-bg-layer-2); text-transform: uppercase;
522
+ font-size: 10px; font-weight: 700; color: var(--dsw-alias-label-secondary); }
523
+ .ls-mp-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
524
+ .ls-mp-chev { flex: none; transition: transform .18s; }
525
+ .ls-mp.open .ls-mp-chev { transform: rotate(180deg); }
526
+ .ls-mp-panel { position: absolute; top: calc(100% + 6px); left: 0; width: 100%; min-width: 268px;
527
+ z-index: 90; overflow: hidden; background: var(--dsw-alias-bg-layer-1);
528
+ border: 1px solid var(--dsw-alias-border-l1); border-radius: 12px;
529
+ box-shadow: 0 12px 36px rgba(0,0,0,.18);
530
+ animation: ls-pop-in .22s cubic-bezier(.2,.85,.25,1); }
531
+ .ls-mp-panel.up { top: auto; bottom: calc(100% + 6px); transform-origin: bottom left; }
532
+ .ls-mp-search { display: flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px;
533
+ border-bottom: 1px solid var(--dsw-alias-border-l1); color: var(--dsw-alias-label-secondary); }
534
+ .ls-mp-search input { flex: 1; min-width: 0; border: none; outline: none; background: transparent;
535
+ font-family: inherit; font-size: 12px; color: var(--dsw-alias-label-primary); }
536
+ .ls-mp-list { max-height: 248px; overflow-y: auto; padding: 6px; }
537
+ .ls-mp-group { padding: 6px 8px 3px; font-size: 11px; letter-spacing: .5px;
538
+ color: var(--dsw-alias-label-secondary); }
539
+ .ls-mp-item { display: flex; align-items: center; gap: 8px; height: 34px; padding: 0 8px;
540
+ border-radius: 8px; font-size: 13px; color: var(--dsw-alias-label-primary); cursor: pointer; }
541
+ .ls-mp-item.active { background: var(--dsw-alias-bg-layer-2); }
542
+ .ls-mp-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
543
+ .ls-mp-item .ls-check { color: var(--dsw-alias-brand-primary); flex: none; }
544
+ .ls-mp-empty { padding: 14px 8px; text-align: center; font-size: 12px; color: var(--dsw-alias-label-secondary); }
545
+
546
+ /* ── Toast ──────────────────────────────────────── */
547
+ .ls-toasts { position: fixed; right: 18px; bottom: 18px; z-index: 240; display: flex;
548
+ flex-direction: column-reverse; gap: 10px; width: 304px; max-width: calc(100vw - 36px);
549
+ pointer-events: none; }
550
+ .ls-toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 10px;
551
+ background: var(--dsw-alias-bg-layer-1); border: 1px solid var(--dsw-alias-border-l1);
552
+ border-radius: 14px; box-shadow: 0 6px 24px rgba(0,0,0,.14);
553
+ animation: ls-toast-in .3s cubic-bezier(.2,.85,.25,1); }
554
+ .ls-toast.leaving { animation: ls-toast-out .18s ease-in forwards; }
555
+ .ls-toast-tile { display: grid; place-items: center; width: 34px; height: 34px; flex: none;
556
+ border-radius: 11px; color: #fff; }
557
+ .ls-toast-tile.success { background: var(--dsw-alias-state-success-primary); }
558
+ .ls-toast-tile.error { background: var(--dsw-alias-state-danger-primary, #B5432E); }
559
+ .ls-toast-tile.warning { background: var(--dsw-alias-state-warning-primary, #B7791F); }
560
+ .ls-toast-tile.info { background: var(--dsw-alias-brand-primary);
561
+ color: var(--dsw-alias-label-primary-foreground, #fff); }
562
+ .ls-toast-tile.loading { background: var(--dsw-alias-bg-layer-2); color: var(--dsw-alias-label-secondary); }
563
+ .ls-toast-body { flex: 1; min-width: 0; }
564
+ .ls-toast-title { font-size: 13px; font-weight: 600; line-height: 1.35; }
565
+ .ls-toast-desc { margin-top: 1px; font-size: 12px; line-height: 1.5;
566
+ color: var(--dsw-alias-label-secondary); word-break: break-word; }
567
+ .ls-toast-x { flex: none; border: none; background: none; padding: 2px 4px; cursor: pointer;
568
+ font-size: 14px; line-height: 1; color: var(--dsw-alias-label-secondary); }
569
+ .ls-toast-x:hover { color: var(--dsw-alias-label-primary); }
570
+ .ls-spin { animation: ls-spin .9s linear infinite; }
571
+ @keyframes ls-spin { to { transform: rotate(360deg); } }
572
+ @keyframes ls-toast-in { from { opacity: 0; transform: translateY(10px) scale(.96); } to { opacity: 1; transform: none; } }
573
+ @keyframes ls-toast-out { to { opacity: 0; transform: translateX(8px) scale(.97); } }
574
+
575
+ /* 按钮反馈 */
576
+ .ls-btn { transition: background-color .15s, border-color .15s, transform .08s; }
577
+ .ls-btn:active:not(:disabled) { transform: translateY(1px) scale(.99); }
578
+ .ls-btn:focus-visible { outline: 2px solid var(--dsw-alias-brand-primary); outline-offset: 1px; }
579
+
580
+ @media (prefers-reduced-motion: reduce) {
581
+ .ls-aistatus, .ls-aistatus-label, .ls-ai-spark, .ls-ai-spark2, .ls-ai-bar, .ls-ai-check,
582
+ .ls-toast, .ls-bell-swing, .ls-bell-badge, .ls-bell-pop, .ls-mp-panel, .ls-spin {
583
+ animation: none !important; }
584
+ }
207
585
  `
208
586
 
209
587
  /** 极简 DAG 分层布局:roots 在底,目标在顶 */
@@ -319,29 +697,75 @@ window.__ModuleLoader__.load({
319
697
  )
320
698
  }
321
699
 
322
- /** 行内 markdown:**加粗** 与 `行内码`,其余按原文本 */
700
+ /** KaTeX 模块级 Promise 单例:注入样式表 + UMD,失败记 katexFailed 不再重试 */
701
+ let katexPromise = null
702
+ let katexFailed = false
703
+ function loadKatex() {
704
+ if (katexFailed) return Promise.reject(new Error('katex asset failed'))
705
+ if (!katexPromise) {
706
+ katexPromise = new Promise((resolve, reject) => {
707
+ const link = document.createElement('link')
708
+ link.rel = 'stylesheet'
709
+ link.href = '/api/learning-space/assets/katex/katex.min.css'
710
+ document.head.appendChild(link)
711
+ const s = document.createElement('script')
712
+ s.src = '/api/learning-space/assets/katex/katex.min.js'
713
+ s.onload = () => {
714
+ if (window.katex) resolve(window.katex)
715
+ else { katexFailed = true; katexPromise = null; reject(new Error('katex 未挂载')) }
716
+ }
717
+ s.onerror = () => { katexFailed = true; katexPromise = null; reject(new Error('katex 资产加载失败')) }
718
+ document.head.appendChild(s)
719
+ })
720
+ }
721
+ return katexPromise
722
+ }
723
+
724
+ /** LaTeX 公式:katex.render 写进 ref 元素(不拼用户文本进 innerHTML),失败降级显示原始 TeX */
725
+ function MathNode({ tex, block }) {
726
+ const ref = useRef(null)
727
+ const [failed, setFailed] = useState(false)
728
+ useEffect(() => {
729
+ let alive = true
730
+ loadKatex().then(k => {
731
+ if (!alive || !ref.current) return
732
+ k.render(tex, ref.current, { displayMode: !!block, throwOnError: false, strict: false })
733
+ }).catch(() => { if (alive) setFailed(true) })
734
+ return () => { alive = false }
735
+ }, [tex, block])
736
+ if (failed) return h('code', { className: 'ls-math-fallback' }, block ? `$$${tex}$$` : `$${tex}$`)
737
+ return h(block ? 'div' : 'span', { className: block ? 'ls-math ls-math-block' : 'ls-math', ref })
738
+ }
739
+
740
+ /** 行内 markdown:**加粗**、`行内码`、$$…$$ / $…$ / \(…\) 公式,其余按原文本 */
323
741
  function inlineNodes(text, keyBase) {
742
+ const src = String(text == null ? '' : text)
324
743
  const out = []
325
- const re = /(\*\*[^*]+\*\*|`[^`]+`)/g
744
+ const re = /(\*\*[^*]+\*\*|`[^`]+`|\$\$[^$\n]+?\$\$|(?<!\\)\$(?![\s$])[^$\n]+?(?<![\s\\])\$(?!\d)|\\\((?:[^\\\n]|\\.)+?\\\)|\\\[(?:[^\\\n]|\\.)+?\\\])/g
326
745
  let last = 0, m, i = 0
327
- while ((m = re.exec(text))) {
328
- if (m.index > last) out.push(text.slice(last, m.index))
746
+ while ((m = re.exec(src))) {
747
+ if (m.index > last) out.push(src.slice(last, m.index))
329
748
  const t = m[0]
330
749
  if (t.startsWith('**')) out.push(h('strong', { key: `${keyBase}b${i}` }, t.slice(2, -2)))
331
- else out.push(h('code', { key: `${keyBase}c${i}`, className: 'ls-md-code' }, t.slice(1, -1)))
750
+ else if (t.startsWith('`')) out.push(h('code', { key: `${keyBase}c${i}`, className: 'ls-md-code' }, t.slice(1, -1)))
751
+ else if (t.startsWith('$$')) out.push(h(MathNode, { key: `${keyBase}m${i}`, tex: t.slice(2, -2), block: false }))
752
+ else if (t.startsWith('$')) out.push(h(MathNode, { key: `${keyBase}m${i}`, tex: t.slice(1, -1), block: false }))
753
+ else out.push(h(MathNode, { key: `${keyBase}m${i}`, tex: t.slice(2, -2), block: false }))
332
754
  last = m.index + t.length
333
755
  i++
334
756
  }
335
- if (last < text.length) out.push(text.slice(last))
757
+ if (last < src.length) out.push(src.slice(last))
336
758
  return out
337
759
  }
338
760
 
339
- /** 极简 markdown → React 元素数组(代码块/标题/列表/加粗/行内码),无法识别的行原样输出 */
761
+ /** 极简 markdown → React 元素数组(代码块/块级公式/标题/列表/加粗/行内码/行内公式),无法识别的行原样输出 */
340
762
  function markdownLite(text) {
341
763
  const lines = String(text || '').split(/\r?\n/)
342
764
  const els = []
343
765
  let code = null
344
766
  let list = null
767
+ let math = null
768
+ let mathClose = null
345
769
  let k = 0
346
770
  const flushCode = () => {
347
771
  if (code) { els.push(h('pre', { key: `pre${k++}`, className: 'ls-md-pre' }, h('code', null, code.join('\n')))); code = null }
@@ -349,6 +773,13 @@ window.__ModuleLoader__.load({
349
773
  const flushList = () => {
350
774
  if (list && list.length) { els.push(h('ul', { key: `ul${k++}`, className: 'ls-md-ul' }, list.map((li, i) => h('li', { key: i }, li)))); list = null }
351
775
  }
776
+ const flushMath = () => {
777
+ if (!math) return
778
+ const tex = math.join('\n').trim()
779
+ math = null; mathClose = null
780
+ if (tex) els.push(h(MathNode, { key: `m${k++}`, tex, block: true }))
781
+ }
782
+ const pushMath = (tex) => { els.push(h(MathNode, { key: `m${k++}`, tex, block: true })) }
352
783
  for (const line of lines) {
353
784
  if (/^\s*```/.test(line)) {
354
785
  if (code) flushCode()
@@ -356,6 +787,33 @@ window.__ModuleLoader__.load({
356
787
  continue
357
788
  }
358
789
  if (code) { code.push(line); continue }
790
+ if (math) {
791
+ const closeAt = line.search(mathClose)
792
+ if (closeAt >= 0) {
793
+ const before = line.slice(0, closeAt)
794
+ if (before.trim()) math.push(before)
795
+ flushMath()
796
+ } else math.push(line)
797
+ continue
798
+ }
799
+ // 块级公式:$$…$$ 或 \[…\],同行闭合且后面没正文才当块,否则交给行内处理(免得吞掉尾部文字)
800
+ const openAt = /^\s*(?:\$\$|\\\[)/.test(line) ? (/^\s*\$\$/.test(line) ? line.indexOf('$$') : line.indexOf('\\[')) : -1
801
+ if (openAt >= 0) {
802
+ const dollar = line[openAt] === '$'
803
+ const body = line.slice(openAt + 2)
804
+ const closeRe = dollar ? /\$\$/ : /\\\]/
805
+ const closeAt = body.search(closeRe)
806
+ const after = closeAt >= 0 ? body.slice(closeAt + 2) : ''
807
+ if (closeAt < 0 || !after.trim()) {
808
+ flushList()
809
+ if (closeAt < 0) { math = []; mathClose = closeRe; if (body.trim()) math.push(body) }
810
+ else {
811
+ const tex = body.slice(0, closeAt).trim()
812
+ if (tex) pushMath(tex)
813
+ }
814
+ continue
815
+ }
816
+ }
359
817
  const hm = /^(#{1,3})\s+(.*)$/.exec(line)
360
818
  if (hm) {
361
819
  flushList()
@@ -372,6 +830,7 @@ window.__ModuleLoader__.load({
372
830
  }
373
831
  flushCode()
374
832
  flushList()
833
+ flushMath()
375
834
  return els
376
835
  }
377
836
 
@@ -388,7 +847,7 @@ window.__ModuleLoader__.load({
388
847
  quiz.state === 'graded'
389
848
  ? h('span', { className: 'ls-quiz-badge' + (quiz.correct ? ' ok' : ' bad') }, quiz.correct ? '✅ 答对' : '❌ 答错')
390
849
  : answered ? h('span', { className: 'ls-quiz-badge wait' }, '已作答,等待反馈') : null),
391
- quiz.stem ? h('div', { className: 'ls-quiz-stem' }, quiz.stem) : null,
850
+ quiz.stem ? h('div', { className: 'ls-quiz-stem' }, inlineNodes(quiz.stem, 'qs')) : null,
392
851
  h('div', { className: 'ls-quiz-opts' },
393
852
  (quiz.options || []).map(o =>
394
853
  h('button', {
@@ -399,7 +858,7 @@ window.__ModuleLoader__.load({
399
858
  onClick: () => { Promise.resolve(onAnswer(o.key)).then(ok => setLocalAnswer(ok ? o.key : null)) },
400
859
  },
401
860
  h('span', { className: 'ls-quiz-opt-key' }, o.key),
402
- h('span', null, o.text)))),
861
+ h('span', null, inlineNodes(o.text, `qo${o.key}`))))),
403
862
  )
404
863
  }
405
864
 
@@ -428,9 +887,9 @@ window.__ModuleLoader__.load({
428
887
  r.node ? h('span', { className: 'ls-qh-node' }, r.node) : null,
429
888
  h('span', { className: 'ls-qh-ans' }, `答 ${r.answer}`)),
430
889
  openSeq === r.fbSeq ? h('div', { className: 'ls-qh-detail' },
431
- h('div', { className: 'ls-qh-line' }, `题面:${r.stem}`),
432
- h('div', { className: 'ls-qh-line' }, `选项:${r.options}`),
433
- h('div', { className: 'ls-qh-line' }, `反馈:${r.feedback}`)) : null))),
890
+ h('div', { className: 'ls-qh-line' }, '题面:', inlineNodes(r.stem, `qhs${r.fbSeq}`)),
891
+ h('div', { className: 'ls-qh-line' }, '选项:', inlineNodes(r.options, `qho${r.fbSeq}`)),
892
+ h('div', { className: 'ls-qh-line' }, '反馈:', inlineNodes(r.feedback, `qhf${r.fbSeq}`))) : null))),
434
893
  )
435
894
  }
436
895
 
@@ -448,6 +907,9 @@ window.__ModuleLoader__.load({
448
907
  const inFlightRef = useRef(false)
449
908
  const pendingIdRef = useRef(0)
450
909
  const listRef = useRef(null)
910
+ const [doneInfo, setDoneInfo] = useState(null)
911
+ const prevRunningRef = useRef(false)
912
+ const runStartRef = useRef(null)
451
913
 
452
914
  const poll = useCallback(async () => {
453
915
  if (inFlightRef.current) return
@@ -495,7 +957,20 @@ window.__ModuleLoader__.load({
495
957
  }, [topic, phase])
496
958
 
497
959
  useEffect(() => { poll(); const t = setInterval(poll, 2500); return () => clearInterval(t) }, [poll])
498
- useEffect(() => { if (listRef.current) listRef.current.scrollTop = listRef.current.scrollHeight }, [messages, running])
960
+ // running 由 true→false 视为一轮结束:记下用时并短暂展示完成态
961
+ useEffect(() => {
962
+ if (running && !prevRunningRef.current) runStartRef.current = Date.now()
963
+ if (!running && prevRunningRef.current && runStartRef.current) {
964
+ const sec = Math.max(1, Math.round((Date.now() - runStartRef.current) / 1000))
965
+ runStartRef.current = null
966
+ setDoneInfo({ sec })
967
+ prevRunningRef.current = running
968
+ const t = setTimeout(() => setDoneInfo(null), 2600)
969
+ return () => clearTimeout(t)
970
+ }
971
+ prevRunningRef.current = running
972
+ }, [running])
973
+ useEffect(() => { if (listRef.current) listRef.current.scrollTop = listRef.current.scrollHeight }, [messages, running, doneInfo])
499
974
 
500
975
  // 发文本(输入框与 QuizCard 点选共用):失败里 409 = 绑定会话已失效
501
976
  const sendText = async (text) => {
@@ -517,10 +992,11 @@ window.__ModuleLoader__.load({
517
992
  poll()
518
993
  return true
519
994
  }
520
- if (j.error === 'session gone, start first') { setErr('会话已失效'); setNeedRebind(true); return false }
521
- setErr(j.error)
522
- return false
523
- } catch (e) { setErr(String(e)); return false }
995
+ if (j.error === 'session gone, start first') {
996
+ setErr('会话已失效'); setNeedRebind(true); toast.warning('会话已失效', '点「重新绑定」即可继续'); return false
997
+ }
998
+ setErr(j.error); toast.error('发送失败', j.error); return false
999
+ } catch (e) { setErr(String(e)); toast.error('发送失败', String(e)); return false }
524
1000
  finally { setSending(false) }
525
1001
  }
526
1002
 
@@ -546,11 +1022,20 @@ window.__ModuleLoader__.load({
546
1022
  setMessages([])
547
1023
  lastSeqRef.current = null
548
1024
  poll()
1025
+ toast.success('会话已重新绑定')
549
1026
  } else setErr(j.error || '重新绑定失败')
550
1027
  } catch (e) { setErr(String(e)) }
551
1028
  }
552
1029
 
553
1030
  const last = messages[messages.length - 1]
1031
+ const toolMsg = running && last && last.role === 'tool' && last.state !== 'done' && last.state !== 'error' ? last : null
1032
+ const statusNode = doneInfo && !running
1033
+ ? h(AiStatus, { state: 'done', label: '完成', elapsed: doneInfo.sec })
1034
+ : toolMsg
1035
+ ? h(AiStatus, { state: 'tool', label: '正在调用工具', detail: toolMsg.toolName || '工具' })
1036
+ : running && (!last || last.role !== 'assistant')
1037
+ ? h(AiStatus, { state: 'thinking', label: '思考中' })
1038
+ : null
554
1039
  return h('div', {
555
1040
  className: 'ls-chat',
556
1041
  // 点击对话窗(输入框/按钮/滚动)不冒泡到卡片折叠区,否则一点输入框整块就收起
@@ -596,8 +1081,7 @@ window.__ModuleLoader__.load({
596
1081
  ? h(QuizCard, { quiz: m.quiz, sending, onAnswer: sendText })
597
1082
  : m.role === 'assistant' ? markdownLite(m.text) : m.text)
598
1083
  }),
599
- running && (!last || last.role !== 'assistant')
600
- ? h('div', { className: 'ls-thinking' }, '思考中…') : null),
1084
+ running || doneInfo ? statusNode : null),
601
1085
  err ? h('div', { className: 'ls-chat-err' }, `出错:${err},可点「在会话中打开」继续`) : null,
602
1086
  needRebind ? h('button', { className: 'ls-btn ls-rebind', type: 'button', onClick: rebind }, '会话已失效,重新绑定') : null,
603
1087
  h('div', { className: 'ls-chat-row' },
@@ -674,9 +1158,13 @@ window.__ModuleLoader__.load({
674
1158
  const doUpload = async files => {
675
1159
  setUploading(true); setPct(0); setErr(null)
676
1160
  try {
677
- await uploadFiles(topic.name, files, p => setPct(Math.round(p * 100)))
1161
+ const res = await uploadFiles(topic.name, files, p => setPct(Math.round(p * 100)))
1162
+ toast.success('材料已导入', `${(res && res.files ? res.files.length : files.length) || files.length} 个文件`)
678
1163
  onRefresh()
679
- } catch (e) { setErr(String(e.message || e)) }
1164
+ } catch (e) {
1165
+ const msg = String(e.message || e)
1166
+ setErr(msg); toast.error('上传失败', msg)
1167
+ }
680
1168
  finally { setUploading(false) }
681
1169
  }
682
1170
  return h('div', { className: 'ls-section' },
@@ -787,7 +1275,7 @@ window.__ModuleLoader__.load({
787
1275
  return h('div', { className: 'ls-detail' },
788
1276
  h('div', { className: 'ls-detail-head' },
789
1277
  h('span', { className: 'ls-name' }, topic.name),
790
- h('span', { style: { display: 'flex', gap: 10, alignItems: 'baseline' } },
1278
+ h('span', { style: { display: 'flex', gap: 10, alignItems: 'center' } },
791
1279
  h('span', { className: 'ls-frac' }, phase === 1 ? '阶段一 · 摸底' : `${done}/${total} 已确认`),
792
1280
  h('a', {
793
1281
  className: 'ls-btn', href: `/api/learning-space/export?topic=${encodeURIComponent(topic.name)}`,
@@ -802,7 +1290,8 @@ window.__ModuleLoader__.load({
802
1290
  className: 'ls-btn', title: '新建学习会话,从学习方案开头重新教;旧会话保留在会话列表',
803
1291
  disabled: starting,
804
1292
  onClick: () => onStart(topic.name, 2, true),
805
- }, starting ? '…' : '重新学习 ↻') : null)),
1293
+ }, starting ? '…' : '重新学习 ↻') : null,
1294
+ topic.nodes.length ? h(NotificationBell, { nodes: topic.nodes }) : null)),
806
1295
  topic.goal ? h('div', { className: 'ls-goal' }, topic.goal) : null,
807
1296
  h('div', { className: 'ls-bar' }, h('div', { className: 'ls-bar-fill', style: { width: pct + '%' } })),
808
1297
  h('div', { className: 'ls-badges' },
@@ -896,7 +1385,8 @@ window.__ModuleLoader__.load({
896
1385
  h('div', { className: 'ls-focus-head' },
897
1386
  h('button', { className: 'ls-btn', type: 'button', onClick: onBack }, '← 返回'),
898
1387
  h('span', { className: 'ls-focus-title', title: topic.name }, topic.name),
899
- h('span', { className: 'ls-frac' }, `${done}/${total} 已确认`)),
1388
+ h('span', { className: 'ls-frac' }, `${done}/${total} 已确认`),
1389
+ topic.nodes.length ? h(NotificationBell, { nodes: topic.nodes }) : null),
900
1390
  h(NodeAccordion, { topic }),
901
1391
  h(MaterialList, { topic, onRefresh })),
902
1392
  h('div', { className: 'ls-focus-right' },
@@ -1006,12 +1496,12 @@ window.__ModuleLoader__.load({
1006
1496
  const groups = (catalog && Array.isArray(catalog.groups)) ? catalog.groups : []
1007
1497
  const group = groups.find(g => g.id === provider)
1008
1498
  const models = group ? (group.models || []) : []
1009
-
1010
- const onProviderChange = id => {
1011
- setProvider(id)
1012
- const g = groups.find(x => x.id === id)
1013
- setModel((g && (g.models || [])[0]) ? g.models[0].id : '')
1014
- }
1499
+ const pickerModels = useMemo(() => groups.flatMap(g => (g.models || []).map(m => ({
1500
+ provider: g.id,
1501
+ providerName: g.name || g.id,
1502
+ modelId: m.id,
1503
+ name: m.name || m.id,
1504
+ }))), [catalog])
1015
1505
 
1016
1506
  const save = async () => {
1017
1507
  if (busy) return
@@ -1031,8 +1521,12 @@ window.__ModuleLoader__.load({
1031
1521
  applyToTopic: applyNow && currentTopic ? currentTopic : undefined }),
1032
1522
  })
1033
1523
  const j = await r.json()
1034
- if (!j.ok) { setErr(j.error || '保存失败'); return }
1035
- if (j.applyError) { setApplyNotice(`已保存,但应用到会话失败:${j.applyError}`); return }
1524
+ if (!j.ok) { setErr(j.error || '保存失败'); toast.error('保存失败', j.error || ''); return }
1525
+ if (j.applyError) {
1526
+ const msg = `已保存,但应用到会话失败:${j.applyError}`
1527
+ setApplyNotice(msg); toast.warning('已保存', msg); return
1528
+ }
1529
+ toast.success('模型设置已保存', sel ? `${sel.provider} / ${sel.model}` : '跟随宿主默认')
1036
1530
  onClose(true)
1037
1531
  } catch (e) { setErr(String(e)) }
1038
1532
  finally { setBusy(false) }
@@ -1046,24 +1540,29 @@ window.__ModuleLoader__.load({
1046
1540
  catalog === undefined ? h('div', { className: 'ls-empty' }, '加载模型目录…') : [
1047
1541
  h('label', { key: 'follow', className: 'ls-set-check' },
1048
1542
  h('input', { type: 'checkbox', checked: followDefault,
1049
- onChange: e => setFollowDefault(e.target.checked) }),
1543
+ onChange: e => {
1544
+ const on = e.target.checked
1545
+ setFollowDefault(on)
1546
+ // 取消跟随默认且尚未选过:落到目录里的第一个模型,避免空选
1547
+ if (!on && !provider && pickerModels.length) {
1548
+ setProvider(pickerModels[0].provider)
1549
+ setModel(pickerModels[0].modelId)
1550
+ }
1551
+ } }),
1050
1552
  '跟随宿主默认模型'),
1051
1553
  followDefault && catalog && catalog.default
1052
1554
  ? h('div', { key: 'def', className: 'ls-set-note' },
1053
1555
  `当前默认:${catalog.default.provider} / ${catalog.default.model}`)
1054
1556
  : null,
1055
- h('label', { key: 'prov', className: 'ls-set-label' }, 'Provider'),
1056
- h('select', {
1057
- key: 'provsel', className: 'ls-select', value: provider,
1058
- disabled: followDefault || catalogDown, onChange: e => onProviderChange(e.target.value),
1059
- }, catalogDown ? null : groups.map(g =>
1060
- h('option', { key: g.id, value: g.id }, g.name || g.id))),
1061
1557
  h('label', { key: 'mdl', className: 'ls-set-label' }, '模型'),
1062
- h('select', {
1063
- key: 'mdlsel', className: 'ls-select', value: model,
1064
- disabled: followDefault || catalogDown || !provider, onChange: e => setModel(e.target.value),
1065
- }, catalogDown ? null : models.map(m =>
1066
- h('option', { key: m.id, value: m.id }, m.name || m.id))),
1558
+ h(ModelPicker, {
1559
+ key: 'picker',
1560
+ models: pickerModels,
1561
+ value: { provider, model },
1562
+ disabled: followDefault || catalogDown,
1563
+ placeholder: catalogDown ? '模型目录不可用' : '选择模型',
1564
+ onChange: sel => { setProvider(sel.provider); setModel(sel.model) },
1565
+ }),
1067
1566
  h('label', { key: 'apply', className: 'ls-set-check' },
1068
1567
  h('input', { type: 'checkbox', checked: applyNow, disabled: !currentTopic,
1069
1568
  onChange: e => setApplyNow(e.target.checked) }),
@@ -1107,15 +1606,21 @@ window.__ModuleLoader__.load({
1107
1606
  body: JSON.stringify({ topic: t, goal: goal.trim() }),
1108
1607
  })
1109
1608
  const j = await r.json()
1110
- if (!j.ok) { setErr(j.error || '创建失败'); return }
1609
+ if (!j.ok) { setErr(j.error || '创建失败'); toast.error('创建失败', j.error || ''); return }
1111
1610
  // 第二步:对所选文件上传(失败有补救路径:课程已建成,详情区可再导入)
1112
1611
  if (files.length) {
1113
1612
  try { await uploadFiles(t, files) }
1114
- catch (e2) { setErr(`课程已创建,但材料上传失败:${e2.message || e2}`) }
1613
+ catch (e2) {
1614
+ const msg = `课程已创建,但材料上传失败:${e2.message || e2}`
1615
+ setErr(msg); toast.warning('材料上传失败', msg)
1616
+ }
1115
1617
  }
1116
1618
  setName(''); setGoal(''); setFiles([])
1117
1619
  onCreated(t)
1118
- } catch (e2) { setErr(String(e2)) }
1620
+ toast.success('课程已创建', files.length ? `${t} · ${files.length} 个材料` : t)
1621
+ } catch (e2) {
1622
+ setErr(String(e2)); toast.error('创建失败', String(e2))
1623
+ }
1119
1624
  finally { setBusy(false) }
1120
1625
  }
1121
1626
  return h('form', { className: 'ls-new', onSubmit: submit, style: { flexDirection: 'column' } },
@@ -1186,9 +1691,15 @@ window.__ModuleLoader__.load({
1186
1691
  setSelectedTopic(topic) // 切到该课程详情
1187
1692
  setChatTopic(topic) // 详情区展开内嵌对话窗(单窗互斥;窗内按 topic.phase 路由)
1188
1693
  setStudyView(topic) // 直接进入专注学习页(左知识右问答,可返回)
1694
+ toast.success(phase === 1 ? '摸底会话已创建' : '学习会话已创建', topic)
1189
1695
  load()
1190
- } else setError(j.error || '创建会话失败')
1191
- } catch (e) { setError(String(e)) }
1696
+ } else {
1697
+ setError(j.error || '创建会话失败')
1698
+ toast.error('创建会话失败', j.error || '')
1699
+ }
1700
+ } catch (e) {
1701
+ setError(String(e)); toast.error('创建会话失败', String(e))
1702
+ }
1192
1703
  finally { setStarting(null) }
1193
1704
  }, [load])
1194
1705
 
@@ -1201,8 +1712,9 @@ window.__ModuleLoader__.load({
1201
1712
  body: JSON.stringify({ topic, enabled }),
1202
1713
  })
1203
1714
  const j = await r.json()
1204
- if (!j.ok) setError(j.error || '设置失败')
1205
- else load()
1715
+ if (!j.ok) { setError(j.error || '设置失败'); toast.error('设置失败', j.error || ''); return }
1716
+ toast.info(enabled ? '已开启联网检索' : '已关闭联网检索', '对下一次新建会话生效')
1717
+ load()
1206
1718
  } catch (e) { setError(String(e)) }
1207
1719
  }, [load])
1208
1720
 
@@ -1218,11 +1730,18 @@ window.__ModuleLoader__.load({
1218
1730
  })
1219
1731
  const j = await r.json()
1220
1732
  if (j.ok) {
1733
+ const name = deleting.name
1221
1734
  setDeleting(null)
1222
1735
  if (selectedTopic === deleting.name) { setSelectedTopic(null); setChatTopic(null) }
1736
+ toast.success('课程已删除', name)
1223
1737
  load()
1224
- } else setError(j.error || '删除失败')
1225
- } catch (e) { setError(String(e)) }
1738
+ } else {
1739
+ setError(j.error || '删除失败')
1740
+ toast.error('删除失败', j.error || '')
1741
+ }
1742
+ } catch (e) {
1743
+ setError(String(e)); toast.error('删除失败', String(e))
1744
+ }
1226
1745
  finally { setDeleting(d => d && { ...d, busy: false }) }
1227
1746
  }, [deleting, selectedTopic, load])
1228
1747
 
@@ -1231,6 +1750,7 @@ window.__ModuleLoader__.load({
1231
1750
  const studyTopic = studyView && data ? data.topics.find(t => t.name === studyView) : null
1232
1751
  if (studyTopic) return h('div', { className: 'ls-panel' },
1233
1752
  h('style', null, css),
1753
+ h(ToastHost),
1234
1754
  error ? h('div', { className: 'ls-empty' }, `出错:${error}`) : null,
1235
1755
  h(StudyFocusView, {
1236
1756
  topic: studyTopic,
@@ -1241,6 +1761,7 @@ window.__ModuleLoader__.load({
1241
1761
  )
1242
1762
  return h('div', { className: 'ls-panel' },
1243
1763
  h('style', null, css),
1764
+ h(ToastHost),
1244
1765
  h('div', { className: 'ls-title-row' },
1245
1766
  h('h1', { className: 'ls-title' }, '学习空间'),
1246
1767
  h('button', {