feat(qaops): 接入独立只读问答查询与治理覆盖复检
This commit is contained in:
@@ -4,6 +4,7 @@ import { DocumentWorkbench } from './DocumentWorkbench'
|
||||
import { SourceCatalogBrowser } from './SourceCatalogBrowser'
|
||||
import { WeKnoraMonitor } from './WeKnoraMonitor'
|
||||
import { VersionHistory } from './VersionHistory'
|
||||
import { QAOperations } from './QAOperations'
|
||||
import { SourceLinkManager } from './SourceLinkManager'
|
||||
import { SystemSettings } from './SystemSettings'
|
||||
import { WorkspaceContextTabsBar, WorkspaceContextTabsSetter } from './workspaceContext'
|
||||
@@ -59,6 +60,7 @@ const workspaceStorageKey = 'knowledge-governance.workspace.v1'
|
||||
const modules: ReadonlyArray<{ id: ModuleId; label: string; icon: string }> = [
|
||||
{ id: 'dashboard', label: '来源与目录', icon: '◫' },
|
||||
{ id: 'tasks', label: '解析监控', icon: '↻' },
|
||||
{ id: 'qaops', label: '问答运营', icon: '▤' },
|
||||
{ id: 'releases', label: '发布管理', icon: '⇧' },
|
||||
{ id: 'settings', label: '系统设置', icon: '⚙' },
|
||||
{ id: 'versions', label: '版本记录', icon: '⌥' },
|
||||
@@ -3004,6 +3006,8 @@ export default function App() {
|
||||
<DocumentWorkbench mode="attention" connections={connectionPage.items} />
|
||||
) : workspace.activeTab === 'versions' ? (
|
||||
<VersionHistory />
|
||||
) : workspace.activeTab === 'qaops' ? (
|
||||
<QAOperations />
|
||||
) : (
|
||||
<ModulePage
|
||||
moduleId={workspace.activeTab}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
import { renderToStaticMarkup } from 'react-dom/server'
|
||||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { QAOperationsView } from './QAOperations'
|
||||
import type { QARecord, QARecordPage } from './qaOps'
|
||||
import { restoreWorkspace } from './workspace'
|
||||
|
||||
const item: QARecord = {
|
||||
id: 'fixture',
|
||||
status: 'succeeded',
|
||||
question: '<script>not executable</script>',
|
||||
answer: '当前暂无已发布的权威知识。',
|
||||
asked_at: '2026-10-14T03:00:00Z',
|
||||
time_source: 'request_message.created_at',
|
||||
asker: '测试人员',
|
||||
trigger_person: '测试昵称',
|
||||
department: '',
|
||||
region: '',
|
||||
references: [{ title: '测试引用' }],
|
||||
media: [],
|
||||
feedback: { asker_value: 'down', up: 0, down: 1 },
|
||||
source_coverage: { verdict: 'covered', reason_code: 'covered_has_references', evaluator_version: 'v5' },
|
||||
coverage: {
|
||||
verdict: 'uncovered',
|
||||
state: 'checked',
|
||||
rule_version: 'governance-answer-substring-v1',
|
||||
matched_text: '暂无已发布',
|
||||
},
|
||||
is_correct: false,
|
||||
}
|
||||
const page: QARecordPage = {
|
||||
items: [item],
|
||||
columns: ['answer', 'coverage', 'is_correct', 'asked_at', 'asker', 'question', 'feedback'],
|
||||
total: 1,
|
||||
has_more: false,
|
||||
next_cursor: '',
|
||||
as_of: '2026-10-14T04:00:00Z',
|
||||
}
|
||||
const props = {
|
||||
page,
|
||||
status: null,
|
||||
loading: false,
|
||||
error: null,
|
||||
detail: null,
|
||||
detailLoading: false,
|
||||
detailError: null,
|
||||
onSelect: vi.fn(),
|
||||
onCloseDetail: vi.fn(),
|
||||
onLoadMore: vi.fn(),
|
||||
onRetry: vi.fn(),
|
||||
}
|
||||
|
||||
describe('QA operations workbench', () => {
|
||||
it('shows populated columns in required order and keeps false/downvotes visible', () => {
|
||||
const html = renderToStaticMarkup(<QAOperationsView {...props} />)
|
||||
expect(html).toContain('原始问题')
|
||||
expect(html.indexOf('AI答案')).toBeLessThan(html.indexOf('是否覆盖'))
|
||||
expect(html.indexOf('是否正确')).toBeLessThan(html.indexOf('提问时间'))
|
||||
expect(html).toContain('否(点踩)')
|
||||
expect(html).toContain('是否正确')
|
||||
expect(html).not.toContain('<th>部门</th>')
|
||||
expect(html).not.toContain('<th>产品分类</th>')
|
||||
expect(html).not.toContain('<script>not executable</script>')
|
||||
})
|
||||
it('distinguishes an unavailable source from a successful empty query', () => {
|
||||
const html = renderToStaticMarkup(<QAOperationsView {...props} page={null} error="只读源不可用" />)
|
||||
expect(html).toContain('role="alert"')
|
||||
expect(html).toContain('只读源不可用')
|
||||
expect(html).not.toContain('没有符合条件的问答')
|
||||
})
|
||||
it('shows complete source and governance evidence separately in the detail drawer', () => {
|
||||
const html = renderToStaticMarkup(<QAOperationsView {...props} detail={item} />)
|
||||
expect(html).toContain('role="dialog"')
|
||||
expect(html).toContain('暂无已发布')
|
||||
expect(html).toContain('源端覆盖(仅对照)')
|
||||
expect(html).toContain('covered_has_references')
|
||||
expect(html).toContain('测试引用')
|
||||
})
|
||||
it('restores the existing singleton workspace tab without creating another application', () => {
|
||||
const restored = restoreWorkspace(JSON.stringify({ openTabs: ['dashboard', 'qaops'], activeTab: 'qaops' }))
|
||||
expect(restored.openTabs).toEqual(['dashboard', 'qaops'])
|
||||
expect(restored.activeTab).toBe('qaops')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,428 @@
|
||||
import { useEffect, useRef, useState } from 'react'
|
||||
import type { FormEvent } from 'react'
|
||||
import { useOptionalAuth } from './auth'
|
||||
import { fetchQARecord, fetchQARecords, fetchQAStatus, qaCellValue, qaColumns } from './qaOps'
|
||||
import type { QAQuery, QARecord, QARecordPage, QAStatus } from './qaOps'
|
||||
import './qaOps.css'
|
||||
|
||||
interface ViewProps {
|
||||
page: QARecordPage | null
|
||||
status: QAStatus | null
|
||||
loading: boolean
|
||||
error: string | null
|
||||
detail: QARecord | null
|
||||
detailLoading: boolean
|
||||
detailError: string | null
|
||||
onSelect: (id: string) => void
|
||||
onCloseDetail: () => void
|
||||
onLoadMore: () => void
|
||||
onRetry: () => void
|
||||
}
|
||||
const stateLabels = { disabled: '未配置', unavailable: '连接不可用', blocked: '接入被阻断', connected: '已连接' }
|
||||
const warningLabels: Record<string, string> = {
|
||||
database_temp_enabled: '数据库仍允许临时对象:未视为完全只读验收通过',
|
||||
database_transport_unencrypted: '数据库连接未启用 TLS:上线前须完成传输安全审核',
|
||||
}
|
||||
const stamp = (value: string) => new Date(value).toLocaleString('zh-CN', { hour12: false })
|
||||
const statusLabels: Record<string, string> = {
|
||||
succeeded: '成功',
|
||||
failed: '失败',
|
||||
running: '处理中',
|
||||
cancelled: '已取消',
|
||||
}
|
||||
const sourceCoverageLabels: Record<string, string> = { covered: '已覆盖', uncovered: '未覆盖' }
|
||||
|
||||
export function QAOperationsView(props: ViewProps) {
|
||||
const page = props.page
|
||||
const columns = qaColumns.filter(({ key }) => page?.columns.includes(key))
|
||||
const detail = props.detail
|
||||
const showDrawer = Boolean(detail || props.detailLoading || props.detailError)
|
||||
return (
|
||||
<section className="qa-ops-results" aria-label="问答记录">
|
||||
<div className="qa-ops-result-bar">
|
||||
<span>
|
||||
{props.loading ? '正在读取…' : page ? `共 ${page.total} 条 · 已显示 ${page.items.length} 条` : '尚未读取问答'}
|
||||
</span>
|
||||
<span className="qa-ops-source">
|
||||
DobotAI 2.0 / 钉钉 · 独立只读连接{props.status ? ` · ${stateLabels[props.status.state]}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
{props.status?.warnings.map((warning) => (
|
||||
<p className="qa-ops-warning" key={warning}>
|
||||
{warningLabels[warning] ?? '数据源有待审核的安全告警'}
|
||||
</p>
|
||||
))}
|
||||
{props.error ? (
|
||||
<div className="error-banner" role="alert">
|
||||
{props.error}{' '}
|
||||
<button type="button" onClick={props.onRetry} disabled={props.loading}>
|
||||
重试读取
|
||||
</button>
|
||||
</div>
|
||||
) : null}
|
||||
{page && page.items.length > 0 ? (
|
||||
<div className="qa-ops-table-scroll" aria-label="问答表格滚动区" tabIndex={0}>
|
||||
<table className="qa-ops-table">
|
||||
<thead>
|
||||
<tr>
|
||||
{columns.map(({ key, label }) => (
|
||||
<th key={key}>{label}</th>
|
||||
))}
|
||||
<th>操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{page.items.map((item) => (
|
||||
<tr key={item.id}>
|
||||
{columns.map(({ key }) => (
|
||||
<td
|
||||
key={key}
|
||||
className={
|
||||
key === 'answer' || key === 'question' || key === 'question_chinese' ? 'qa-ops-text-cell' : ''
|
||||
}
|
||||
>
|
||||
<span
|
||||
className={
|
||||
key === 'coverage' && item.coverage.verdict === 'uncovered' ? 'qa-ops-uncovered' : ''
|
||||
}
|
||||
>
|
||||
{qaCellValue(item, key) ?? '—'}
|
||||
</span>
|
||||
</td>
|
||||
))}
|
||||
<td>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => props.onSelect(item.id)}
|
||||
aria-label={`查看问答 ${item.id} 的详情`}
|
||||
>
|
||||
详情
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
) : page && !props.loading && !props.error ? (
|
||||
<p className="qa-ops-empty">没有符合条件的问答,请调整时间范围或关键词。</p>
|
||||
) : null}
|
||||
{page ? (
|
||||
<footer className="qa-ops-page-bar">
|
||||
<span>本次读取:{stamp(page.as_of)} · 空列按整个筛选结果隐藏</span>
|
||||
{page.has_more ? (
|
||||
<button type="button" onClick={props.onLoadMore} disabled={props.loading}>
|
||||
{props.loading ? '读取中…' : '加载更多'}
|
||||
</button>
|
||||
) : page.items.length > 0 ? (
|
||||
<span>已显示全部</span>
|
||||
) : null}
|
||||
</footer>
|
||||
) : null}
|
||||
{showDrawer ? (
|
||||
<>
|
||||
<button
|
||||
className="qa-ops-backdrop"
|
||||
type="button"
|
||||
onClick={props.onCloseDetail}
|
||||
aria-label="关闭问答详情遮罩"
|
||||
/>
|
||||
<aside
|
||||
className="qa-ops-drawer"
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
aria-label="问答详情"
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === 'Escape') props.onCloseDetail()
|
||||
if (event.key === 'Tab') {
|
||||
const buttons = Array.from(
|
||||
event.currentTarget.querySelectorAll<HTMLElement>('button, a[href], input, [tabindex="0"]')
|
||||
)
|
||||
const first = buttons[0],
|
||||
last = buttons[buttons.length - 1]
|
||||
if (event.shiftKey && document.activeElement === first) {
|
||||
event.preventDefault()
|
||||
last?.focus()
|
||||
}
|
||||
if (!event.shiftKey && document.activeElement === last) {
|
||||
event.preventDefault()
|
||||
first?.focus()
|
||||
}
|
||||
}
|
||||
}}
|
||||
>
|
||||
<header>
|
||||
<h3>问答详情</h3>
|
||||
<button type="button" autoFocus onClick={props.onCloseDetail}>
|
||||
关闭详情
|
||||
</button>
|
||||
</header>
|
||||
{props.detailLoading ? <p role="status">正在读取完整问答…</p> : null}
|
||||
{props.detailError ? (
|
||||
<p className="error-banner" role="alert">
|
||||
{props.detailError}
|
||||
</p>
|
||||
) : null}
|
||||
{detail ? (
|
||||
<div className="qa-ops-detail-content">
|
||||
<dl className="qa-ops-detail-meta">
|
||||
<dt>提问时间</dt>
|
||||
<dd>
|
||||
{stamp(detail.asked_at)}
|
||||
{detail.time_source === 'turn.created_at' ? '(问答时间回退,入站消息缺失)' : ''}
|
||||
</dd>
|
||||
<dt>提问人</dt>
|
||||
<dd>{detail.asker || '未关联'}</dd>
|
||||
<dt>问答状态</dt>
|
||||
<dd>{statusLabels[detail.status] ?? detail.status}</dd>
|
||||
<dt>流程触发人员信息</dt>
|
||||
<dd>{detail.trigger_person || '未记录'}</dd>
|
||||
</dl>
|
||||
<h4>原始问题</h4>
|
||||
<div className="qa-ops-full-text">{detail.question || '无文本问题'}</div>
|
||||
<h4>AI答案</h4>
|
||||
<div className="qa-ops-full-text">{detail.answer || '尚无答案;不默认判覆盖或正确'}</div>
|
||||
<h4>治理侧覆盖复检</h4>
|
||||
<p>
|
||||
{detail.coverage.verdict === 'uncovered'
|
||||
? '未覆盖:答案包含“暂无已发布”,引用不能抵消这一结果。'
|
||||
: '待评估:未命中“暂无已发布”不代表已覆盖。'}
|
||||
</p>
|
||||
<p className="qa-ops-muted">规则:{detail.coverage.rule_version}</p>
|
||||
<h4>源端覆盖(仅对照)</h4>
|
||||
<p>
|
||||
{sourceCoverageLabels[detail.source_coverage.verdict] ?? '未记录'} ·{' '}
|
||||
{detail.source_coverage.evaluator_version || '无版本'}
|
||||
</p>
|
||||
<p className="qa-ops-muted">{detail.source_coverage.reason_code || '未记录判定原因'}</p>
|
||||
<h4>用户反馈</h4>
|
||||
<p>
|
||||
提问人:
|
||||
{detail.feedback.asker_value === 'up'
|
||||
? '点赞'
|
||||
: detail.feedback.asker_value === 'down'
|
||||
? '点踩'
|
||||
: '无反馈'}
|
||||
;全部反馈:赞 {detail.feedback.up} / 踩 {detail.feedback.down}
|
||||
</p>
|
||||
<h4>引用知识</h4>
|
||||
<pre>{JSON.stringify(detail.references, null, 2)}</pre>
|
||||
<details>
|
||||
<summary>问题媒体记录</summary>
|
||||
<pre>{JSON.stringify(detail.media, null, 2)}</pre>
|
||||
</details>
|
||||
</div>
|
||||
) : null}
|
||||
</aside>
|
||||
</>
|
||||
) : null}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
function localInput(value: Date): string {
|
||||
return new Date(value.getTime() - value.getTimezoneOffset() * 60_000).toISOString().slice(0, 16)
|
||||
}
|
||||
function initialDraft() {
|
||||
const end = new Date()
|
||||
return { start: localInput(new Date(end.getTime() - 7 * 24 * 3600_000)), end: localInput(end), keyword: '' }
|
||||
}
|
||||
|
||||
export function QAOperations() {
|
||||
const auth = useOptionalAuth()
|
||||
const canRead = auth?.identity?.role === 'admin'
|
||||
const [draft, setDraft] = useState(initialDraft)
|
||||
const [query, setQuery] = useState<QAQuery | null>(null)
|
||||
const [page, setPage] = useState<QARecordPage | null>(null)
|
||||
const [status, setStatus] = useState<QAStatus | null>(null)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(false)
|
||||
const [revision, setRevision] = useState(0)
|
||||
const [detail, setDetail] = useState<QARecord | null>(null)
|
||||
const [detailLoading, setDetailLoading] = useState(false)
|
||||
const [detailError, setDetailError] = useState<string | null>(null)
|
||||
const generation = useRef(0)
|
||||
const detailRequest = useRef<AbortController | null>(null)
|
||||
const moreRequest = useRef<AbortController | null>(null)
|
||||
const returnFocus = useRef<HTMLElement | null>(null)
|
||||
|
||||
useEffect(() => {
|
||||
if (!canRead || query) return
|
||||
setQuery({
|
||||
start: new Date(draft.start).toISOString(),
|
||||
end: new Date(draft.end).toISOString(),
|
||||
keyword: draft.keyword,
|
||||
cursor: '',
|
||||
})
|
||||
}, [canRead, draft, query])
|
||||
|
||||
useEffect(() => {
|
||||
if (!query || !canRead) return
|
||||
const controller = new AbortController()
|
||||
generation.current += 1
|
||||
moreRequest.current?.abort()
|
||||
detailRequest.current?.abort()
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
setPage(null)
|
||||
setDetail(null)
|
||||
setDetailError(null)
|
||||
setDetailLoading(false)
|
||||
void fetchQAStatus(controller.signal)
|
||||
.then(setStatus)
|
||||
.catch(() => {
|
||||
if (!controller.signal.aborted) setStatus(null)
|
||||
})
|
||||
void fetchQARecords(query, controller.signal)
|
||||
.then((result) => {
|
||||
if (!controller.signal.aborted) setPage(result)
|
||||
})
|
||||
.catch((reason: unknown) => {
|
||||
if (!controller.signal.aborted) setError(reason instanceof Error ? reason.message : '问答读取失败')
|
||||
})
|
||||
.finally(() => {
|
||||
if (!controller.signal.aborted) setLoading(false)
|
||||
})
|
||||
return () => controller.abort()
|
||||
}, [query, canRead, revision])
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
detailRequest.current?.abort()
|
||||
moreRequest.current?.abort()
|
||||
},
|
||||
[]
|
||||
)
|
||||
|
||||
const submit = (event: FormEvent) => {
|
||||
event.preventDefault()
|
||||
try {
|
||||
const start = new Date(draft.start),
|
||||
end = new Date(draft.end)
|
||||
if (!(start < end)) throw new Error('开始时间必须早于结束时间')
|
||||
setQuery({ start: start.toISOString(), end: end.toISOString(), keyword: draft.keyword, cursor: '' })
|
||||
} catch (reason) {
|
||||
setError(reason instanceof Error ? reason.message : '时间格式无效')
|
||||
}
|
||||
}
|
||||
const select = async (id: string) => {
|
||||
detailRequest.current?.abort()
|
||||
returnFocus.current = document.activeElement as HTMLElement | null
|
||||
const controller = new AbortController()
|
||||
detailRequest.current = controller
|
||||
setDetail(null)
|
||||
setDetailError(null)
|
||||
setDetailLoading(true)
|
||||
try {
|
||||
const result = await fetchQARecord(id, controller.signal)
|
||||
if (!controller.signal.aborted) setDetail(result)
|
||||
} catch (reason) {
|
||||
if (!controller.signal.aborted) setDetailError(reason instanceof Error ? reason.message : '详情读取失败')
|
||||
} finally {
|
||||
if (!controller.signal.aborted) setDetailLoading(false)
|
||||
}
|
||||
}
|
||||
const close = () => {
|
||||
detailRequest.current?.abort()
|
||||
setDetail(null)
|
||||
setDetailError(null)
|
||||
setDetailLoading(false)
|
||||
returnFocus.current?.focus()
|
||||
}
|
||||
const loadMore = async () => {
|
||||
if (!query || !page?.has_more || loading) return
|
||||
const currentGeneration = generation.current
|
||||
const controller = new AbortController()
|
||||
moreRequest.current = controller
|
||||
setLoading(true)
|
||||
setError(null)
|
||||
try {
|
||||
const result = await fetchQARecords({ ...query, cursor: page.next_cursor }, controller.signal)
|
||||
if (!controller.signal.aborted && currentGeneration === generation.current) {
|
||||
setPage((current) =>
|
||||
current
|
||||
? {
|
||||
...result,
|
||||
items: [
|
||||
...current.items,
|
||||
...result.items.filter((item) => !current.items.some(({ id }) => id === item.id)),
|
||||
],
|
||||
}
|
||||
: result
|
||||
)
|
||||
}
|
||||
} catch (reason) {
|
||||
if (!controller.signal.aborted && currentGeneration === generation.current)
|
||||
setError(reason instanceof Error ? reason.message : '翻页失败')
|
||||
} finally {
|
||||
if (!controller.signal.aborted && currentGeneration === generation.current) setLoading(false)
|
||||
}
|
||||
}
|
||||
return (
|
||||
<section className="qa-ops" aria-label="问答运营">
|
||||
<header className="qa-ops-header">
|
||||
<h2>
|
||||
问答运营 <span>/ 问答记录</span>
|
||||
</h2>
|
||||
<p>真实问答只读查询;原始记录、源端判断与治理复检分开保留。</p>
|
||||
</header>
|
||||
{!canRead ? (
|
||||
<p className="error-banner" role="alert">
|
||||
尚未配置员工问答可见范围,当前仅管理员可访问。
|
||||
</p>
|
||||
) : (
|
||||
<>
|
||||
<form className="qa-ops-query" onSubmit={submit}>
|
||||
<label>
|
||||
开始时间
|
||||
<input
|
||||
type="datetime-local"
|
||||
required
|
||||
value={draft.start}
|
||||
onChange={(event) => setDraft({ ...draft, start: event.target.value })}
|
||||
/>
|
||||
</label>
|
||||
<label>
|
||||
结束时间(不含)
|
||||
<input
|
||||
type="datetime-local"
|
||||
required
|
||||
value={draft.end}
|
||||
onChange={(event) => setDraft({ ...draft, end: event.target.value })}
|
||||
/>
|
||||
</label>
|
||||
<label className="qa-ops-keyword">
|
||||
关键词
|
||||
<input
|
||||
type="search"
|
||||
maxLength={200}
|
||||
placeholder="检索原始问题"
|
||||
value={draft.keyword}
|
||||
onChange={(event) => setDraft({ ...draft, keyword: event.target.value })}
|
||||
/>
|
||||
</label>
|
||||
<button type="submit" disabled={loading}>
|
||||
查询
|
||||
</button>
|
||||
</form>
|
||||
<p className="qa-ops-slice-note">
|
||||
当前切片:问答查询与覆盖复检。外语翻译、AI评估及人员映射尚未接入;空值不默认填“否”。
|
||||
</p>
|
||||
<QAOperationsView
|
||||
page={page}
|
||||
status={status}
|
||||
error={error}
|
||||
loading={loading}
|
||||
detail={detail}
|
||||
detailLoading={detailLoading}
|
||||
detailError={detailError}
|
||||
onSelect={(id) => void select(id)}
|
||||
onCloseDetail={close}
|
||||
onLoadMore={() => void loadMore()}
|
||||
onRetry={() => setRevision((value) => value + 1)}
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,267 @@
|
||||
.qa-ops {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
min-width: 0;
|
||||
gap: 14px;
|
||||
padding: 20px;
|
||||
height: calc(100dvh - 44px);
|
||||
overflow: hidden;
|
||||
}
|
||||
.qa-ops-header h2 {
|
||||
margin: 0 0 5px;
|
||||
font-size: 21px;
|
||||
font-weight: 650;
|
||||
}
|
||||
.qa-ops-header h2 span {
|
||||
font-size: 15px;
|
||||
color: var(--ink-mute);
|
||||
font-weight: 400;
|
||||
}
|
||||
.qa-ops-header p,
|
||||
.qa-ops-slice-note {
|
||||
margin: 0;
|
||||
color: var(--ink-mute);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
.qa-ops-query {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: end;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
border: 1px solid var(--border-base);
|
||||
background: var(--bg-panel);
|
||||
}
|
||||
.qa-ops-query label {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 6px;
|
||||
color: var(--ink-mute);
|
||||
font-size: 12px;
|
||||
}
|
||||
.qa-ops-query input {
|
||||
min-height: 36px;
|
||||
min-width: 0;
|
||||
padding: 7px 10px;
|
||||
color: var(--ink-strong);
|
||||
border: 1px solid var(--border-strong);
|
||||
border-radius: var(--r-sm);
|
||||
background: var(--bg-panel);
|
||||
}
|
||||
.qa-ops-keyword {
|
||||
flex: 1;
|
||||
min-width: 170px;
|
||||
}
|
||||
.qa-ops-query button {
|
||||
min-height: 36px;
|
||||
min-width: 72px;
|
||||
color: #fff;
|
||||
background: var(--c-run);
|
||||
border: 1px solid var(--c-run);
|
||||
}
|
||||
.qa-ops button:focus-visible,
|
||||
.qa-ops input:focus-visible,
|
||||
.qa-ops-table-scroll:focus-visible {
|
||||
outline: 2px solid var(--c-run);
|
||||
outline-offset: 2px;
|
||||
}
|
||||
.qa-ops-results {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
border: 1px solid var(--border-base);
|
||||
background: var(--bg-panel);
|
||||
}
|
||||
.qa-ops-result-bar,
|
||||
.qa-ops-page-bar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
flex-wrap: wrap;
|
||||
padding: 11px 14px;
|
||||
font-size: 12px;
|
||||
color: var(--ink-mute);
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
.qa-ops-result-bar {
|
||||
border-bottom: 1px solid var(--border-base);
|
||||
}
|
||||
.qa-ops-source {
|
||||
color: var(--ink-mute);
|
||||
}
|
||||
.qa-ops-warning {
|
||||
margin: 8px 14px;
|
||||
padding: 7px 10px;
|
||||
font-size: 12px;
|
||||
line-height: 1.5;
|
||||
color: var(--c-warn);
|
||||
background: var(--c-warn-bg);
|
||||
border-left: 2px solid var(--c-warn-border);
|
||||
}
|
||||
.qa-ops-table-scroll {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow: auto;
|
||||
}
|
||||
.qa-ops-table {
|
||||
width: 100%;
|
||||
min-width: 980px;
|
||||
border-collapse: collapse;
|
||||
table-layout: auto;
|
||||
font-size: 13px;
|
||||
}
|
||||
.qa-ops-table th {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 1;
|
||||
white-space: nowrap;
|
||||
background: var(--bg-soft);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--ink-mute);
|
||||
}
|
||||
.qa-ops-table td,
|
||||
.qa-ops-table th {
|
||||
padding: 11px 12px;
|
||||
border-bottom: 1px solid var(--border-soft);
|
||||
text-align: left;
|
||||
vertical-align: top;
|
||||
}
|
||||
.qa-ops-table td {
|
||||
min-width: 90px;
|
||||
max-width: 210px;
|
||||
color: var(--ink-strong);
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.qa-ops-table tr:hover td {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
.qa-ops-table td.qa-ops-text-cell {
|
||||
min-width: 240px;
|
||||
max-width: 340px;
|
||||
}
|
||||
.qa-ops-text-cell > span {
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 3;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
.qa-ops-uncovered {
|
||||
color: var(--c-warn);
|
||||
font-weight: 600;
|
||||
}
|
||||
.qa-ops-empty {
|
||||
padding: 35px 16px;
|
||||
margin: 0;
|
||||
color: var(--ink-mute);
|
||||
text-align: center;
|
||||
}
|
||||
.qa-ops-page-bar {
|
||||
border-top: 1px solid var(--border-base);
|
||||
}
|
||||
.qa-ops-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 80;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 0;
|
||||
border-radius: 0;
|
||||
background: rgb(15 23 32 / 28%);
|
||||
cursor: default;
|
||||
}
|
||||
.qa-ops-backdrop:hover {
|
||||
background: rgb(15 23 32 / 28%);
|
||||
}
|
||||
.qa-ops-drawer {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 81;
|
||||
width: min(760px, 100vw);
|
||||
height: 100vh;
|
||||
overflow: auto;
|
||||
padding: 22px;
|
||||
background: var(--bg-panel);
|
||||
border-left: 1px solid var(--border-strong);
|
||||
color: var(--ink-strong);
|
||||
}
|
||||
.qa-ops-drawer > header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
gap: 14px;
|
||||
position: sticky;
|
||||
top: -22px;
|
||||
padding: 12px 0;
|
||||
background: var(--bg-panel);
|
||||
border-bottom: 1px solid var(--border-base);
|
||||
}
|
||||
.qa-ops-drawer h3 {
|
||||
margin: 0;
|
||||
font-size: 18px;
|
||||
}
|
||||
.qa-ops-drawer h4 {
|
||||
margin: 24px 0 9px;
|
||||
font-size: 14px;
|
||||
}
|
||||
.qa-ops-detail-content {
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.qa-ops-detail-meta {
|
||||
display: grid;
|
||||
grid-template-columns: 140px 1fr;
|
||||
gap: 6px 14px;
|
||||
margin: 18px 0;
|
||||
}
|
||||
.qa-ops-detail-meta dt,
|
||||
.qa-ops-muted {
|
||||
color: var(--ink-mute);
|
||||
}
|
||||
.qa-ops-detail-meta dd {
|
||||
margin: 0;
|
||||
}
|
||||
.qa-ops-full-text {
|
||||
white-space: pre-wrap;
|
||||
background: var(--bg-soft);
|
||||
padding: 12px;
|
||||
border: 1px solid var(--border-soft);
|
||||
}
|
||||
.qa-ops-drawer pre {
|
||||
white-space: pre-wrap;
|
||||
word-break: break-word;
|
||||
background: var(--bg-soft);
|
||||
padding: 12px;
|
||||
font-size: 12px;
|
||||
}
|
||||
@media (max-width: 760px) {
|
||||
.qa-ops {
|
||||
height: auto;
|
||||
min-height: calc(100dvh - 44px);
|
||||
padding: 14px;
|
||||
overflow: visible;
|
||||
}
|
||||
.qa-ops-results {
|
||||
flex: none;
|
||||
}
|
||||
.qa-ops-query label {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
.qa-ops-table-scroll {
|
||||
min-height: 160px;
|
||||
max-height: 55vh;
|
||||
}
|
||||
.qa-ops-drawer {
|
||||
padding: 14px;
|
||||
}
|
||||
.qa-ops-detail-meta {
|
||||
grid-template-columns: 100px 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest'
|
||||
import { fetchQARecords, parseQARecord, parseQARecordPage } from './qaOps'
|
||||
|
||||
export const fixtureRecord = {
|
||||
id: 'test-turn',
|
||||
status: 'succeeded',
|
||||
question: 'How to configure CR5?',
|
||||
answer: '当前暂无已发布的权威知识,暂不建议操作。',
|
||||
asked_at: '2026-10-14T03:00:00Z',
|
||||
time_source: 'request_message.created_at',
|
||||
asker: '测试人员',
|
||||
trigger_person: '回调昵称',
|
||||
department: '',
|
||||
region: '',
|
||||
references: [{ title: '测试引用' }],
|
||||
media: [],
|
||||
source_coverage: { verdict: 'covered', reason_code: 'covered_has_references', evaluator_version: 'v5' },
|
||||
feedback: { asker_value: 'down', up: 0, down: 1 },
|
||||
coverage: {
|
||||
state: 'checked',
|
||||
verdict: 'uncovered',
|
||||
rule_version: 'governance-answer-substring-v1',
|
||||
matched_text: '暂无已发布',
|
||||
},
|
||||
}
|
||||
const fixturePage = {
|
||||
items: [fixtureRecord],
|
||||
columns: ['answer', 'coverage', 'asked_at', 'asker', 'question', 'trigger_person', 'feedback'],
|
||||
total: 1,
|
||||
has_more: false,
|
||||
next_cursor: '',
|
||||
as_of: '2026-10-14T04:00:00Z',
|
||||
}
|
||||
|
||||
afterEach(() => vi.unstubAllGlobals())
|
||||
|
||||
describe('QA operations data contract', () => {
|
||||
it('keeps governance coverage separate from source coverage and downvotes', () => {
|
||||
const item = parseQARecord(fixtureRecord)
|
||||
expect(item.coverage.verdict).toBe('uncovered')
|
||||
expect(item.source_coverage.verdict).toBe('covered')
|
||||
expect(item.feedback.asker_value).toBe('down')
|
||||
expect(parseQARecordPage(fixturePage).columns).not.toContain('department')
|
||||
})
|
||||
it('rejects malformed rows and pagination rather than rendering an empty success', () => {
|
||||
expect(() => parseQARecord({ ...fixtureRecord, answer: null })).toThrow('响应无效')
|
||||
expect(() => parseQARecordPage({ ...fixturePage, has_more: true })).toThrow('响应无效')
|
||||
expect(() => parseQARecordPage({ ...fixturePage, columns: ['unapproved_secret_column'] })).toThrow('响应无效')
|
||||
})
|
||||
it('uses only the governance API and preserves keyword text', async () => {
|
||||
const mocked = vi.fn().mockResolvedValue(new Response(JSON.stringify({ data: fixturePage }), { status: 200 }))
|
||||
vi.stubGlobal('fetch', mocked)
|
||||
await fetchQARecords({ start: '2026-10-14T00:00:00Z', end: '2026-10-15T00:00:00Z', keyword: '%_CR5', cursor: '' })
|
||||
const url = String(mocked.mock.calls[0][0])
|
||||
expect(url.startsWith('/api/v1/qa-ops/records?')).toBe(true)
|
||||
expect(new URL(url, 'http://localhost').searchParams.get('keyword')).toBe('%_CR5')
|
||||
expect(url).not.toContain('tenant')
|
||||
})
|
||||
it('surfaces source errors, never silently replacing them with no questions', async () => {
|
||||
vi.stubGlobal(
|
||||
'fetch',
|
||||
vi.fn().mockResolvedValue(new Response(JSON.stringify({ error: '只读权限校验未通过' }), { status: 503 }))
|
||||
)
|
||||
await expect(fetchQARecords({ start: '', end: '', keyword: '', cursor: '' })).rejects.toThrow('只读权限校验未通过')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,197 @@
|
||||
export const qaColumns = [
|
||||
{ key: 'question_chinese', label: '中文问题' },
|
||||
{ key: 'answer', label: 'AI答案' },
|
||||
{ key: 'coverage', label: '是否覆盖' },
|
||||
{ key: 'is_correct', label: '是否正确' },
|
||||
{ key: 'product_category', label: '产品分类' },
|
||||
{ key: 'problem_type', label: '问题类型' },
|
||||
{ key: 'root_cause', label: '根因分析' },
|
||||
{ key: 'asked_at', label: '提问时间' },
|
||||
{ key: 'asker', label: '提问人' },
|
||||
{ key: 'question', label: '原始问题' },
|
||||
{ key: 'language', label: '语言' },
|
||||
{ key: 'trigger_person', label: '流程触发人员信息' },
|
||||
{ key: 'department', label: '部门' },
|
||||
{ key: 'region', label: '区域' },
|
||||
{ key: 'feedback', label: '是否点赞' },
|
||||
] as const
|
||||
|
||||
export type QAColumn = (typeof qaColumns)[number]['key']
|
||||
export interface QARecord {
|
||||
id: string
|
||||
status: string
|
||||
question: string
|
||||
answer: string
|
||||
asked_at: string
|
||||
time_source: string
|
||||
asker: string
|
||||
trigger_person: string
|
||||
department: string
|
||||
region: string
|
||||
references: unknown
|
||||
media: unknown
|
||||
source_coverage: { verdict: string; reason_code: string; evaluator_version: string }
|
||||
feedback: { asker_value: string; up: number; down: number }
|
||||
coverage: { state: 'pending' | 'checked'; verdict?: 'uncovered'; rule_version: string; matched_text?: string }
|
||||
question_chinese?: string
|
||||
is_correct?: boolean | null
|
||||
product_category?: string
|
||||
problem_type?: string
|
||||
root_cause?: string
|
||||
language?: string
|
||||
}
|
||||
export interface QARecordPage {
|
||||
items: QARecord[]
|
||||
columns: QAColumn[]
|
||||
total: number
|
||||
has_more: boolean
|
||||
next_cursor: string
|
||||
as_of: string
|
||||
}
|
||||
export interface QAQuery {
|
||||
start: string
|
||||
end: string
|
||||
keyword: string
|
||||
cursor: string
|
||||
limit?: number
|
||||
}
|
||||
export interface QAStatus {
|
||||
state: 'disabled' | 'unavailable' | 'blocked' | 'connected'
|
||||
code: string
|
||||
warnings: string[]
|
||||
read_only: true
|
||||
source_version: '2.0'
|
||||
channel: 'dingtalk'
|
||||
}
|
||||
|
||||
const invalid = (): never => {
|
||||
throw new Error('问答运营响应无效,请联系管理员检查接口契约')
|
||||
}
|
||||
const object = (value: unknown): Record<string, unknown> => {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return invalid()
|
||||
return value as Record<string, unknown>
|
||||
}
|
||||
const text = (value: unknown): string => (typeof value === 'string' ? value : invalid())
|
||||
const count = (value: unknown): number =>
|
||||
typeof value === 'number' && Number.isSafeInteger(value) && value >= 0 ? value : invalid()
|
||||
const instant = (value: unknown): string => {
|
||||
const result = text(value)
|
||||
if (!result || Number.isNaN(Date.parse(result))) return invalid()
|
||||
return result
|
||||
}
|
||||
const columnKeys = new Set<string>(qaColumns.map(({ key }) => key))
|
||||
|
||||
export function parseQARecord(value: unknown): QARecord {
|
||||
const row = object(value)
|
||||
const feedback = object(row.feedback)
|
||||
const source = object(row.source_coverage)
|
||||
const coverage = object(row.coverage)
|
||||
if (coverage.state !== 'pending' && coverage.state !== 'checked') return invalid()
|
||||
if (coverage.verdict !== undefined && coverage.verdict !== 'uncovered') return invalid()
|
||||
if (coverage.state === 'checked' && coverage.verdict !== 'uncovered') return invalid()
|
||||
const askerValue = text(feedback.asker_value)
|
||||
if (!['', 'up', 'down'].includes(askerValue)) return invalid()
|
||||
const item: QARecord = {
|
||||
id: text(row.id),
|
||||
status: text(row.status),
|
||||
question: text(row.question),
|
||||
answer: text(row.answer),
|
||||
asked_at: instant(row.asked_at),
|
||||
time_source: text(row.time_source),
|
||||
asker: text(row.asker),
|
||||
trigger_person: text(row.trigger_person),
|
||||
department: text(row.department),
|
||||
region: text(row.region),
|
||||
references: row.references,
|
||||
media: row.media,
|
||||
source_coverage: {
|
||||
verdict: text(source.verdict),
|
||||
reason_code: text(source.reason_code),
|
||||
evaluator_version: text(source.evaluator_version),
|
||||
},
|
||||
feedback: { asker_value: askerValue, up: count(feedback.up), down: count(feedback.down) },
|
||||
coverage: { state: coverage.state, verdict: coverage.verdict, rule_version: text(coverage.rule_version) },
|
||||
}
|
||||
if (!item.id || !item.coverage.rule_version) return invalid()
|
||||
if (coverage.matched_text !== undefined) item.coverage.matched_text = text(coverage.matched_text)
|
||||
for (const key of ['question_chinese', 'product_category', 'problem_type', 'root_cause', 'language'] as const) {
|
||||
if (row[key] !== undefined) item[key] = text(row[key])
|
||||
}
|
||||
if (row.is_correct !== undefined) {
|
||||
if (typeof row.is_correct !== 'boolean' && row.is_correct !== null) return invalid()
|
||||
item.is_correct = row.is_correct
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
export function parseQARecordPage(value: unknown): QARecordPage {
|
||||
const page = object(value)
|
||||
if (!Array.isArray(page.items) || !Array.isArray(page.columns) || typeof page.has_more !== 'boolean') return invalid()
|
||||
const items = page.items.map(parseQARecord)
|
||||
const columns = page.columns.map((key) =>
|
||||
typeof key === 'string' && columnKeys.has(key) ? (key as QAColumn) : invalid()
|
||||
)
|
||||
const total = count(page.total)
|
||||
const nextCursor = text(page.next_cursor)
|
||||
if (total < items.length || (page.has_more && (!items.length || !nextCursor)) || (!page.has_more && nextCursor))
|
||||
return invalid()
|
||||
if (new Set(items.map(({ id }) => id)).size !== items.length || new Set(columns).size !== columns.length)
|
||||
return invalid()
|
||||
return { items, columns, total, has_more: page.has_more, next_cursor: nextCursor, as_of: instant(page.as_of) }
|
||||
}
|
||||
|
||||
async function getPayload(path: string, signal?: AbortSignal): Promise<unknown> {
|
||||
const response = await fetch(path, { credentials: 'same-origin', cache: 'no-store', signal })
|
||||
const raw: unknown = await response.json().catch(() => null)
|
||||
if (!response.ok) {
|
||||
const payload = raw && typeof raw === 'object' ? (raw as Record<string, unknown>) : null
|
||||
throw new Error(typeof payload?.error === 'string' ? payload.error : `问答数据读取失败(HTTP ${response.status})`)
|
||||
}
|
||||
return object(raw).data
|
||||
}
|
||||
|
||||
export async function fetchQARecords(query: QAQuery, signal?: AbortSignal): Promise<QARecordPage> {
|
||||
const parameters = new URLSearchParams({
|
||||
start: query.start,
|
||||
end: query.end,
|
||||
keyword: query.keyword,
|
||||
cursor: query.cursor,
|
||||
limit: String(query.limit ?? 20),
|
||||
})
|
||||
return parseQARecordPage(await getPayload(`/api/v1/qa-ops/records?${parameters}`, signal))
|
||||
}
|
||||
export async function fetchQARecord(id: string, signal?: AbortSignal): Promise<QARecord> {
|
||||
return parseQARecord(await getPayload(`/api/v1/qa-ops/records/${encodeURIComponent(id)}`, signal))
|
||||
}
|
||||
export async function fetchQAStatus(signal?: AbortSignal): Promise<QAStatus> {
|
||||
const value = object(await getPayload('/api/v1/qa-ops/status', signal))
|
||||
if (
|
||||
!['disabled', 'unavailable', 'blocked', 'connected'].includes(text(value.state)) ||
|
||||
!Array.isArray(value.warnings) ||
|
||||
value.read_only !== true ||
|
||||
value.source_version !== '2.0' ||
|
||||
value.channel !== 'dingtalk'
|
||||
)
|
||||
return invalid()
|
||||
return {
|
||||
state: value.state as QAStatus['state'],
|
||||
code: text(value.code),
|
||||
warnings: value.warnings.map(text),
|
||||
read_only: true,
|
||||
source_version: '2.0',
|
||||
channel: 'dingtalk',
|
||||
}
|
||||
}
|
||||
|
||||
export function qaCellValue(item: QARecord, column: QAColumn): string | null {
|
||||
if (column === 'coverage') return item.coverage.verdict === 'uncovered' ? '否' : null
|
||||
if (column === 'is_correct') return typeof item.is_correct === 'boolean' ? (item.is_correct ? '是' : '否') : null
|
||||
if (column === 'feedback') {
|
||||
if (item.feedback.asker_value === 'up') return '是'
|
||||
if (item.feedback.asker_value === 'down') return '否(点踩)'
|
||||
if (item.feedback.up || item.feedback.down) return `其他人:赞 ${item.feedback.up} / 踩 ${item.feedback.down}`
|
||||
return null
|
||||
}
|
||||
if (column === 'asked_at') return new Date(item.asked_at).toLocaleString('zh-CN', { hour12: false })
|
||||
return item[column] || null
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
export type ModuleId = 'dashboard' | 'sources' | 'knowledge' | 'tasks' | 'releases' | 'settings' | 'versions'
|
||||
export type ModuleId = 'dashboard' | 'sources' | 'knowledge' | 'tasks' | 'releases' | 'settings' | 'versions' | 'qaops'
|
||||
|
||||
export interface WorkspaceState {
|
||||
openTabs: ModuleId[]
|
||||
activeTab: ModuleId
|
||||
}
|
||||
|
||||
const moduleIds = new Set<ModuleId>(['dashboard', 'tasks', 'releases', 'settings'])
|
||||
const moduleIds = new Set<ModuleId>(['dashboard', 'tasks', 'releases', 'settings', 'qaops'])
|
||||
|
||||
export const initialWorkspace: WorkspaceState = {
|
||||
openTabs: ['dashboard'],
|
||||
|
||||
Reference in New Issue
Block a user