1855 lines
100 KiB
JavaScript
1855 lines
100 KiB
JavaScript
// Better Sidebar / 右侧栏单项目工作台(.ssv2):仅使用 createElement,严格绑定当前会话所属项目,数据全走 /api/sansheng。
|
||
import { createElement as h, useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
||
import { SEAT_IDS, SEATS } from '../shared/roles.js'
|
||
import {
|
||
buildWorkbenchView,
|
||
clearDraft,
|
||
describeModel,
|
||
describeSeatPreset,
|
||
draftOf,
|
||
findModelOption,
|
||
PRESET_OPTIONS,
|
||
presetLabel,
|
||
presetShortLabel,
|
||
recommendedPresetForSeat,
|
||
UNCHOSEN_MODEL_LABEL,
|
||
updateDraft,
|
||
} from './workbench.js'
|
||
import { mergePendingItems } from './pending-model.js'
|
||
import { groupModelChoices, modelPartsOf, modelObjectFromParts, shortModelName } from './master-model.js'
|
||
import { request } from './transport.js'
|
||
|
||
const SANSHENG_ORDER = ['zhongshu', 'menxia', 'shangshu']
|
||
const LIUBU_ORDER = ['libu', 'hubu', 'lipu', 'bingbu', 'xingbu', 'gongbu']
|
||
|
||
const TASK_META = {
|
||
draft: { label: '待派发', tone: 'muted' },
|
||
dispatched: { label: '已派发', tone: 'primary' },
|
||
running: { label: '进行中', tone: 'primary' },
|
||
prepared: { label: '待复核', tone: 'warning' },
|
||
done: { label: '已完成', tone: 'success' },
|
||
cancelled: { label: '已取消', tone: 'muted' },
|
||
failed: { label: '失败', tone: 'error' },
|
||
waiting_user: { label: '待批准', tone: 'warning' },
|
||
returned: { label: '已退回', tone: 'error' },
|
||
reconfirm: { label: '待重确认', tone: 'error' },
|
||
}
|
||
|
||
const REQ_STATUS_META = {
|
||
discussing: { label: '商讨中', tone: 'primary' },
|
||
ready: { label: '待下派', tone: 'warning' },
|
||
published: { label: '已下派', tone: 'success' },
|
||
returned: { label: '已退回', tone: 'error' },
|
||
cancelled: { label: '已取消', tone: 'muted' },
|
||
}
|
||
|
||
const REQ_JUDGEMENT_LABELS = {
|
||
can_do: '可立项',
|
||
needs_discussion: '需商讨',
|
||
not_now: '暂不可做',
|
||
}
|
||
|
||
const WORKFLOW_STAGES = [
|
||
{ id: 'zhongshu_draft', label: '中书拟案' },
|
||
{ id: 'menxia_review', label: '门下审核' },
|
||
{ id: 'awaiting_execution_approval', label: '待批准' },
|
||
{ id: 'shangshu_dispatch', label: '尚书调度' },
|
||
{ id: 'department_exec', label: '六部执行' },
|
||
{ id: 'menxia_acceptance', label: '门下验收' },
|
||
{ id: 'delivered', label: '已交付' },
|
||
]
|
||
|
||
function smallSvg(paths, size = 14) {
|
||
return h('svg', {
|
||
viewBox: '0 0 24 24',
|
||
width: size,
|
||
height: size,
|
||
fill: 'none',
|
||
stroke: 'currentColor',
|
||
strokeWidth: 1.8,
|
||
strokeLinecap: 'round',
|
||
strokeLinejoin: 'round',
|
||
'aria-hidden': 'true',
|
||
}, paths.map((d, idx) => h('path', { key: idx, d })))
|
||
}
|
||
const RefreshIcon = () => smallSvg(['M21 12a9 9 0 1 1-2.64-6.36', 'M21 3v6h-6'], 13)
|
||
const ChatIcon = () => smallSvg(['M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z'], 13)
|
||
const PlusIcon = () => smallSvg(['M12 5v14', 'M5 12h14'], 13)
|
||
const SearchIcon = () => h('svg', {
|
||
viewBox: '0 0 24 24', width: 14, height: 14, fill: 'none', stroke: 'currentColor',
|
||
strokeWidth: 2, strokeLinecap: 'round', 'aria-hidden': 'true',
|
||
}, h('circle', { cx: 11, cy: 11, r: 8 }), h('path', { d: 'm21 21-4.3-4.3' }))
|
||
const ChevronDown = (open) => h('svg', {
|
||
viewBox: '0 0 24 24', width: 14, height: 14, fill: 'none', stroke: 'currentColor',
|
||
strokeWidth: 2, strokeLinecap: 'round', strokeLinejoin: 'round', 'aria-hidden': 'true',
|
||
style: { transform: open ? 'rotate(180deg)' : 'none', transition: 'transform 150ms ease' },
|
||
}, h('path', { d: 'm6 9 6 6 6-6' }))
|
||
|
||
function pad2(n) { return String(n).padStart(2, '0') }
|
||
function dateText(ts) {
|
||
const n = Number(ts)
|
||
if (!Number.isFinite(n) || n <= 0) return '—'
|
||
const d = new Date(n)
|
||
return (d.getMonth() + 1) + '-' + pad2(d.getDate()) + ' ' + pad2(d.getHours()) + ':' + pad2(d.getMinutes())
|
||
}
|
||
function durationText(ms) {
|
||
const n = Number(ms)
|
||
if (!Number.isFinite(n) || n <= 0) return '—'
|
||
const s = Math.round(n / 1000)
|
||
const m = Math.floor(s / 60) % 60
|
||
const hr = Math.floor(s / 3600)
|
||
if (hr > 0) return hr + 'h ' + m + 'm'
|
||
if (m > 0) return m + 'm ' + pad2(s % 60) + 's'
|
||
return s + 's'
|
||
}
|
||
function taskDurationMs(task) {
|
||
if (!task) return 0
|
||
const st = Number(task.dispatchedAt || task.createdAt || 0)
|
||
const end = task.resultAt ? Number(task.resultAt) : Date.now()
|
||
if (!Number.isFinite(st) || !Number.isFinite(end) || st <= 0 || end <= st) return 0
|
||
return end - st
|
||
}
|
||
function shortText(text, max) {
|
||
const val = String(text || '').replace(/\s+/g, ' ').trim()
|
||
if (!val) return ''
|
||
return val.length > max ? val.slice(0, max - 1) + '…' : val
|
||
}
|
||
function refreshList(value, prev, projectChanged = false) {
|
||
if (Array.isArray(value)) return value
|
||
return projectChanged ? [] : prev
|
||
}
|
||
function seatKind(id) {
|
||
if (id === 'lead') return '总协调'
|
||
if (id === 'zhongshu') return '方案'
|
||
if (id === 'menxia') return '审核'
|
||
if (id === 'shangshu') return '调度'
|
||
return '工作'
|
||
}
|
||
function seatTone(seat) {
|
||
if (!seat) return 'muted'
|
||
if (seat.status === 'missing' || seat.status === 'failed' || seat.modelSyncStatus === 'failed') return 'error'
|
||
if (seat.approvalState === 'waiting') return 'error'
|
||
if (seat.runtimeState === 'running' || seat.status === 'creating') return 'success'
|
||
return 'muted'
|
||
}
|
||
function seatStatusText(seat) {
|
||
if (!seat) return '待命'
|
||
if (seat.status === 'missing') return '会话缺失'
|
||
if (seat.status === 'failed') return '创建失败'
|
||
if (seat.modelSyncStatus === 'failed') return '同步失败'
|
||
if (seat.approvalState === 'waiting') return '等待审批'
|
||
if (seat.runtimeLabel) return seat.runtimeLabel
|
||
if (seat.status === 'bound') return '待命'
|
||
if (seat.status === 'creating') return '开启中'
|
||
return '未开启'
|
||
}
|
||
|
||
export function WorkbenchV2(props) {
|
||
const {
|
||
sessionId,
|
||
resolveWorkspace,
|
||
navigateToSession,
|
||
openRightTab,
|
||
selectionCache,
|
||
getLastSeatId,
|
||
setLastSeatId,
|
||
} = props || {}
|
||
|
||
const [phase, setPhase] = useState('loading')
|
||
const [error, setError] = useState(null)
|
||
const [errorRetryable, setErrorRetryable] = useState(true)
|
||
const [notice, setNotice] = useState(null)
|
||
const [view, setView] = useState(null)
|
||
const [models, setModels] = useState(null)
|
||
const [selectedSeatId, setSelectedSeatId] = useState(() => {
|
||
const saved = typeof getLastSeatId === 'function' ? getLastSeatId() : null
|
||
return SEAT_IDS.includes(saved) ? saved : SEAT_IDS[0]
|
||
})
|
||
const [tab, setTab] = useState('court') // court | flow | memory | config
|
||
const [inspectorTab, setInspectorTab] = useState('overview') // overview | config
|
||
const [seatFilter, setSeatFilter] = useState('all') // all | running | attention | pending
|
||
const [flowSubTab, setFlowSubTab] = useState('tasks') // tasks | requirements | queue | delivery
|
||
const [queueSearch, setQueueSearch] = useState('')
|
||
const [expandedConfigSeatId, setExpandedConfigSeatId] = useState(null)
|
||
|
||
const [draft, setDraft] = useState({})
|
||
const [busy, setBusy] = useState(false)
|
||
const [summaryBusy, setSummaryBusy] = useState(false)
|
||
const [memory, setMemory] = useState(null)
|
||
const [memoryEditing, setMemoryEditing] = useState(false)
|
||
const [memoryDraft, setMemoryDraft] = useState({ goal: '', constraints: '', acceptance: '', decisions: '' })
|
||
const [tasks, setTasks] = useState([])
|
||
const [requirements, setRequirements] = useState([])
|
||
const [pendingApprovals, setPendingApprovals] = useState([])
|
||
const [pendingCards, setPendingCards] = useState([])
|
||
const [approvalStatus, setApprovalStatus] = useState(null)
|
||
|
||
const [artifacts, setArtifacts] = useState([])
|
||
const [artifactDraft, setArtifactDraft] = useState({ title: '', path: '', summary: '' })
|
||
const [artifactModalOpen, setArtifactModalOpen] = useState(false)
|
||
const [durationModalOpen, setDurationModalOpen] = useState(false)
|
||
const [selectedTask, setSelectedTask] = useState(null)
|
||
|
||
const alive = useRef(true)
|
||
const loadedProjectId = useRef(null)
|
||
const taskAnswerVersion = useRef(0)
|
||
|
||
useEffect(() => {
|
||
alive.current = true
|
||
return () => { alive.current = false }
|
||
}, [])
|
||
|
||
const loadProject = useCallback(async () => {
|
||
setPhase('loading')
|
||
setError(null)
|
||
setErrorRetryable(true)
|
||
setNotice(null)
|
||
if (typeof resolveWorkspace !== 'function') { setPhase('no-workspace'); return }
|
||
const workspace = resolveWorkspace()
|
||
if (!workspace) { setPhase('no-workspace'); return }
|
||
try {
|
||
const projectView = await request('open', { workspaceId: workspace.workspaceId, name: workspace.name, path: workspace.path })
|
||
let modelCatalog = null
|
||
try { modelCatalog = await request('models') } catch { /* 模型目录失败时不阻断打开 */ }
|
||
let memoryData = null
|
||
try { memoryData = (await request('memory', { projectId: projectView.project.id })).memory } catch { /* 共识可选 */ }
|
||
const nextProjectId = projectView.project.id
|
||
const answerVersion = taskAnswerVersion.current
|
||
const [taskRes, artifactRes, requirementRes, approvalRes, cardRes] = await Promise.allSettled([
|
||
request('tasks', { projectId: nextProjectId }),
|
||
request('artifacts', { projectId: nextProjectId }),
|
||
request('requirements', { projectId: nextProjectId }),
|
||
request('approvals', { projectId: nextProjectId }),
|
||
request('cards', { projectId: nextProjectId }),
|
||
])
|
||
if (!alive.current) return
|
||
const projectChanged = loadedProjectId.current !== nextProjectId
|
||
loadedProjectId.current = nextProjectId
|
||
setView(projectView)
|
||
setModels(modelCatalog)
|
||
setMemory(memoryData)
|
||
setMemoryDraft({
|
||
goal: memoryData?.goal ?? '',
|
||
constraints: (memoryData?.constraints ?? []).join('\n'),
|
||
acceptance: (memoryData?.acceptance ?? []).join('\n'),
|
||
decisions: '',
|
||
})
|
||
if (projectChanged) {
|
||
setSelectedTask(null)
|
||
setMemoryEditing(false)
|
||
}
|
||
if (projectChanged || taskAnswerVersion.current === answerVersion) {
|
||
setTasks(prev => refreshList(taskRes.value?.tasks, prev, projectChanged))
|
||
}
|
||
setArtifacts(prev => refreshList(artifactRes.value?.artifacts, prev, projectChanged))
|
||
setRequirements(prev => refreshList(requirementRes.value?.requirements, prev, projectChanged))
|
||
setPendingApprovals(prev => refreshList(approvalRes.value?.approvals, prev, projectChanged))
|
||
setPendingCards(prev => refreshList(cardRes.value?.cards, prev, projectChanged))
|
||
setApprovalStatus(approvalRes.status === 'fulfilled' ? approvalRes.value?.status ?? null : { available: false, degraded: true })
|
||
setPhase('ready')
|
||
} catch (loadError) {
|
||
if (!alive.current) return
|
||
setError(loadError?.message || '加载失败')
|
||
setErrorRetryable(!(loadError && loadError.retryable === false))
|
||
setPhase('error')
|
||
}
|
||
}, [resolveWorkspace])
|
||
|
||
useEffect(() => { void loadProject() }, [loadProject])
|
||
|
||
const projectId = view?.project?.id || null
|
||
|
||
useEffect(() => {
|
||
if (!projectId) return undefined
|
||
let disposed = false
|
||
let running = false
|
||
const tick = async () => {
|
||
if (disposed || running) return
|
||
if (typeof document !== 'undefined' && document.visibilityState === 'hidden') return
|
||
running = true
|
||
try {
|
||
const answerVer = taskAnswerVersion.current
|
||
const [projectRes, taskRes, artifactRes, requirementRes, approvalRes, cardRes] = await Promise.allSettled([
|
||
request('project', { projectId }),
|
||
request('tasks', { projectId }),
|
||
request('artifacts', { projectId }),
|
||
request('requirements', { projectId }),
|
||
request('approvals', { projectId }),
|
||
request('cards', { projectId }),
|
||
])
|
||
if (disposed || !alive.current || loadedProjectId.current !== projectId) return
|
||
if (projectRes.value) setView(projectRes.value)
|
||
if (taskAnswerVersion.current === answerVer) setTasks(prev => refreshList(taskRes.value?.tasks, prev))
|
||
setArtifacts(prev => refreshList(artifactRes.value?.artifacts, prev))
|
||
setRequirements(prev => refreshList(requirementRes.value?.requirements, prev))
|
||
setPendingApprovals(prev => refreshList(approvalRes.value?.approvals, prev))
|
||
setPendingCards(prev => refreshList(cardRes.value?.cards, prev))
|
||
setApprovalStatus(approvalRes.status === 'fulfilled' ? approvalRes.value?.status ?? null : { available: false, degraded: true })
|
||
} finally {
|
||
running = false
|
||
}
|
||
}
|
||
const timer = setInterval(() => { void tick() }, 4000)
|
||
const onVis = () => { if (document.visibilityState === 'visible') void tick() }
|
||
if (typeof document !== 'undefined') document.addEventListener('visibilitychange', onVis)
|
||
void tick()
|
||
return () => {
|
||
disposed = true
|
||
clearInterval(timer)
|
||
if (typeof document !== 'undefined') document.removeEventListener('visibilitychange', onVis)
|
||
}
|
||
}, [projectId])
|
||
|
||
useEffect(() => {
|
||
if (!projectId || !selectionCache) return
|
||
const saved = selectionCache.get(projectId)
|
||
if (saved && SEAT_IDS.includes(saved)) setSelectedSeatId(saved)
|
||
}, [projectId, selectionCache])
|
||
|
||
const wb = buildWorkbenchView(view, { selectedSeatId, models, draft })
|
||
const seatById = useMemo(() => {
|
||
const map = {}
|
||
for (const seat of wb.seats) map[seat.id] = seat
|
||
return map
|
||
}, [wb.seats])
|
||
|
||
const seatRecMap = useMemo(() => {
|
||
const raw = view?.project?.seats
|
||
const map = {}
|
||
if (Array.isArray(raw)) {
|
||
for (const s of raw) if (s?.id) map[s.id] = s
|
||
} else if (raw && typeof raw === 'object') {
|
||
for (const [k, s] of Object.entries(raw)) map[k] = { id: k, ...s }
|
||
}
|
||
return map
|
||
}, [view])
|
||
|
||
const activeChatSeatId = useMemo(() => {
|
||
if (!sessionId) return null
|
||
for (const sid of SEAT_IDS) {
|
||
if (seatRecMap[sid]?.sessionId === sessionId) return sid
|
||
}
|
||
return null
|
||
}, [seatRecMap, sessionId])
|
||
|
||
const groupedChoices = useMemo(() => groupModelChoices(wb.selected.modelOptions), [wb.selected.modelOptions])
|
||
|
||
function selectSeat(id) {
|
||
if (!id || id === selectedSeatId) return
|
||
setSelectedSeatId(id)
|
||
if (typeof setLastSeatId === 'function') setLastSeatId(id)
|
||
if (projectId && selectionCache) selectionCache.set(projectId, id)
|
||
}
|
||
|
||
function seatDraftState(seatId) {
|
||
const seatRec = seatRecMap[seatId] || {}
|
||
const dEntry = draftOf(draft, seatId)
|
||
let modelValue = ''
|
||
if (Object.prototype.hasOwnProperty.call(dEntry, 'modelValue')) {
|
||
modelValue = String(dEntry.modelValue || '')
|
||
} else if (Object.prototype.hasOwnProperty.call(dEntry, 'model')) {
|
||
modelValue = describeModel(dEntry.model, wb.selected.modelOptions).modelValue
|
||
} else {
|
||
modelValue = describeModel(seatRec.model ?? null, wb.selected.modelOptions).modelValue
|
||
}
|
||
const parts = modelValue.split('::')
|
||
const modelKey = parts[0] && parts[1] ? (parts[0] + '::' + parts[1]) : ''
|
||
const effort = parts[2] || ''
|
||
const instructions = Object.prototype.hasOwnProperty.call(dEntry, 'instructions')
|
||
? dEntry.instructions
|
||
: (typeof seatRec.instructions === 'string' ? seatRec.instructions : '')
|
||
const presetInfo = describeSeatPreset(seatId, seatRec, dEntry, view?.project)
|
||
return {
|
||
modelKey,
|
||
effort,
|
||
modelValue,
|
||
instructions,
|
||
agentPreset: presetInfo.presetValue,
|
||
hasDraftPreset: Object.prototype.hasOwnProperty.call(dEntry, 'agentPreset'),
|
||
presetInfo,
|
||
}
|
||
}
|
||
|
||
function updateSeatDraftModel(seatId, nextKey, nextEffort) {
|
||
const val = nextKey ? (nextEffort ? nextKey + '::' + nextEffort : nextKey) : ''
|
||
setDraft(prev => updateDraft(prev, seatId, { modelValue: val }))
|
||
}
|
||
|
||
async function saveSeatConfigFor(seatId) {
|
||
if (!projectId) return
|
||
const { modelKey, effort, instructions, agentPreset, hasDraftPreset, presetInfo } = seatDraftState(seatId)
|
||
const model = modelObjectFromParts(modelKey, effort)
|
||
if (!model) {
|
||
setNotice('请先为当前角色选择模型' + (!presetInfo.presetSupported && hasDraftPreset ? '(执行模式持久化待后端启用)' : ''))
|
||
return
|
||
}
|
||
setBusy(true)
|
||
setError(null)
|
||
setNotice('保存中…')
|
||
try {
|
||
const payload = { projectId, seatId, model, instructions }
|
||
if (presetInfo.presetSupported) payload.agentPreset = agentPreset || null
|
||
await request('configure', payload)
|
||
const next = await request('project', { projectId })
|
||
if (!alive.current) return
|
||
setView(next)
|
||
setDraft(prev => clearDraft(prev, seatId))
|
||
const label = SEATS[seatId]?.label || seatId
|
||
if (!presetInfo.presetSupported && hasDraftPreset) {
|
||
setNotice('已保存「' + label + '」模型与说明;执行模式切换暂需后续后端启用后生效')
|
||
} else {
|
||
setNotice('已保存「' + label + '」配置')
|
||
}
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '保存失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function applyRecommendedPresets() {
|
||
if (!projectId) return
|
||
if (!wb.project.presetSupported) {
|
||
setDraft(prev => {
|
||
let next = prev
|
||
for (const id of SEAT_IDS) {
|
||
next = updateDraft(next, id, { agentPreset: recommendedPresetForSeat(id) })
|
||
}
|
||
return next
|
||
})
|
||
setNotice('已在前端草稿按分工预填推荐模式(中枢与三省:标准模式;六部:OPS PTC)。当前后端尚未开启模式写入,待后端改造完成后可保存生效。')
|
||
return
|
||
}
|
||
setBusy(true)
|
||
setError(null)
|
||
setNotice('正在按角色分工应用推荐执行模式…')
|
||
try {
|
||
let skipped = 0
|
||
for (const id of SEAT_IDS) {
|
||
const rec = seatRecMap[id] || {}
|
||
const model = rec.configuredModel ?? rec.model ?? null
|
||
if (!model) { skipped += 1; continue }
|
||
await request('configure', {
|
||
projectId,
|
||
seatId: id,
|
||
model,
|
||
instructions: typeof rec.instructions === 'string' ? rec.instructions : '',
|
||
agentPreset: recommendedPresetForSeat(id),
|
||
})
|
||
}
|
||
const next = await request('project', { projectId })
|
||
if (!alive.current) return
|
||
setView(next)
|
||
setDraft({})
|
||
setNotice(skipped > 0
|
||
? '已为已配模型的席位应用推荐执行模式(另有 ' + skipped + ' 个未选模型席位待配置)'
|
||
: '已为全部十席应用推荐执行模式(中枢/三省=标准模式,六部=OPS PTC)')
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '应用推荐模式失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function setGlobalDefaultFor(seatId) {
|
||
if (!projectId) return
|
||
const { modelKey, effort } = seatDraftState(seatId)
|
||
const configured = seatRecMap[seatId]?.configuredModel ?? seatRecMap[seatId]?.model ?? null
|
||
const model = modelObjectFromParts(modelKey, effort) || configured
|
||
if (!model) { setNotice('请先为当前角色选择模型'); return }
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
const res = await request('setGlobalDefault', { seatId, model })
|
||
const next = await request('project', { projectId })
|
||
if (!alive.current) return
|
||
setView(next)
|
||
setNotice('已将「' + (SEATS[seatId]?.label || seatId) + '」设为全局默认;已同步 ' + ((res.applied || []).length) + ' 个项目')
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '设置全局默认失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function clearOverrideFor(seatId) {
|
||
if (!projectId) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
await request('configure', { projectId, seatId, model: null })
|
||
const next = await request('project', { projectId })
|
||
if (!alive.current) return
|
||
setView(next)
|
||
setDraft(prev => clearDraft(prev, seatId))
|
||
setNotice('「' + (SEATS[seatId]?.label || seatId) + '」已恢复继承全局默认')
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '恢复继承失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function retrySyncFor(seatId) {
|
||
if (!projectId) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
const res = await request('retrySeatModel', { projectId, seatId })
|
||
const next = await request('project', { projectId })
|
||
if (!alive.current) return
|
||
setView(next)
|
||
setNotice('模型同步状态:' + (res.sync?.status ?? 'unknown'))
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '重试同步失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function openSeat(seatId) {
|
||
const seat = seatById[seatId]
|
||
if (!projectId || !seat) return
|
||
if (seat.status === 'missing') { setNotice('「' + seat.name + '」的会话已缺失,点击「重建会话」可恢复'); return }
|
||
if (seat.status !== 'bound') { setNotice('「' + seat.name + '」尚未开启,请先点击开启'); return }
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
const res = await request('openSeat', { projectId, seatId })
|
||
if (!alive.current) return
|
||
if (!res?.sessionId) throw new Error('宿主没有返回会话')
|
||
navigateToSession?.(res.sessionId)
|
||
setNotice('已切换到「' + seat.name + '」原生会话')
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '打开会话失败')
|
||
if (err?.code === 'sansheng/session-missing') {
|
||
try { const next = await request('project', { projectId }); if (alive.current) setView(next) } catch { /* 忽略 */ }
|
||
}
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function enableSeat(seatId) {
|
||
if (!projectId) return
|
||
const seat = seatById[seatId]
|
||
setBusy(true)
|
||
setError(null)
|
||
setNotice('正在开启「' + (seat?.name || seatId) + '」…')
|
||
try {
|
||
const next = await request('enableSeat', { projectId, seatId })
|
||
if (!alive.current) return
|
||
setView(next)
|
||
setNotice('已按需开启「' + (seat?.name || seatId) + '」独立会话')
|
||
try { if (typeof openRightTab === 'function') openRightTab() } catch { /* 忽略 */ }
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '开启失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function rebuildSeat(seatId, force = false) {
|
||
const seat = seatById[seatId]
|
||
if (!projectId || !seat) return
|
||
const rec = seatRecMap[seatId]
|
||
setBusy(true)
|
||
setError(null)
|
||
setNotice('正在重建「' + seat.name + '」会话…')
|
||
try {
|
||
const next = await request('rebuildSeat', {
|
||
projectId,
|
||
seatId,
|
||
expectedSessionId: rec?.sessionId || undefined,
|
||
force,
|
||
})
|
||
if (!alive.current) return
|
||
setView(next)
|
||
setNotice('已重建「' + seat.name + '」会话(旧历史保留)')
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '重建失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function answerApproval(entry, choice) {
|
||
if (!projectId || !entry || busy) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
await request('approvalAnswer', {
|
||
projectId,
|
||
seatId: entry.seatId,
|
||
id: entry.id,
|
||
sessionId: entry.sessionId,
|
||
choice,
|
||
})
|
||
const [data, cardRes] = await Promise.allSettled([
|
||
request('approvals', { projectId }),
|
||
request('cards', { projectId }),
|
||
])
|
||
if (!alive.current || loadedProjectId.current !== projectId) return
|
||
if (data.status === 'fulfilled') {
|
||
setPendingApprovals(prev => refreshList(data.value?.approvals, prev))
|
||
setApprovalStatus(data.value?.status ?? null)
|
||
}
|
||
if (cardRes.status === 'fulfilled') {
|
||
setPendingCards(prev => refreshList(cardRes.value?.cards, prev))
|
||
}
|
||
setNotice(choice === 'allow' ? '已允许审批' : '已拒绝审批')
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '审批应答失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function dismissQuestion(card) {
|
||
if (!projectId || busy || !globalThis.confirm('删除这张问答卡片?它会从「待你处理」移除。')) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
const { card: dismissed } = await request('cardDismiss', { projectId, cardId: card.id })
|
||
if (!alive.current || loadedProjectId.current !== projectId) return
|
||
setPendingCards(prev => prev.map(item => item.id === dismissed.id ? dismissed : item))
|
||
setNotice('已删除问答卡片')
|
||
} catch (error) {
|
||
if (alive.current) setError(error?.message || '删除问答卡片失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function answerCard(card, choice) {
|
||
if (!projectId || !card?.id || busy) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
await request('cardAnswer', { cardId: card.id, choice })
|
||
const [cardRes, apprRes] = await Promise.allSettled([
|
||
request('cards', { projectId }),
|
||
request('approvals', { projectId }),
|
||
])
|
||
if (!alive.current || loadedProjectId.current !== projectId) return
|
||
if (cardRes.status === 'fulfilled') setPendingCards(prev => refreshList(cardRes.value?.cards, prev))
|
||
if (apprRes.status === 'fulfilled') {
|
||
setPendingApprovals(prev => refreshList(apprRes.value?.approvals, prev))
|
||
setApprovalStatus(apprRes.value?.status ?? null)
|
||
}
|
||
setNotice('已提交卡片选择')
|
||
} catch (err) {
|
||
const stale = err?.code === 'sansheng/approval-stale' || /失效|已结束|已取消|stale|expired/i.test(err?.message || '')
|
||
if (alive.current) {
|
||
if (stale) {
|
||
setNotice('该审批卡已失效或被取消,正在刷新最新队列')
|
||
try {
|
||
const [cardRes, apprRes] = await Promise.allSettled([
|
||
request('cards', { projectId }),
|
||
request('approvals', { projectId }),
|
||
])
|
||
if (alive.current && loadedProjectId.current === projectId) {
|
||
if (cardRes.status === 'fulfilled') setPendingCards(prev => refreshList(cardRes.value?.cards, prev))
|
||
if (apprRes.status === 'fulfilled') {
|
||
setPendingApprovals(prev => refreshList(apprRes.value?.approvals, prev))
|
||
setApprovalStatus(apprRes.value?.status ?? null)
|
||
}
|
||
}
|
||
} catch { /* 忽略刷新错误 */ }
|
||
} else {
|
||
setError(err?.message || '卡片提交失败')
|
||
}
|
||
}
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function answerDecision(taskId, decisionId, value) {
|
||
if (!projectId || busy) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
await request('taskDecisionAnswer', { projectId, taskId, decisionId, value })
|
||
if (!alive.current || loadedProjectId.current !== projectId) return
|
||
taskAnswerVersion.current += 1
|
||
setTasks(prev => prev.map(t => t.id === taskId && Array.isArray(t.decisions)
|
||
? { ...t, decisions: t.decisions.map(d => d.id === decisionId ? { ...d, status: 'answered', answer: value } : d) }
|
||
: t))
|
||
setNotice('已提交项目决定')
|
||
} catch (err) {
|
||
if (alive.current && loadedProjectId.current === projectId) setError(err?.message || '项目决定提交失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function redispatchTask(task) {
|
||
if (!projectId || !task?.deliveryId || busy) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
const res = await request('taskRedispatch', {
|
||
projectId,
|
||
taskId: task.id,
|
||
expectedDeliveryId: task.deliveryId,
|
||
})
|
||
const nextTasks = await request('tasks', { projectId })
|
||
if (!alive.current || loadedProjectId.current !== projectId) return
|
||
setTasks(prev => refreshList(nextTasks?.tasks, prev))
|
||
const updated = nextTasks?.tasks?.find(x => x.id === task.id)
|
||
if (updated) setSelectedTask(updated)
|
||
setNotice(res?.delivery?.status === 'sent' ? '已显式重投此任务并送达席位会话' : '重投状态:' + (res?.delivery?.reason || res?.delivery?.status || '已处理'))
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '显式重投失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function summarizeByShangshu() {
|
||
if (!projectId || summaryBusy || busy) return
|
||
setSummaryBusy(true)
|
||
setError(null)
|
||
try {
|
||
const res = await request('shangshuSummary', { projectId })
|
||
if (!alive.current) return
|
||
if (!res?.sessionId) throw new Error('宿主未返回尚书会话')
|
||
setNotice('已请尚书汇总当前项目进度,正在前往尚书会话')
|
||
navigateToSession?.(res.sessionId)
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '尚书汇总请求失败')
|
||
} finally {
|
||
if (alive.current) setSummaryBusy(false)
|
||
}
|
||
}
|
||
|
||
async function reloadTasks() {
|
||
if (!projectId) return
|
||
try {
|
||
const res = await request('tasks', { projectId })
|
||
if (alive.current && loadedProjectId.current === projectId) {
|
||
setTasks(prev => refreshList(res?.tasks, prev))
|
||
setNotice('已同步最新派工队列')
|
||
}
|
||
} catch (err) {
|
||
if (alive.current) setNotice(err?.message || '刷新失败')
|
||
}
|
||
}
|
||
|
||
async function saveMemory() {
|
||
if (!projectId || busy) return
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
const res = await request('memoryUpdate', {
|
||
projectId,
|
||
expectedRevision: memory?.revision ?? 0,
|
||
goal: memoryDraft.goal,
|
||
constraints: memoryDraft.constraints.split('\n').map(x => x.trim()).filter(Boolean),
|
||
acceptance: memoryDraft.acceptance.split('\n').map(x => x.trim()).filter(Boolean),
|
||
decisions: memoryDraft.decisions.split('\n').map(x => x.trim()).filter(Boolean).map(text => ({ type: 'user', status: 'active', text, sourceRefs: [] })),
|
||
sources: [],
|
||
})
|
||
if (!alive.current) return
|
||
setMemory(res.memory)
|
||
setMemoryEditing(false)
|
||
setMemoryDraft(prev => ({ ...prev, decisions: '' }))
|
||
setNotice('项目共识已保存为 v' + res.memory.revision)
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '保存项目共识失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
async function addArtifact() {
|
||
if (!projectId || busy) return
|
||
const title = artifactDraft.title.trim()
|
||
if (!title) { setNotice('成果名称不能为空'); return }
|
||
setBusy(true)
|
||
setError(null)
|
||
try {
|
||
const res = await request('artifactAdd', {
|
||
projectId,
|
||
title,
|
||
path: artifactDraft.path.trim(),
|
||
summary: artifactDraft.summary.trim(),
|
||
})
|
||
if (!alive.current) return
|
||
setArtifacts(list => [...list, res.artifact])
|
||
setArtifactDraft({ title: '', path: '', summary: '' })
|
||
setArtifactModalOpen(false)
|
||
setNotice('成果已登记')
|
||
} catch (err) {
|
||
if (alive.current) setError(err?.message || '登记成果失败')
|
||
} finally {
|
||
if (alive.current) setBusy(false)
|
||
}
|
||
}
|
||
|
||
// ---- 派生计数 ----
|
||
const pendingSummary = useMemo(() => mergePendingItems({
|
||
approvals: pendingApprovals,
|
||
approvalStatus,
|
||
cards: pendingCards,
|
||
tasks,
|
||
}), [pendingApprovals, approvalStatus, pendingCards, tasks])
|
||
const degraded = pendingSummary.degraded
|
||
const toolApprovals = pendingSummary.approvals
|
||
const questionCards = pendingSummary.questions
|
||
const decisions = pendingSummary.decisions
|
||
const blockedTasks = pendingSummary.blockedTasks
|
||
const pendingCount = pendingSummary.pendingCount
|
||
const openTasksCount = tasks.filter(t => ['running', 'prepared', 'dispatched', 'failed', 'waiting_user', 'reconfirm'].includes(t.status)).length
|
||
const reviewCount = tasks.filter(t => t.ownerSeatId === 'menxia' && ['running', 'prepared', 'dispatched'].includes(t.status)).length
|
||
const anomalyCount = tasks.filter(t => t.workflowBlockage || t.status === 'failed' || t.deliveryState === 'unknown').length
|
||
+ wb.seats.filter(s => s.status === 'missing' || s.modelSyncStatus === 'failed').length
|
||
const syncIssues = wb.seats.filter(s => s.modelSyncStatus === 'failed' || s.status === 'missing').length
|
||
const projectDurationMs = tasks.reduce((sum, t) => sum + taskDurationMs(t), 0)
|
||
const runningSeatsCount = wb.seats.filter(s => s.runtimeState === 'running').length
|
||
|
||
function latestTaskOf(seatId) {
|
||
return tasks
|
||
.filter(t => t.ownerSeatId === seatId && t.status !== 'cancelled')
|
||
.sort((a, b) => Number(b.updatedAt || b.createdAt || 0) - Number(a.updatedAt || a.createdAt || 0))[0] || null
|
||
}
|
||
|
||
function renderPendingZone() {
|
||
if (pendingCount === 0 && blockedTasks.length === 0 && !degraded) return null
|
||
return h('section', { className: 'frameless-zone', 'aria-label': '待你处理' },
|
||
h('div', { className: 'frameless-zone-head' },
|
||
h('div', { className: 'frameless-zone-title-wrap' },
|
||
h('span', { className: 'ss-dot is-primary is-pulse' }),
|
||
h('h2', { className: 'frameless-zone-title' }, '待你处理'),
|
||
pendingCount > 0 ? h('span', { className: 'frameless-zone-count' }, String(pendingCount)) : null,
|
||
blockedTasks.length > 0 ? h('span', { className: 'ss-pill is-error' }, blockedTasks.length + ' 阻塞') : null,
|
||
),
|
||
h('span', { className: 'frameless-zone-sub' }, '审批 / 问答卡 / 决定 / 阻塞同步'),
|
||
),
|
||
degraded ? h('div', { className: 'frameless-code', style: { color: 'var(--ss-error)' } },
|
||
'工作台暂时无法获取工具审批队列,请在席位原生会话中使用审批卡。' + (approvalStatus?.reason ? '(' + approvalStatus.reason + ')' : '')) : null,
|
||
h('div', { className: 'frameless-zone-list' },
|
||
toolApprovals.map(a => h('article', { className: 'frameless-item', key: 'apr:' + a.sessionId + ':' + a.id },
|
||
h('div', { className: 'frameless-item-head' },
|
||
h('div', { className: 'frameless-item-meta' },
|
||
h('span', { className: 'frameless-chip is-err' }, h('span', { className: 'ss-dot is-error' }), a.card ? '审批卡片' : '工具审批'),
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700, fontSize: 13 } }, SEATS[a.seatId]?.label || a.seatId),
|
||
a.tool ? h('span', { className: 'font-mono-num', style: { fontSize: 12, color: 'var(--ss-muted)' } }, a.tool) : null,
|
||
),
|
||
h('button', { type: 'button', className: 'frameless-link', disabled: busy, onClick: () => void openSeat(a.seatId) }, '查看会话 →'),
|
||
),
|
||
a.card?.title ? h('p', { style: { margin: 0, fontSize: 12, fontWeight: 600 } }, a.card.title) : null,
|
||
h('div', { className: 'frameless-code' }, a.card?.body || a.reason || a.detail?.text || '等待工具授权'),
|
||
a.card && Array.isArray(a.card.options) && a.card.options.length > 0
|
||
? h('div', { className: 'frameless-btn-group' },
|
||
a.card.options.map((opt, idx) => h('button', {
|
||
key: opt.value,
|
||
type: 'button',
|
||
className: opt.value === 'allow' || idx === 0 ? 'frameless-primary-btn' : 'frameless-btn',
|
||
disabled: busy,
|
||
onClick: () => void answerCard(a.card, opt.value),
|
||
}, opt.label)))
|
||
: h('div', { className: 'frameless-btn-group' },
|
||
h('button', { type: 'button', className: 'frameless-btn', disabled: busy, onClick: () => void answerApproval(a, 'reject') }, '拒绝'),
|
||
h('button', { type: 'button', className: 'frameless-primary-btn', disabled: busy, onClick: () => void answerApproval(a, 'allow') }, '允许一次'),
|
||
),
|
||
)),
|
||
questionCards.map(card => h('article', { className: 'frameless-item', key: 'qcard:' + card.id },
|
||
h('div', { className: 'frameless-item-head' },
|
||
h('div', { className: 'frameless-item-meta' },
|
||
h('span', { className: 'frameless-chip is-pri' }, h('span', { className: 'ss-dot is-primary' }), '问答卡片'),
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700, fontSize: 13 } }, card.seatLabel || SEATS[card.seatId]?.label || '丞相'),
|
||
),
|
||
h('div', { className: 'frameless-btn-group' },
|
||
card.seatId ? h('button', { type: 'button', className: 'frameless-link', disabled: busy, onClick: () => void openSeat(card.seatId) }, '查看会话 →') : null,
|
||
h('button', { type: 'button', className: 'frameless-link', disabled: busy, onClick: () => void dismissQuestion(card) }, '删除'),
|
||
),
|
||
),
|
||
h('p', { style: { margin: 0, fontSize: 12, fontWeight: 600 } }, card.title),
|
||
card.body ? h('div', { className: 'frameless-code' }, card.body) : null,
|
||
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 6 }, role: 'group', 'aria-label': card.title },
|
||
(card.options || []).map(opt => h('button', {
|
||
key: opt.value,
|
||
type: 'button',
|
||
className: 'frameless-btn',
|
||
disabled: busy,
|
||
title: opt.description || '',
|
||
onClick: () => void answerCard(card, opt.value),
|
||
}, opt.label)),
|
||
),
|
||
)),
|
||
decisions.map(({ task, decision }) => h('article', { className: 'frameless-item', key: 'dec:' + task.id + ':' + decision.id },
|
||
h('div', { className: 'frameless-item-head' },
|
||
h('div', { className: 'frameless-item-meta' },
|
||
h('span', { className: 'frameless-chip is-pri' }, h('span', { className: 'ss-dot is-primary' }), '项目决定'),
|
||
h('span', { className: 'truncate', style: { fontSize: 12, fontWeight: 500 } }, task.title),
|
||
),
|
||
h('button', { type: 'button', className: 'frameless-link font-mono-num', onClick: () => setSelectedTask(task) }, task.id),
|
||
),
|
||
h('p', { style: { margin: 0, fontSize: 12, lineHeight: 1.55 } }, decision.question),
|
||
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 6 }, role: 'group', 'aria-label': decision.question },
|
||
(decision.options || []).map(opt => h('button', {
|
||
key: opt.value,
|
||
type: 'button',
|
||
className: 'frameless-btn',
|
||
disabled: busy,
|
||
onClick: () => void answerDecision(task.id, decision.id, opt.value),
|
||
}, opt.label)),
|
||
),
|
||
)),
|
||
blockedTasks.map(task => {
|
||
const seatLabel = SEATS[task.ownerSeatId]?.label || task.ownerSeatId || '席位'
|
||
return h('article', { className: 'frameless-item', key: 'blk:' + task.id },
|
||
h('div', { className: 'frameless-item-head' },
|
||
h('div', { className: 'frameless-item-meta' },
|
||
h('span', { className: 'frameless-chip is-err' }, h('span', { className: 'ss-dot is-error' }), '流程阻塞'),
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700, fontSize: 13 } }, seatLabel),
|
||
h('span', { className: 'truncate', style: { fontSize: 12, fontWeight: 500 } }, task.title),
|
||
),
|
||
h('button', { type: 'button', className: 'frameless-link font-mono-num', onClick: () => setSelectedTask(task) }, '详情 →'),
|
||
),
|
||
h('div', { className: 'frameless-code', style: { color: 'var(--ss-error)' } },
|
||
(task.workflowBlockage?.label ? task.workflowBlockage.label + ' · ' : '') + (task.workflowBlockage?.reason || '流程等待恢复')),
|
||
task.ownerSeatId ? h('div', { className: 'frameless-btn-group' },
|
||
h('button', { type: 'button', className: 'frameless-btn', disabled: busy, onClick: () => void openSeat(task.ownerSeatId) }, '打开' + seatLabel + '会话'),
|
||
) : null,
|
||
)
|
||
}),
|
||
),
|
||
)
|
||
}
|
||
|
||
function renderModelControlsForSeat(seatId, onSaveCallback) {
|
||
const rec = seatRecMap[seatId] || {}
|
||
const { modelKey, effort, instructions, agentPreset, presetInfo } = seatDraftState(seatId)
|
||
const choiceObj = groupedChoices.find(c => c.value === modelKey) || null
|
||
const extraChoices = modelKey && !choiceObj
|
||
? [{ value: modelKey, label: (rec.model?.model || modelKey) + '(目录未列出)', efforts: effort ? [effort] : [] }, ...groupedChoices]
|
||
: groupedChoices
|
||
const efforts = choiceObj?.efforts || []
|
||
const configured = rec.configuredModel ?? rec.model ?? null
|
||
const sourceLabel = wb.seats.find(s => s.id === seatId)?.modelSourceLabel || '未选择'
|
||
const syncStatus = rec.modelSync?.status || null
|
||
const activePresetDesc = PRESET_OPTIONS.find(p => p.value === (agentPreset || presetInfo.recommendedPreset))?.description || ''
|
||
|
||
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } },
|
||
h('div', { className: 'kv-grid-2' },
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '主任模型'),
|
||
h('select', {
|
||
className: 'wb-select',
|
||
value: modelKey,
|
||
onChange: (e) => {
|
||
const nextKey = e.target.value
|
||
const nextChoice = groupedChoices.find(c => c.value === nextKey)
|
||
const nextEffort = nextChoice?.efforts?.includes(effort) ? effort : (nextChoice?.efforts?.[0] || '')
|
||
updateSeatDraftModel(seatId, nextKey, nextEffort)
|
||
},
|
||
},
|
||
h('option', { value: '' }, UNCHOSEN_MODEL_LABEL),
|
||
extraChoices.map(opt => h('option', { key: opt.value, value: opt.value }, opt.label)),
|
||
),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '推理等级'),
|
||
h('select', {
|
||
className: 'wb-select',
|
||
value: effort,
|
||
disabled: efforts.length === 0,
|
||
onChange: (e) => updateSeatDraftModel(seatId, modelKey, e.target.value),
|
||
},
|
||
h('option', { value: '' }, efforts.length === 0 ? '默认(固定)' : '默认'),
|
||
efforts.map(ef => h('option', { key: ef, value: ef }, ef)),
|
||
),
|
||
),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 } },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '执行模式(防 2 分钟审批超时)'),
|
||
h('span', { className: 'ss-pill' }, '推荐 ' + presetInfo.recommendedPresetShortLabel),
|
||
),
|
||
h('select', {
|
||
className: 'wb-select',
|
||
value: agentPreset,
|
||
onChange: (e) => setDraft(prev => updateDraft(prev, seatId, { agentPreset: e.target.value })),
|
||
},
|
||
h('option', { value: '' }, '按角色推荐(推荐:' + presetInfo.recommendedPresetLabel + ')'),
|
||
PRESET_OPTIONS.map(opt => h('option', { key: opt.value, value: opt.value }, opt.label)),
|
||
),
|
||
activePresetDesc ? h('span', { style: { fontSize: 11, color: 'var(--ss-muted)', lineHeight: 1.45 } }, activePresetDesc) : null,
|
||
),
|
||
h('div', { className: 'kv-box', style: { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 } },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '配置来源'),
|
||
h('span', { className: 'ss-pill' + (rec.modelSource === 'project' ? ' is-primary' : '') }, sourceLabel),
|
||
),
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '当前会话模型'),
|
||
h('span', { className: 'font-mono-num' }, rec.sessionModel ? (rec.sessionModel.provider + '/' + rec.sessionModel.model) : (configured ? shortModelName(configured) : '未绑定会话')),
|
||
),
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '执行模式状态'),
|
||
h('span', { style: { color: presetInfo.presetSupported ? 'var(--ss-fg)' : 'var(--ss-muted)' } },
|
||
presetInfo.presetSupported
|
||
? (presetInfo.sessionPresetLabel ? ('会话已绑定:' + presetInfo.sessionPresetLabel) : ('配置:' + presetInfo.presetShortLabel))
|
||
: ('待后端启用按席写入(界面先预览:' + presetInfo.presetShortLabel + ')')),
|
||
),
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '同步状态'),
|
||
h('span', { style: { color: syncStatus === 'failed' ? 'var(--ss-error)' : syncStatus === 'synced' ? 'var(--ss-success)' : 'var(--ss-muted)' } },
|
||
syncStatus === 'synced' ? '已同步' : syncStatus === 'failed' ? ('同步失败' + (rec.modelSync?.error ? ' · ' + rec.modelSync.error : '')) : '待开启或待同步'),
|
||
),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '角色补充说明(仅对本席生效)'),
|
||
h('textarea', {
|
||
rows: 3,
|
||
className: 'wb-textarea',
|
||
value: instructions,
|
||
placeholder: '追加给该席位的项目级补充约束…',
|
||
onChange: (e) => setDraft(prev => updateDraft(prev, seatId, { instructions: e.target.value })),
|
||
}),
|
||
),
|
||
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 8 } },
|
||
h('button', { type: 'button', className: 'wb-btn-primary', disabled: busy, onClick: () => void onSaveCallback(seatId) }, busy ? '保存中…' : '保存配置'),
|
||
configured ? h('button', { type: 'button', className: 'wb-btn-outline', disabled: busy, onClick: () => void setGlobalDefaultFor(seatId) }, '设为全局默认') : null,
|
||
rec.modelSource === 'project' ? h('button', { type: 'button', className: 'wb-btn-outline', disabled: busy, onClick: () => void clearOverrideFor(seatId) }, '恢复继承') : null,
|
||
(syncStatus === 'failed' || syncStatus === 'unresolved') ? h('button', { type: 'button', className: 'wb-btn-outline', disabled: busy, onClick: () => void retrySyncFor(seatId) }, '重试同步') : null,
|
||
),
|
||
)
|
||
}
|
||
|
||
function renderCourtTab() {
|
||
const lead = seatById.lead
|
||
const leadTone = seatTone(lead)
|
||
const leadSelected = selectedSeatId === 'lead'
|
||
const leadLatest = latestTaskOf('lead')
|
||
|
||
const filterMatch = (seat) => {
|
||
if (seatFilter === 'running') return seat.runtimeState === 'running'
|
||
if (seatFilter === 'attention') return seat.status === 'missing' || seat.status === 'failed' || seat.modelSyncStatus === 'failed' || seat.approvalState === 'waiting'
|
||
if (seatFilter === 'pending') return seat.status === 'pending'
|
||
return true
|
||
}
|
||
|
||
const renderSeatCard = (seatId, tier) => {
|
||
const seat = seatById[seatId]
|
||
const tone = seatTone(seat)
|
||
const selected = selectedSeatId === seatId
|
||
const isLive = activeChatSeatId === seatId
|
||
const dimmed = !filterMatch(seat)
|
||
const latest = latestTaskOf(seatId)
|
||
const modelShort = shortModelName(seatRecMap[seatId]?.configuredModel ?? seatRecMap[seatId]?.model ?? null)
|
||
const presetShort = seatDraftState(seatId).presetInfo.presetShortLabel
|
||
return h('button', {
|
||
key: seatId,
|
||
type: 'button',
|
||
'aria-pressed': selected,
|
||
className: 'seat-card' + (tier === 'sansheng' ? ' is-sansheng' : ' is-liubu') + (selected ? ' is-selected' : '') + (dimmed ? ' is-dimmed' : ''),
|
||
onClick: () => selectSeat(seatId),
|
||
},
|
||
h('div', null,
|
||
h('div', { className: 'seat-head' },
|
||
h('span', { className: 'seat-title-wrap' },
|
||
h('span', { className: 'seat-name' }, seat.name),
|
||
isLive ? h('span', { className: 'seat-live-tag' }, '对话中') : null,
|
||
),
|
||
h('span', { className: 'seat-status-text' + (tone === 'error' ? ' is-error' : tone === 'success' ? ' is-success' : '') },
|
||
h('span', { className: 'ss-dot is-' + tone + (tone === 'success' ? ' is-pulse' : '') }),
|
||
seatStatusText(seat),
|
||
),
|
||
),
|
||
h('div', { className: 'seat-duty' }, seat.duty),
|
||
),
|
||
h('div', { className: 'seat-footer' },
|
||
h('span', { className: 'seat-task-title', style: { color: latest ? 'var(--ss-fg)' : 'var(--ss-muted)' } },
|
||
latest ? latest.title : (seat.status === 'bound' ? '空闲待命' : '点击按需开启')),
|
||
h('span', { style: { display: 'inline-flex', alignItems: 'center', gap: 4, flexShrink: 0 } },
|
||
h('span', { className: 'seat-mode-tag', title: '执行模式:' + presetShort }, presetShort),
|
||
h('span', { className: 'seat-model-tag hide-narrow' }, modelShort === '未选模型' ? '—' : modelShort),
|
||
),
|
||
),
|
||
)
|
||
}
|
||
|
||
const sel = wb.selected
|
||
const selSeat = seatById[sel.id]
|
||
const selTone = seatTone(selSeat)
|
||
const selTasks = tasks.filter(t => t.ownerSeatId === sel.id && t.status !== 'cancelled')
|
||
.sort((a, b) => Number(b.updatedAt || b.createdAt || 0) - Number(a.updatedAt || a.createdAt || 0))
|
||
const todayCutoff = new Date().setHours(0, 0, 0, 0)
|
||
const selToday = selTasks.filter(t => Number(t.createdAt) >= todayCutoff)
|
||
const selTodayDone = selToday.filter(t => t.status === 'done')
|
||
const selLatest = selTasks[0] || null
|
||
const actionLabel = sel.status === 'bound' ? '开始对话' : sel.status === 'missing' ? '重建会话' : ('开启「' + sel.name + '」')
|
||
const actionHandler = sel.status === 'bound' ? () => void openSeat(sel.id) : sel.status === 'missing' ? () => void rebuildSeat(sel.id) : () => void enableSeat(sel.id)
|
||
|
||
return [
|
||
h('section', { key: 'telemetry', className: 'telemetry-strip', 'aria-label': '项目运行摘要' },
|
||
h('div', { className: 'telemetry-group' },
|
||
h('span', { className: 'telemetry-item' },
|
||
h('span', { className: 'ss-dot ' + (runningSeatsCount > 0 ? 'is-success is-pulse' : 'is-muted') }),
|
||
h('strong', { className: 'font-mono-num' }, wb.project.boundCount + '/10'),
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '在册'),
|
||
),
|
||
h('button', { type: 'button', onClick: () => { setTab('flow'); setFlowSubTab('tasks') } },
|
||
h('strong', { className: 'font-mono-num', style: { color: reviewCount > 0 ? 'var(--ss-primary)' : 'inherit' } }, String(reviewCount)),
|
||
' ',
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '待复核'),
|
||
),
|
||
h('button', { type: 'button', onClick: () => { setTab('flow'); setFlowSubTab('queue'); setQueueSearch('异常') } },
|
||
h('strong', { className: 'font-mono-num', style: { color: anomalyCount > 0 ? 'var(--ss-error)' : 'inherit' } }, String(anomalyCount)),
|
||
' ',
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '异常'),
|
||
),
|
||
),
|
||
h('button', { type: 'button', className: 'font-mono-num', style: { color: 'var(--ss-muted)' }, onClick: () => setDurationModalOpen(true) },
|
||
projectDurationMs > 0 ? durationText(projectDurationMs) : '—'),
|
||
),
|
||
renderPendingZone(),
|
||
h('div', { key: 'split', className: 'court-split' },
|
||
h('section', { style: { display: 'flex', flexDirection: 'column', gap: 12 }, 'aria-label': '十席谱系' },
|
||
h('div', { className: 'court-head' },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
||
h('h2', { className: 'court-title' }, '十席谱系'),
|
||
h('span', { style: { fontSize: 12, color: 'var(--ss-muted)' } }, '点击席位查看详情'),
|
||
),
|
||
h('div', { className: 'seg-group' },
|
||
[
|
||
{ id: 'all', label: '全部' },
|
||
{ id: 'running', label: '运行中' },
|
||
{ id: 'attention', label: '需关注' },
|
||
{ id: 'pending', label: '未开启' },
|
||
].map(f => h('button', {
|
||
key: f.id,
|
||
type: 'button',
|
||
className: 'seg-btn' + (seatFilter === f.id ? ' is-active' : ''),
|
||
onClick: () => setSeatFilter(f.id),
|
||
}, f.label)),
|
||
),
|
||
),
|
||
h('div', { className: 'lead-card' + (leadSelected ? ' is-selected' : '') },
|
||
h('button', { type: 'button', className: 'lead-select-btn', onClick: () => selectSeat('lead') },
|
||
h('span', { className: 'lead-seal' }, '相'),
|
||
h('div', { style: { minWidth: 0, flex: '1 1 auto' } },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700, fontSize: 15, color: leadSelected ? 'var(--ss-primary)' : 'var(--ss-fg)' } }, '丞相'),
|
||
h('span', { className: 'ss-pill is-' + leadTone },
|
||
h('span', { className: 'ss-dot is-' + leadTone + (leadTone === 'success' ? ' is-pulse' : '') }),
|
||
seatStatusText(lead),
|
||
),
|
||
h('span', { className: 'seat-mode-tag', title: '执行模式:' + seatDraftState('lead').presetInfo.presetShortLabel },
|
||
seatDraftState('lead').presetInfo.presetShortLabel),
|
||
h('span', { className: 'hide-narrow', style: { fontSize: 12, color: 'var(--ss-muted)' } }, '总协调 · 需求入口'),
|
||
),
|
||
h('p', { className: 'truncate', style: { margin: '2px 0 0', fontSize: 12, color: 'var(--ss-muted)' } },
|
||
leadLatest ? (leadLatest.result || leadLatest.title) : SEATS.lead.duty),
|
||
),
|
||
),
|
||
h('button', {
|
||
type: 'button',
|
||
className: 'wb-btn-outline',
|
||
disabled: busy || lead.status === 'creating',
|
||
onClick: () => (lead.status === 'bound' ? void openSeat('lead') : void enableSeat('lead')),
|
||
}, lead.status === 'bound' ? '进入对话' : '开启丞相'),
|
||
),
|
||
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
||
h('div', { className: 'tier-divider' }, h('strong', null, '三省'), h('span', null, '中书拟案 → 门下审核 → 尚书调度'), h('span', { className: 'tier-line' })),
|
||
h('div', { className: 'sansheng-grid' }, SANSHENG_ORDER.map(id => renderSeatCard(id, 'sansheng'))),
|
||
),
|
||
h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
||
h('div', { className: 'tier-divider' }, h('strong', null, '六部'), h('span', null, '尚书统筹 · 同级并行交付'), h('span', { className: 'tier-line' })),
|
||
h('div', { className: 'liubu-grid' }, LIUBU_ORDER.map(id => renderSeatCard(id, 'liubu'))),
|
||
),
|
||
),
|
||
h('aside', { className: 'inspector-card', 'aria-label': '席位检视面板' },
|
||
h('div', { className: 'inspector-head' },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 } },
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700, fontSize: 20, color: 'var(--ss-primary)', lineHeight: 1 } }, sel.name),
|
||
h('span', { className: 'ss-pill is-' + selTone }, seatStatusText(selSeat)),
|
||
h('span', { style: { fontSize: 12, color: 'var(--ss-muted)' } }, seatKind(sel.id)),
|
||
),
|
||
h('button', {
|
||
type: 'button',
|
||
className: 'wb-btn-primary',
|
||
disabled: busy || sel.status === 'creating',
|
||
onClick: actionHandler,
|
||
}, ChatIcon(), h('span', null, actionLabel)),
|
||
),
|
||
h('div', { className: 'inspector-subtabs' },
|
||
h('button', { type: 'button', className: 'inspector-subtab' + (inspectorTab === 'overview' ? ' is-active' : ''), onClick: () => setInspectorTab('overview') }, '概览与任务'),
|
||
h('button', { type: 'button', className: 'inspector-subtab' + (inspectorTab === 'config' ? ' is-active' : ''), onClick: () => setInspectorTab('config') },
|
||
'模型与指令' + (sel.modelSyncStatus === 'failed' ? ' · 异常' : '')),
|
||
),
|
||
h('div', { className: 'inspector-body' },
|
||
inspectorTab === 'config'
|
||
? renderModelControlsForSeat(sel.id, saveSeatConfigFor)
|
||
: [
|
||
h('div', { key: 'kv', className: 'kv-grid-2' },
|
||
h('div', { className: 'kv-box' },
|
||
h('div', { style: { color: 'var(--ss-muted)' } }, '主任模型'),
|
||
h('div', { className: 'font-mono-num truncate', style: { fontWeight: 500, marginTop: 2 } }, sel.modelLabel),
|
||
h('div', { style: { color: 'var(--ss-muted)', marginTop: 2 } }, sel.modelSourceLabel),
|
||
),
|
||
h('div', { className: 'kv-box' },
|
||
h('div', { style: { color: 'var(--ss-muted)' } }, '会话绑定'),
|
||
h('div', { className: 'font-mono-num', style: { fontWeight: 500, marginTop: 2, color: sel.status === 'missing' ? 'var(--ss-error)' : 'var(--ss-fg)' } },
|
||
sel.status === 'missing' ? '会话已缺失' : (sel.sessionId ? sel.sessionId.slice(0, 10) : '尚未建立')),
|
||
h('div', { style: { color: 'var(--ss-muted)', marginTop: 2 } }, '本日 ' + selToday.length + ' 条 · 完 ' + selTodayDone.length),
|
||
),
|
||
),
|
||
sel.status === 'missing' ? h('div', { key: 'miss', className: 'wb-alert' },
|
||
h('span', null, '原会话在宿主中已不存在,重建后保留旧任务历史。'),
|
||
h('button', { type: 'button', className: 'wb-btn-outline', disabled: busy, onClick: () => void rebuildSeat(sel.id) }, '重建会话'),
|
||
) : null,
|
||
sel.status === 'bound' && sel.presetMismatch ? h('div', { key: 'preset', className: 'wb-alert' },
|
||
h('span', null, '当前会话的执行模式与配置不同,重建后保留旧会话历史。'),
|
||
h('button', { type: 'button', className: 'wb-btn-outline', disabled: busy, onClick: () => void rebuildSeat(sel.id, true) }, '重建并切换模式'),
|
||
) : null,
|
||
sel.modelSyncStatus === 'failed' ? h('div', { key: 'fail', className: 'wb-alert' },
|
||
h('span', null, '模型同步失败:' + (sel.modelSync?.error || '未知原因')),
|
||
h('button', { type: 'button', className: 'wb-btn-outline', disabled: busy, onClick: () => void retrySyncFor(sel.id) }, '重试同步'),
|
||
) : null,
|
||
h('div', { key: 'resp', style: { borderRadius: 8, border: '1px solid var(--ss-border)', padding: 12, display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('div', { style: { fontWeight: 500, color: 'var(--ss-muted)' } }, '最近动态与职责'),
|
||
h('p', { style: { margin: 0, lineHeight: 1.55 } }, (selLatest && (selLatest.result || selLatest.note)) || sel.responsibility),
|
||
selLatest ? h('p', { style: { margin: '4px 0 0', paddingTop: 6, borderTop: '1px dashed var(--ss-border)', color: 'var(--ss-muted)' } }, '职责:' + sel.responsibility) : null,
|
||
),
|
||
sel.id === 'shangshu' ? h('button', {
|
||
key: 'ss',
|
||
type: 'button',
|
||
className: 'frameless-btn',
|
||
style: { width: '100%', padding: '8px 12px', borderRadius: 8 },
|
||
disabled: summaryBusy || busy,
|
||
onClick: () => void summarizeByShangshu(),
|
||
}, summaryBusy ? '正在通知尚书汇总…' : '请尚书汇总当前项目任务进度 →') : null,
|
||
sel.id === 'lead' ? h('button', {
|
||
key: 'reqjump',
|
||
type: 'button',
|
||
className: 'frameless-btn',
|
||
style: { width: '100%', padding: '8px 12px', borderRadius: 8 },
|
||
onClick: () => { setTab('flow'); setFlowSubTab('requirements') },
|
||
}, '前往「流转 · 需求清单」查看 ' + requirements.length + ' 条需求 →') : null,
|
||
h('div', { key: 'recent', style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
|
||
h('span', { style: { fontWeight: 500, color: 'var(--ss-muted)' } }, '本席近期任务 (' + selTasks.length + ')'),
|
||
selTasks.length > 0 ? h('button', { type: 'button', className: 'frameless-link', onClick: () => { setTab('flow'); setFlowSubTab('queue') } }, '查看全部') : null,
|
||
),
|
||
selTasks.length === 0
|
||
? h('div', { className: 'wb-empty-box' }, '该席位暂无任务记录。')
|
||
: selTasks.slice(0, 3).map(t => {
|
||
const tm = TASK_META[t.status] || { label: t.status, tone: 'muted' }
|
||
return h('button', {
|
||
key: t.id,
|
||
type: 'button',
|
||
className: 'wb-card',
|
||
style: { textAlign: 'left', padding: 10 },
|
||
onClick: () => setSelectedTask(t),
|
||
},
|
||
h('div', { style: { display: 'flex', alignItems: 'center', justifyContent: 'space-between', gap: 8 } },
|
||
h('span', { className: 'truncate', style: { fontWeight: 500 } }, t.title),
|
||
h('span', { className: 'ss-pill is-' + tm.tone }, tm.label),
|
||
),
|
||
h('p', { className: 'line-clamp-2', style: { margin: 0, color: 'var(--ss-muted)' } },
|
||
t.workflowBlockage ? t.workflowBlockage.reason : (t.result || t.goal || t.requirement || '(暂无说明)')),
|
||
)
|
||
}),
|
||
),
|
||
],
|
||
),
|
||
),
|
||
),
|
||
]
|
||
}
|
||
|
||
function renderStageStepper(stage) {
|
||
const idx = WORKFLOW_STAGES.findIndex(s => s.id === stage)
|
||
return h('div', { className: 'stage-stepper' },
|
||
WORKFLOW_STAGES.map((st, i) => {
|
||
const done = idx >= 0 && i < idx
|
||
const cur = idx >= 0 && i === idx
|
||
return h('span', { key: st.id, style: { display: 'inline-flex', alignItems: 'center', gap: 4, flexShrink: 0 } },
|
||
h('span', { className: 'stage-step-pill' + (done ? ' is-done' : cur ? ' is-cur' : '') }, st.label),
|
||
i < WORKFLOW_STAGES.length - 1 ? h('span', { style: { color: 'var(--ss-muted)', fontSize: 12 } }, '→') : null,
|
||
)
|
||
}),
|
||
stage === 'reconfirm' ? h('span', { className: 'ss-pill is-error' }, '阻塞 · 待重确认') : null,
|
||
)
|
||
}
|
||
|
||
function renderFlowTab() {
|
||
const wfTasks = tasks.filter(t => t.kind === 'workflow' || t.kind === 'execution')
|
||
const deliveries = tasks.filter(t => t.stage === 'delivered' || t.status === 'done')
|
||
const q = queueSearch.trim().toLowerCase()
|
||
const filteredQueue = tasks.filter(t => {
|
||
if (!q) return true
|
||
const sName = SEATS[t.ownerSeatId]?.label || ''
|
||
const tmLabel = TASK_META[t.status]?.label || ''
|
||
const isAnomaly = Boolean(t.workflowBlockage || t.status === 'failed' || t.deliveryState === 'unknown')
|
||
return [
|
||
t.id, t.title, sName, tmLabel, t.goal, t.result,
|
||
t.workflowBlockage?.label, t.workflowBlockage?.reason,
|
||
t.workflowBlockage ? '阻塞' : '',
|
||
isAnomaly ? '异常' : '',
|
||
].filter(Boolean).join(' ').toLowerCase().includes(q)
|
||
})
|
||
const subTabs = [
|
||
{ id: 'tasks', label: '流转任务', count: wfTasks.length },
|
||
{ id: 'requirements', label: '需求清单', count: requirements.length },
|
||
{ id: 'queue', label: '派工队列', count: tasks.length },
|
||
{ id: 'delivery', label: '交付结果', count: deliveries.length },
|
||
]
|
||
let body = null
|
||
if (flowSubTab === 'requirements') {
|
||
body = requirements.length === 0
|
||
? h('div', { className: 'wb-empty-box' }, '暂无需求条目。与丞相在对话中明确需求后将整理至此。')
|
||
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } }, requirements.map(req => {
|
||
const rm = REQ_STATUS_META[req.status] || { label: req.status, tone: 'muted' }
|
||
return h('article', { className: 'wb-card', key: req.id },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 8 } },
|
||
h('div', { style: { minWidth: 0 } },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
||
h('span', { className: 'font-mono-num', style: { fontWeight: 600, color: 'var(--ss-primary)' } }, req.id + ' · v' + req.revision),
|
||
h('span', { className: 'ss-pill is-' + rm.tone }, rm.label),
|
||
req.judgement ? h('span', { style: { color: 'var(--ss-muted)' } }, '丞相:' + (REQ_JUDGEMENT_LABELS[req.judgement] || req.judgement)) : null,
|
||
),
|
||
h('h3', { style: { margin: '4px 0 0', fontSize: 13, fontWeight: 600 } }, req.title),
|
||
),
|
||
h('button', {
|
||
type: 'button',
|
||
className: 'wb-btn-outline',
|
||
onClick: () => {
|
||
try { void navigator.clipboard?.writeText?.(req.id) } catch { /* 忽略 */ }
|
||
setNotice('已复制需求编号:' + req.id)
|
||
},
|
||
}, '复制编号'),
|
||
),
|
||
req.summary ? h('p', { style: { margin: 0, lineHeight: 1.55 } }, req.summary) : null,
|
||
req.blockedReason ? h('div', { className: 'wb-alert' }, '阻塞:' + req.blockedReason) : null,
|
||
h('details', { style: { borderRadius: 8, background: 'var(--ss-subtle)', border: '1px solid var(--ss-border)', padding: '6px 10px' } },
|
||
h('summary', { style: { cursor: 'pointer', color: 'var(--ss-muted)', fontWeight: 500 } }, '展开范围、验收标准与待补信息'),
|
||
h('dl', { style: { margin: '8px 0 0', paddingTop: 8, borderTop: '1px solid var(--ss-border)', display: 'grid', gap: 6 } },
|
||
h('div', null, h('dt', { style: { color: 'var(--ss-muted)' } }, '用户原话'), h('dd', { style: { margin: '2px 0 0' } }, req.originalText || '—')),
|
||
h('div', null, h('dt', { style: { color: 'var(--ss-muted)' } }, '范围'), h('dd', { style: { margin: '2px 0 0' } }, req.scope || '—')),
|
||
h('div', null, h('dt', { style: { color: 'var(--ss-muted)' } }, '非目标'), h('dd', { style: { margin: '2px 0 0' } }, req.nonGoals || '—')),
|
||
h('div', null, h('dt', { style: { color: 'var(--ss-muted)' } }, '验收标准'), h('dd', { style: { margin: '2px 0 0' } }, req.acceptanceCriteria || '—')),
|
||
req.risks ? h('div', null, h('dt', { style: { color: 'var(--ss-muted)' } }, '风险'), h('dd', { style: { margin: '2px 0 0' } }, req.risks)) : null,
|
||
req.missingInfo ? h('div', null, h('dt', { style: { color: 'var(--ss-muted)' } }, '待补信息'), h('dd', { style: { margin: '2px 0 0' } }, req.missingInfo)) : null,
|
||
),
|
||
),
|
||
)
|
||
}))
|
||
} else if (flowSubTab === 'queue') {
|
||
body = h('div', { className: 'wb-card', style: { padding: 0, overflow: 'hidden', gap: 0 } },
|
||
h('div', { style: { padding: 10, borderBottom: '1px solid var(--ss-border)', display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center' } },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, flex: '1 1 150px', border: '1px solid var(--ss-border)', borderRadius: 8, background: 'var(--ss-bg)', padding: '5px 10px' } },
|
||
SearchIcon(),
|
||
h('input', {
|
||
type: 'search',
|
||
value: queueSearch,
|
||
placeholder: '按任务、席位、状态筛选…',
|
||
style: { width: '100%', border: 0, background: 'transparent', outline: 'none', fontSize: 12 },
|
||
onChange: (e) => setQueueSearch(e.target.value),
|
||
}),
|
||
),
|
||
h('button', { type: 'button', className: 'frameless-btn', disabled: summaryBusy || busy, onClick: () => void summarizeByShangshu() }, summaryBusy ? '汇总中…' : '尚书汇总'),
|
||
h('button', { type: 'button', className: 'wb-btn-outline', disabled: busy, onClick: () => void reloadTasks() }, '刷新'),
|
||
),
|
||
filteredQueue.length === 0
|
||
? h('div', { style: { padding: 28, textAlign: 'center', color: 'var(--ss-muted)' } }, '没有匹配的派工记录。')
|
||
: h('div', { style: { overflowX: 'auto' } },
|
||
h('table', { className: 'queue-table' },
|
||
h('thead', null, h('tr', null,
|
||
h('th', null, '任务'),
|
||
h('th', null, '席位'),
|
||
h('th', null, '状态'),
|
||
h('th', { className: 'col-dur' }, '耗时'),
|
||
h('th', { className: 'col-time' }, '派发时间'),
|
||
)),
|
||
h('tbody', null, filteredQueue.map(t => {
|
||
const tm = TASK_META[t.status] || { label: t.status, tone: 'muted' }
|
||
return h('tr', { key: t.id, className: 'is-click', onClick: () => setSelectedTask(t) },
|
||
h('td', null, h('div', { style: { fontWeight: 500 } }, t.title), h('div', { className: 'font-mono-num', style: { color: 'var(--ss-muted)' } }, t.id)),
|
||
h('td', { className: 'font-seal', style: { fontWeight: 700, whiteSpace: 'nowrap' } }, SEATS[t.ownerSeatId]?.label || '—'),
|
||
h('td', null,
|
||
h('span', { className: 'ss-pill is-' + tm.tone }, tm.label),
|
||
t.workflowBlockage ? h('span', { className: 'ss-pill is-error', style: { marginLeft: 4 }, title: t.workflowBlockage.reason || '' }, '阻塞') : null,
|
||
),
|
||
h('td', { className: 'col-dur font-mono-num', style: { color: 'var(--ss-muted)', whiteSpace: 'nowrap' } }, durationText(taskDurationMs(t))),
|
||
h('td', { className: 'col-time font-mono-num', style: { color: 'var(--ss-muted)', whiteSpace: 'nowrap' } }, dateText(t.dispatchedAt)),
|
||
)
|
||
})),
|
||
),
|
||
),
|
||
)
|
||
} else if (flowSubTab === 'delivery') {
|
||
body = deliveries.length === 0
|
||
? h('div', { className: 'wb-empty-box' }, '还没有已交付结果。')
|
||
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } }, deliveries.map(t => {
|
||
const children = tasks.filter(c => c.parentTaskId === t.id && c.kind === 'execution')
|
||
return h('article', { className: 'wb-card', key: t.id },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', gap: 8 } },
|
||
h('h3', { style: { margin: 0, fontSize: 13, fontWeight: 600 } }, t.title),
|
||
h('span', { className: 'ss-pill is-success' }, '已交付'),
|
||
),
|
||
h('div', { className: 'font-mono-num', style: { display: 'flex', flexWrap: 'wrap', gap: 8, color: 'var(--ss-muted)' } },
|
||
h('span', null, t.id),
|
||
h('span', null, '承办:' + (SEATS[t.ownerSeatId]?.label || '—')),
|
||
t.resultSessionId ? h('span', null, '会话 ' + t.resultSessionId.slice(0, 8)) : null,
|
||
h('span', null, '耗时 ' + durationText(taskDurationMs(t))),
|
||
),
|
||
h('p', { style: { margin: 0, lineHeight: 1.55, whiteSpace: 'pre-wrap' } }, t.deliveryNote || t.result || t.summary || '(暂无交付说明)'),
|
||
children.length ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6, paddingTop: 8, borderTop: '1px dashed var(--ss-border)' } },
|
||
children.map(ch => h('div', { key: ch.id, style: { display: 'flex', flexWrap: 'wrap', gap: 8, alignItems: 'center' } },
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700 } }, SEATS[ch.ownerSeatId]?.label || ch.ownerSeatId),
|
||
h('span', { className: 'ss-pill is-' + (TASK_META[ch.status]?.tone || 'muted') }, TASK_META[ch.status]?.label || ch.status),
|
||
h('span', { style: { flex: '1 1 120px', color: 'var(--ss-muted)' } }, shortText(ch.result || ch.note || '(暂无结果)', 80)),
|
||
ch.resultSessionId ? h('span', { className: 'font-mono-num', style: { color: 'var(--ss-muted)' } }, ch.resultSessionId.slice(0, 8)) : null,
|
||
)),
|
||
) : null,
|
||
)
|
||
}))
|
||
} else {
|
||
body = wfTasks.length === 0
|
||
? h('div', { className: 'wb-empty-box' }, '还没有流转任务。丞相下派需求后会出现在这里。')
|
||
: h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10 } }, wfTasks.map(t => {
|
||
const tm = TASK_META[t.status] || { label: t.status, tone: 'muted' }
|
||
return h('article', {
|
||
key: t.id,
|
||
className: 'wb-card',
|
||
style: t.workflowBlockage ? { borderColor: 'color-mix(in srgb,var(--ss-error) 36%,var(--ss-border))' } : undefined,
|
||
},
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'flex-start', gap: 8 } },
|
||
h('div', { style: { minWidth: 0 } },
|
||
h('div', { style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', gap: 6 } },
|
||
h('span', { className: 'font-mono-num', style: { color: 'var(--ss-muted)' } }, t.id),
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700 } }, SEATS[t.ownerSeatId]?.label || t.ownerSeatId),
|
||
t.requirementId ? h('span', { className: 'ss-pill font-mono-num' }, t.requirementId + ' v' + t.requirementRevision) : null,
|
||
h('span', { className: 'ss-pill is-' + tm.tone }, tm.label),
|
||
),
|
||
h('h3', { style: { margin: '4px 0 0', fontSize: 13, fontWeight: 600 } }, t.title),
|
||
),
|
||
h('button', { type: 'button', className: 'wb-btn-outline', onClick: () => setSelectedTask(t) }, '查看详情 →'),
|
||
),
|
||
t.kind === 'workflow' ? renderStageStepper(t.stage) : null,
|
||
t.workflowBlockage
|
||
? h('div', { className: 'wb-alert' },
|
||
h('span', null, t.workflowBlockage.label + ':' + t.workflowBlockage.reason),
|
||
h('button', { type: 'button', className: 'wb-btn-outline', onClick: () => setSelectedTask(t) }, '处理阻塞'),
|
||
)
|
||
: h('p', { style: { margin: 0, color: 'var(--ss-muted)', lineHeight: 1.55 } }, t.result || t.goal || t.requirement || '(暂无说明)'),
|
||
)
|
||
}))
|
||
}
|
||
|
||
return [
|
||
h('div', { key: 'subtabs', className: 'flow-seg' },
|
||
subTabs.map(st => h('button', {
|
||
key: st.id,
|
||
type: 'button',
|
||
className: 'flow-seg-btn' + (flowSubTab === st.id ? ' is-active' : ''),
|
||
onClick: () => setFlowSubTab(st.id),
|
||
}, st.label + ' ' + st.count)),
|
||
),
|
||
h('div', { key: 'flowbody' }, body),
|
||
]
|
||
}
|
||
|
||
function renderMemoryTab() {
|
||
const rev = memory?.revision ?? 0
|
||
const constraints = Array.isArray(memory?.constraints) ? memory.constraints : []
|
||
const acceptance = Array.isArray(memory?.acceptance) ? memory.acceptance : []
|
||
const decisionsList = Array.isArray(memory?.decisions) ? memory.decisions : []
|
||
|
||
if (memoryEditing) {
|
||
return h('section', { className: 'wb-card' },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
|
||
h('h2', { style: { margin: 0, fontSize: 14, fontWeight: 600 } }, '编辑项目共识 · 当前 v' + rev),
|
||
h('button', { type: 'button', className: 'wb-toast-close', onClick: () => setMemoryEditing(false) }, '取消'),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '项目目标'),
|
||
h('textarea', { rows: 2, className: 'wb-textarea', value: memoryDraft.goal, onChange: (e) => setMemoryDraft(m => ({ ...m, goal: e.target.value })) }),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '硬约束(每行一条)'),
|
||
h('textarea', { rows: 4, className: 'wb-textarea', value: memoryDraft.constraints, onChange: (e) => setMemoryDraft(m => ({ ...m, constraints: e.target.value })) }),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '验收标准(每行一条)'),
|
||
h('textarea', { rows: 3, className: 'wb-textarea', value: memoryDraft.acceptance, onChange: (e) => setMemoryDraft(m => ({ ...m, acceptance: e.target.value })) }),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '追加新决定(每行一条)'),
|
||
h('textarea', { rows: 2, className: 'wb-textarea', value: memoryDraft.decisions, placeholder: '可选:记录新增项目级决定', onChange: (e) => setMemoryDraft(m => ({ ...m, decisions: e.target.value })) }),
|
||
),
|
||
h('div', { style: { display: 'flex', justifyContent: 'flex-end', gap: 8 } },
|
||
h('button', { type: 'button', className: 'wb-btn-outline', onClick: () => setMemoryEditing(false) }, '取消'),
|
||
h('button', { type: 'button', className: 'wb-btn-primary', disabled: busy, onClick: () => void saveMemory() }, busy ? '保存中…' : ('保存为 v' + (rev + 1))),
|
||
),
|
||
)
|
||
}
|
||
|
||
return [
|
||
h('section', { key: 'mhero', className: 'wb-card', style: { borderLeft: '3px solid var(--ss-primary)' } },
|
||
h('div', { style: { display: 'flex', flexWrap: 'wrap', justifyContent: 'space-between', alignItems: 'center', gap: 8 } },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8 } },
|
||
h('h2', { style: { margin: 0, fontSize: 14, fontWeight: 600 } }, '项目共识'),
|
||
h('span', { className: 'ss-pill font-mono-num is-primary' }, 'v' + rev),
|
||
),
|
||
h('button', { type: 'button', className: 'wb-btn-outline', onClick: () => setMemoryEditing(true) }, '编辑共识'),
|
||
),
|
||
h('p', { style: { margin: 0, lineHeight: 1.6 } }, memory?.goal || '尚未填写项目目标。保存后将自动注入各部门提示词与派工上下文。'),
|
||
),
|
||
h('div', { key: 'mgrid1', className: 'consensus-grid' },
|
||
h('section', { className: 'wb-card' },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
|
||
h('h3', { style: { margin: 0, fontSize: 12, fontWeight: 600 } }, '硬约束'),
|
||
h('span', { className: 'font-mono-num', style: { color: 'var(--ss-muted)' } }, constraints.length + ' 条'),
|
||
),
|
||
constraints.length === 0
|
||
? h('p', { style: { margin: 0, color: 'var(--ss-muted)' } }, '暂无硬约束。')
|
||
: h('ul', { style: { margin: 0, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 6 } },
|
||
constraints.map((c, idx) => h('li', { key: idx, style: { display: 'flex', gap: 8 } },
|
||
h('span', { className: 'font-mono-num', style: { color: 'var(--ss-primary)', flexShrink: 0 } }, (idx + 1) + '.'),
|
||
h('span', { style: { lineHeight: 1.5 } }, c),
|
||
)),
|
||
),
|
||
),
|
||
h('section', { className: 'wb-card' },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
|
||
h('h3', { style: { margin: 0, fontSize: 12, fontWeight: 600 } }, '验收标准'),
|
||
h('span', { className: 'font-mono-num', style: { color: 'var(--ss-muted)' } }, acceptance.length + ' 条'),
|
||
),
|
||
acceptance.length === 0
|
||
? h('p', { style: { margin: 0, color: 'var(--ss-muted)' } }, '暂无验收标准。')
|
||
: h('ul', { style: { margin: 0, padding: 0, listStyle: 'none', display: 'flex', flexDirection: 'column', gap: 6 } },
|
||
acceptance.map((a, idx) => h('li', { key: idx, style: { display: 'flex', gap: 8 } },
|
||
h('span', { style: { color: 'var(--ss-success)', flexShrink: 0 } }, '✓'),
|
||
h('span', { style: { lineHeight: 1.5 } }, a),
|
||
)),
|
||
),
|
||
),
|
||
),
|
||
h('div', { key: 'mgrid2', className: 'consensus-grid' },
|
||
h('section', { className: 'wb-card' },
|
||
h('h3', { style: { margin: 0, fontSize: 12, fontWeight: 600 } }, '现行决定 (' + decisionsList.length + ')'),
|
||
decisionsList.length === 0
|
||
? h('p', { style: { margin: 0, color: 'var(--ss-muted)' } }, '暂无记录。')
|
||
: decisionsList.slice(-6).map((dec, idx) => h('div', { key: idx, className: 'kv-box' },
|
||
h('div', null, dec.text),
|
||
h('div', { className: 'font-mono-num', style: { color: 'var(--ss-muted)', marginTop: 4 } },
|
||
(dec.recordedAt ? dateText(dec.recordedAt) : '项目记录') + ' · ' + (dec.status === 'active' ? '现行' : '已归档')),
|
||
)),
|
||
),
|
||
h('section', { className: 'wb-card' },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', alignItems: 'center' } },
|
||
h('h3', { style: { margin: 0, fontSize: 12, fontWeight: 600 } }, '成果登记 (' + artifacts.length + ')'),
|
||
h('button', { type: 'button', className: 'frameless-btn', onClick: () => setArtifactModalOpen(true) }, PlusIcon(), ' 登记成果'),
|
||
),
|
||
artifacts.length === 0
|
||
? h('p', { style: { margin: 0, color: 'var(--ss-muted)' } }, '还没有登记成果。')
|
||
: artifacts.map(a => h('div', { key: a.id, className: 'kv-box' },
|
||
h('div', { style: { fontWeight: 500 } }, a.title),
|
||
a.path ? h('div', { className: 'font-mono-num', style: { color: 'var(--ss-primary)', wordBreak: 'break-all', marginTop: 2 } }, a.path) : null,
|
||
a.summary ? h('div', { style: { color: 'var(--ss-muted)', marginTop: 2 } }, a.summary) : null,
|
||
)),
|
||
),
|
||
),
|
||
]
|
||
}
|
||
|
||
function renderConfigTab() {
|
||
return [
|
||
h('section', { key: 'binding', className: 'wb-card' },
|
||
h('div', { style: { display: 'flex', flexWrap: 'wrap', justifyContent: 'space-between', alignItems: 'center', gap: 8 } },
|
||
h('div', { style: { minWidth: 0 } },
|
||
h('h2', { style: { margin: 0, fontSize: 14, fontWeight: 600 } }, '项目绑定与全局默认(R-001)'),
|
||
h('p', { className: 'font-mono-num truncate', style: { margin: '2px 0 0', color: 'var(--ss-muted)' } },
|
||
(wb.project.path || wb.project.name || '—') + ' · ' + (wb.project.workspaceId || '—')),
|
||
),
|
||
h('span', { className: 'ss-pill is-success' }, '项目隔离已生效'),
|
||
),
|
||
h('div', { className: 'kv-box', style: { display: 'flex', flexWrap: 'wrap', alignItems: 'center', justifyContent: 'space-between', gap: 8 } },
|
||
h('div', { style: { flex: '1 1 220px', fontSize: 12, lineHeight: 1.5, color: 'var(--ss-muted)' } },
|
||
h('strong', { style: { color: 'var(--ss-fg)' } }, '执行模式分工建议:'),
|
||
'中枢(丞相)与三省(中书 / 门下 / 尚书)使用「标准模式」,避免 2 分钟审批超时与卡片嵌套;六部使用「OPS PTC」批量读写。',
|
||
!wb.project.presetSupported ? '(后端写入启用前,先展示推荐与前端草稿)' : ''),
|
||
h('button', {
|
||
type: 'button',
|
||
className: 'wb-btn-outline',
|
||
disabled: busy,
|
||
onClick: () => void applyRecommendedPresets(),
|
||
}, '一键按推荐填入分工'),
|
||
),
|
||
),
|
||
h('section', { key: 'seatlist', className: 'wb-card', style: { padding: 0, overflow: 'hidden', gap: 0 } },
|
||
h('div', { style: { padding: '10px 14px', borderBottom: '1px solid var(--ss-border)', display: 'flex', flexWrap: 'wrap', justifyContent: 'space-between', alignItems: 'center', gap: 8 } },
|
||
h('h3', { style: { margin: 0, fontSize: 12, fontWeight: 600 } }, '十席开关、模型与执行模式'),
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '点击任一席位展开配置模型、模式与说明'),
|
||
),
|
||
h('div', null, SEAT_IDS.map(id => {
|
||
const seat = seatById[id]
|
||
const tone = seatTone(seat)
|
||
const expanded = expandedConfigSeatId === id
|
||
const rec = seatRecMap[id] || {}
|
||
const actLabel = seat.status === 'bound' ? '打开' : seat.status === 'missing' ? '重建' : '上线'
|
||
const actHandler = seat.status === 'bound' ? () => void openSeat(id) : seat.status === 'missing' ? () => void rebuildSeat(id) : () => void enableSeat(id)
|
||
const configured = rec.configuredModel ?? rec.model ?? null
|
||
const modelShort = shortModelName(configured)
|
||
const srcShort = rec.modelSource === 'project' ? '项目覆盖' : rec.modelSource === 'global' ? '全局默认' : '未设默认'
|
||
const { presetInfo } = seatDraftState(id)
|
||
return h('div', { key: id, className: 'cfg-row' + (expanded ? ' is-open' : '') },
|
||
h('div', { className: 'cfg-row-head' },
|
||
h('button', {
|
||
type: 'button',
|
||
className: 'cfg-row-toggle',
|
||
'aria-expanded': expanded,
|
||
onClick: () => setExpandedConfigSeatId(expanded ? null : id),
|
||
},
|
||
h('span', { className: 'ss-dot is-' + tone }),
|
||
h('div', { className: 'cfg-seat-info' },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, minWidth: 0 } },
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700, fontSize: 14, flexShrink: 0, color: expanded ? 'var(--ss-primary)' : 'var(--ss-fg)' } }, seat.name),
|
||
h('span', { className: 'truncate', style: { color: 'var(--ss-muted)' } }, seat.duty),
|
||
),
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, minWidth: 0, flexWrap: 'wrap' } },
|
||
h('span', { className: 'font-mono-num truncate' }, modelShort),
|
||
h('span', { className: 'ss-pill' + (rec.modelSource === 'project' ? ' is-primary' : '') }, srcShort),
|
||
h('span', { className: 'ss-pill' + (presetInfo.presetValue ? ' is-primary' : '') }, presetInfo.presetShortLabel),
|
||
seat.modelSyncStatus === 'failed' ? h('span', { style: { color: 'var(--ss-error)', fontWeight: 500, flexShrink: 0 } }, '同步失败') : null,
|
||
),
|
||
),
|
||
),
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 6, paddingRight: 12, flexShrink: 0 } },
|
||
h('button', {
|
||
type: 'button',
|
||
className: seat.status === 'pending' ? 'wb-btn-primary' : 'wb-btn-outline',
|
||
disabled: busy || seat.status === 'creating',
|
||
onClick: actHandler,
|
||
}, actLabel),
|
||
h('button', {
|
||
type: 'button',
|
||
'aria-label': '展开配置',
|
||
style: { width: 28, height: 28, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', borderRadius: 6, color: 'var(--ss-muted)' },
|
||
onClick: () => setExpandedConfigSeatId(expanded ? null : id),
|
||
}, ChevronDown(expanded)),
|
||
),
|
||
),
|
||
expanded ? h('div', { className: 'cfg-inline-panel' }, renderModelControlsForSeat(id, saveSeatConfigFor)) : null,
|
||
)
|
||
})),
|
||
),
|
||
]
|
||
}
|
||
|
||
function renderModals() {
|
||
if (selectedTask) {
|
||
const liveTask = tasks.find(t => t.id === selectedTask.id) || selectedTask
|
||
const tm = TASK_META[liveTask.status] || { label: liveTask.status, tone: 'muted' }
|
||
const seatLabel = SEATS[liveTask.ownerSeatId]?.label || liveTask.ownerSeatId || '—'
|
||
const orig = liveTask.requirementSnapshot?.originalText || liveTask.requirement
|
||
return h('div', { className: 'wb-modal-backdrop', onClick: (e) => { if (e.target === e.currentTarget) setSelectedTask(null) } },
|
||
h('div', { className: 'wb-modal', role: 'dialog', 'aria-modal': 'true' },
|
||
h('div', { className: 'wb-modal-head' },
|
||
h('div', { style: { minWidth: 0 } },
|
||
h('div', { style: { display: 'flex', alignItems: 'center', gap: 8, fontSize: 12 } },
|
||
h('span', { className: 'font-mono-num', style: { color: 'var(--ss-muted)' } }, liveTask.id),
|
||
h('span', { className: 'ss-pill is-' + tm.tone }, tm.label),
|
||
h('span', { className: 'font-seal', style: { fontWeight: 700 } }, seatLabel),
|
||
),
|
||
h('h3', { className: 'wb-modal-title', style: { marginTop: 4 } }, liveTask.title),
|
||
),
|
||
h('button', { type: 'button', className: 'wb-modal-close', 'aria-label': '关闭', onClick: () => setSelectedTask(null) }, '✕'),
|
||
),
|
||
h('div', { className: 'wb-modal-body' },
|
||
liveTask.kind === 'workflow' ? renderStageStepper(liveTask.stage) : null,
|
||
orig ? h('div', { style: { borderRadius: 8, border: '1px solid color-mix(in srgb,var(--ss-primary) 30%,var(--ss-border))', background: 'color-mix(in srgb,var(--ss-primary) 7%,var(--ss-card))', padding: 10 } },
|
||
h('div', { style: { color: 'var(--ss-primary)', fontWeight: 500, marginBottom: 4 } }, '用户原话'),
|
||
h('p', { style: { margin: 0, lineHeight: 1.55 } }, '「' + orig + '」'),
|
||
) : null,
|
||
h('div', null,
|
||
h('div', { style: { color: 'var(--ss-muted)', fontWeight: 500, marginBottom: 4 } }, '任务说明'),
|
||
h('p', { style: { margin: 0, lineHeight: 1.6, whiteSpace: 'pre-wrap' } }, liveTask.goal || '(无任务说明)'),
|
||
),
|
||
liveTask.workflowBlockage ? h('div', { className: 'wb-alert', style: { flexDirection: 'column', alignItems: 'flex-start' } },
|
||
h('div', { style: { fontWeight: 600 } }, '当前阻塞 · ' + liveTask.workflowBlockage.label),
|
||
h('p', { style: { margin: 0, color: 'var(--ss-fg)' } }, liveTask.workflowBlockage.reason),
|
||
h('div', { style: { display: 'flex', flexWrap: 'wrap', gap: 8 } },
|
||
h('button', { type: 'button', className: 'wb-btn-outline', onClick: () => { setSelectedTask(null); void openSeat(liveTask.ownerSeatId) } }, '打开' + seatLabel + '会话'),
|
||
liveTask.deliveryState === 'unknown' && liveTask.deliveryId ? h('button', {
|
||
type: 'button', className: 'wb-btn-primary', disabled: busy,
|
||
onClick: () => void redispatchTask(liveTask),
|
||
}, '显式重投此任务') : null,
|
||
),
|
||
) : null,
|
||
Array.isArray(liveTask.consultations) && liveTask.consultations.length > 0 ? h('div', { style: { display: 'flex', flexDirection: 'column', gap: 6 } },
|
||
h('div', { style: { color: 'var(--ss-muted)', fontWeight: 500 } }, '会商记录 (' + liveTask.consultations.length + ')'),
|
||
liveTask.consultations.map(c => h('div', { key: c.id || c.createdAt, className: 'kv-box' },
|
||
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8, color: 'var(--ss-muted)', marginBottom: 4 } },
|
||
h('span', { style: { color: 'var(--ss-fg)', fontWeight: 500 } }, (SEATS[c.fromSeatId]?.label || c.fromSeatId) + ' → ' + (c.toSeatIds || []).map(x => SEATS[x]?.label || x).join('、')),
|
||
h('span', { className: 'font-mono-num' }, dateText(c.createdAt)),
|
||
),
|
||
h('div', { style: { lineHeight: 1.55 } }, c.text),
|
||
)),
|
||
) : null,
|
||
h('div', null,
|
||
h('div', { style: { color: 'var(--ss-muted)', fontWeight: 500, marginBottom: 4 } }, '任务完成情况'),
|
||
h('div', { className: 'kv-box', style: { whiteSpace: 'pre-wrap', lineHeight: 1.6 } }, liveTask.result || liveTask.note || '(尚未回报结果)'),
|
||
),
|
||
),
|
||
h('div', { className: 'wb-modal-foot' },
|
||
h('button', { type: 'button', className: 'wb-btn-outline', onClick: () => setSelectedTask(null) }, '关闭'),
|
||
),
|
||
),
|
||
)
|
||
}
|
||
|
||
if (durationModalOpen) {
|
||
const rows = tasks.map(t => ({ task: t, ms: taskDurationMs(t) })).filter(r => r.ms > 0).sort((a, b) => b.ms - a.ms)
|
||
return h('div', { className: 'wb-modal-backdrop', onClick: (e) => { if (e.target === e.currentTarget) setDurationModalOpen(false) } },
|
||
h('div', { className: 'wb-modal', role: 'dialog', 'aria-modal': 'true' },
|
||
h('div', { className: 'wb-modal-head' },
|
||
h('h3', { className: 'wb-modal-title' }, '任务耗时与用量说明'),
|
||
h('button', { type: 'button', className: 'wb-modal-close', 'aria-label': '关闭', onClick: () => setDurationModalOpen(false) }, '✕'),
|
||
),
|
||
h('div', { className: 'wb-modal-body' },
|
||
rows.length === 0
|
||
? h('p', { style: { margin: 0, color: 'var(--ss-muted)' } }, '暂无任务耗时记录。')
|
||
: h('div', { style: { borderRadius: 8, border: '1px solid var(--ss-border)', overflow: 'hidden' } },
|
||
h('table', { className: 'queue-table' },
|
||
h('thead', null, h('tr', null, h('th', null, '任务'), h('th', null, '承办'), h('th', { style: { textAlign: 'right' } }, '耗时'))),
|
||
h('tbody', null, rows.map(r => h('tr', { key: r.task.id },
|
||
h('td', null, r.task.title),
|
||
h('td', { className: 'font-seal', style: { fontWeight: 700 } }, SEATS[r.task.ownerSeatId]?.label || '—'),
|
||
h('td', { className: 'font-mono-num', style: { textAlign: 'right' } }, durationText(r.ms)),
|
||
))),
|
||
),
|
||
),
|
||
h('div', { className: 'kv-box', style: { color: 'var(--ss-muted)', lineHeight: 1.6 } },
|
||
h('strong', { style: { color: 'var(--ss-fg)' } }, '关于 Token 与金额统计:'),
|
||
'宿主尚未提供稳定 usage 数据源,这里不展示估算或虚构金额,接入真实用量后会在此呈现。'),
|
||
),
|
||
),
|
||
)
|
||
}
|
||
|
||
if (artifactModalOpen) {
|
||
return h('div', { className: 'wb-modal-backdrop', onClick: (e) => { if (e.target === e.currentTarget) setArtifactModalOpen(false) } },
|
||
h('div', { className: 'wb-modal', role: 'dialog', 'aria-modal': 'true' },
|
||
h('div', { className: 'wb-modal-head' },
|
||
h('h3', { className: 'wb-modal-title' }, '登记项目成果'),
|
||
h('button', { type: 'button', className: 'wb-modal-close', 'aria-label': '关闭', onClick: () => setArtifactModalOpen(false) }, '✕'),
|
||
),
|
||
h('div', { className: 'wb-modal-body' },
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '成果名称'),
|
||
h('input', { type: 'text', className: 'wb-input', value: artifactDraft.title, placeholder: '例如:竞品分析报告 v1', onChange: (e) => setArtifactDraft(p => ({ ...p, title: e.target.value })) }),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '文件路径'),
|
||
h('input', { type: 'text', className: 'wb-input', value: artifactDraft.path, placeholder: '例如:docs/竞品分析.md', onChange: (e) => setArtifactDraft(p => ({ ...p, path: e.target.value })) }),
|
||
),
|
||
h('label', { style: { display: 'flex', flexDirection: 'column', gap: 4 } },
|
||
h('span', { style: { color: 'var(--ss-muted)' } }, '摘要'),
|
||
h('textarea', { rows: 3, className: 'wb-textarea', value: artifactDraft.summary, placeholder: '这份成果解决了什么、在哪里', onChange: (e) => setArtifactDraft(p => ({ ...p, summary: e.target.value })) }),
|
||
),
|
||
),
|
||
h('div', { className: 'wb-modal-foot' },
|
||
h('button', { type: 'button', className: 'wb-btn-outline', onClick: () => setArtifactModalOpen(false) }, '取消'),
|
||
h('button', { type: 'button', className: 'wb-btn-primary', disabled: busy, onClick: () => void addArtifact() }, busy ? '提交中…' : '登记成果'),
|
||
),
|
||
),
|
||
)
|
||
}
|
||
return null
|
||
}
|
||
|
||
function renderMainBody() {
|
||
if (phase === 'loading') return h('div', { className: 'wb-empty-box' }, '正在载入项目工作台…')
|
||
if (phase === 'no-workspace') return h('div', { className: 'wb-empty-box' }, '当前会话尚未关联工作区,请在宿主中打开项目文件夹后重试。')
|
||
if (phase === 'error' && !view) {
|
||
return h('div', { className: 'wb-alert', style: { flexDirection: 'column', alignItems: 'flex-start' } },
|
||
h('span', null, error || '工作台加载失败'),
|
||
errorRetryable ? h('button', { type: 'button', className: 'wb-btn-primary', onClick: () => void loadProject() }, '重试') : null,
|
||
)
|
||
}
|
||
if (tab === 'flow') return renderFlowTab()
|
||
if (tab === 'memory') return renderMemoryTab()
|
||
if (tab === 'config') return renderConfigTab()
|
||
return renderCourtTab()
|
||
}
|
||
|
||
const navTabs = [
|
||
{ id: 'court', label: '朝堂', badge: pendingCount > 0 ? String(pendingCount) : null, tone: 'primary' },
|
||
{ id: 'flow', label: '流转', badge: openTasksCount > 0 ? String(openTasksCount) : null, tone: 'primary' },
|
||
{ id: 'memory', label: '共识', badge: (memory?.revision ?? 0) > 0 ? ('v' + memory.revision) : null, tone: 'muted' },
|
||
{ id: 'config', label: '配置', badge: syncIssues > 0 ? String(syncIssues) : null, tone: 'error' },
|
||
]
|
||
|
||
const headerDotTone = syncIssues > 0 ? 'is-error' : runningSeatsCount > 0 ? 'is-success is-pulse' : 'is-muted'
|
||
|
||
return h('div', { className: 'ssv2 ssw-tab-body', 'data-sansheng-sidebar': '1' },
|
||
h('header', { className: 'wb-header' },
|
||
h('div', { className: 'wb-header-row' },
|
||
h('div', { className: 'wb-brand' },
|
||
h('div', { className: 'wb-seal-badge' }, '省'),
|
||
h('div', { style: { minWidth: 0 } },
|
||
h('div', { className: 'wb-brand-title-row' },
|
||
h('h1', { className: 'wb-brand-title' }, '三省六部'),
|
||
h('span', { className: 'wb-role-badge hide-narrow' }, '单项目侧栏'),
|
||
),
|
||
h('p', { className: 'wb-subline' },
|
||
activeChatSeatId
|
||
? ('固定绑定当前会话项目 · 当前对话:' + (SEATS[activeChatSeatId]?.label || activeChatSeatId))
|
||
: ('固定绑定当前会话项目 · ' + wb.project.boundCount + ' / ' + wb.project.seatCount + ' 席已绑定')),
|
||
),
|
||
),
|
||
h('span', { className: 'wb-proj-pill', title: '已固定绑定当前会话所属项目' },
|
||
h('span', { className: 'ss-dot ' + headerDotTone }),
|
||
h('span', { className: 'wb-proj-name' }, wb.project.name || wb.projectTitle || '当前项目'),
|
||
),
|
||
),
|
||
h('nav', { className: 'wb-tabs', role: 'tablist', 'aria-label': '工作台导航' },
|
||
navTabs.map(t => h('button', {
|
||
key: t.id,
|
||
type: 'button',
|
||
role: 'tab',
|
||
'aria-selected': tab === t.id,
|
||
className: 'wb-tab-btn' + (tab === t.id ? ' is-active' : ''),
|
||
onClick: () => setTab(t.id),
|
||
},
|
||
h('span', null, t.label),
|
||
t.badge ? h('span', { className: 'wb-tab-badge ss-pill is-' + t.tone }, t.badge) : null,
|
||
)),
|
||
),
|
||
),
|
||
|
||
error && view ? h('div', { className: 'wb-toast-wrap' },
|
||
h('div', { className: 'wb-toast-box is-error', role: 'alert' },
|
||
h('span', null, error),
|
||
h('button', { type: 'button', className: 'wb-toast-close', onClick: () => setError(null) }, '✕'),
|
||
),
|
||
) : (!error && notice ? h('div', { className: 'wb-toast-wrap' },
|
||
h('div', { className: 'wb-toast-box is-primary', role: 'status' },
|
||
h('span', null, notice),
|
||
h('button', { type: 'button', className: 'wb-toast-close', onClick: () => setNotice(null) }, '✕'),
|
||
),
|
||
) : null),
|
||
|
||
h('main', { className: 'wb-body' }, renderMainBody()),
|
||
|
||
h('footer', { className: 'wb-footer' },
|
||
h('span', { className: 'truncate' },
|
||
'项目 ' + (wb.project.name || '—') + ' · ' + wb.project.boundCount + ' / ' + wb.project.seatCount + ' 席已绑定 · 共识 v' + (memory?.revision ?? 0)),
|
||
h('button', { type: 'button', className: 'wb-refresh-btn', disabled: busy, onClick: () => void loadProject() },
|
||
RefreshIcon(),
|
||
h('span', null, '刷新'),
|
||
),
|
||
),
|
||
|
||
renderModals(),
|
||
)
|
||
}
|