refactor: remove legacy session recovery UI
This commit is contained in:
@@ -100,15 +100,15 @@ function CitationCards({ items }: { items: any[] }) {
|
||||
{safeUrl(item.image_url) && <a href={safeUrl(item.image_url)} target="_blank" rel="noopener noreferrer">查看图像</a>}</Space></div>;
|
||||
})}</div>;
|
||||
}
|
||||
function Citations({ items, messageId }: { items: any[]; messageId: number }) {
|
||||
function Citations({ items }: { items: any[] }) {
|
||||
const seen = new Set<string>();
|
||||
const unique = (items || []).filter(item => { if (!item || typeof item !== 'object') return false;
|
||||
const key = JSON.stringify([item.title || item.document, item.page, item.quote, item.url, item.image_url]);
|
||||
if (seen.has(key)) return false; seen.add(key); return true; });
|
||||
if (!unique.length) return null;
|
||||
return <section className="chat-citations" aria-label="引用资料"><details id={`citations-${messageId}`} className="chat-citation-group"><summary><Text strong>引用 · {unique.length}</Text></summary><CitationCards items={unique} /></details></section>;
|
||||
return <section className="chat-citations" aria-label="引用资料"><details className="chat-citation-group"><summary><Text strong>引用 · {unique.length}</Text></summary><CitationCards items={unique} /></details></section>;
|
||||
}
|
||||
function Tools({ calls, messageId, legacyEvidence = [] }: { calls: any[]; messageId?: number; legacyEvidence?: any[] }) {
|
||||
function Tools({ calls }: { calls: any[] }) {
|
||||
if (!calls?.length) return null;
|
||||
const active = calls.filter(call => call.status === 'running').length;
|
||||
const failed = calls.filter(call => call.status === 'failed').length;
|
||||
@@ -118,10 +118,7 @@ function Tools({ calls, messageId, legacyEvidence = [] }: { calls: any[]; messag
|
||||
<Tag color={statusColor(call.status || 'completed')}>{call.status === 'running' ? '进行中' : call.status === 'failed' ? '失败' : '成功'}</Tag>
|
||||
<Text type="secondary">{call.status === 'running' ? '正在执行' : call.error ? String(call.error).slice(0, 80) : call.summary || (typeof call.result === 'string' ? call.result : '已完成')}</Text></Space></summary>
|
||||
<div className="tool-detail"><Text strong>调用参数</Text><pre>{JSON.stringify(call.arguments || {}, null, 2)}</pre>
|
||||
<Text strong>{call.error ? '错误' : '调用结果'}</Text><pre>{call.error || (typeof call.result === 'string' ? call.result : JSON.stringify(call.result ?? '运行中', null, 2))}</pre>
|
||||
{call.result?.citations?.count !== undefined && <div><Text type="secondary">旧运行只保存了引用数量,无法还原各次检索对应的原文。</Text>{messageId && <Button type="link" size="small" onClick={() => { const target = document.getElementById(`citations-${messageId}`) as HTMLDetailsElement | null; if (target) { target.open = true; target.scrollIntoView({ behavior: 'smooth', block: 'nearest' }); } }}>查看本轮已核验原文</Button>}
|
||||
{legacyEvidence.length > 0 && <div className="legacy-evidence"><Text strong>本轮回答已核验的相关原文(无法确认属于当前这一次检索)</Text><CitationCards items={legacyEvidence} /></div>}</div>}
|
||||
{call.result?.truncated && <Text type="secondary">旧运行的原始结果未保存。{call.result?.rechecked_current ? '附带的是当前数据库重查结果,不代表当时模型看到的内容。' : '再次提问可使用分页评分查询。'}</Text>}</div>
|
||||
<Text strong>{call.error ? '错误' : '调用结果'}</Text><pre>{call.error || (typeof call.result === 'string' ? call.result : JSON.stringify(call.result ?? '运行中', null, 2))}</pre></div>
|
||||
</details>)}</div></details></section>;
|
||||
}
|
||||
export default function Chat() {
|
||||
@@ -229,7 +226,7 @@ export default function Chat() {
|
||||
<Select aria-label="学生项目" allowClear disabled={locked || scopeSaving || running} placeholder="学生项目(可选)" value={currentScope.project_id} options={projects.filter(p => (!currentScope.course_version_id || p.course_version_id === currentScope.course_version_id) && (!currentScope.batch_id || !batches.find(b => b.id === currentScope.batch_id)?.project_ids || batches.find(b => b.id === currentScope.batch_id).project_ids.includes(p.id))).map(p => ({ value: p.id, label: `${p.student_no} ${p.name}` }))} onChange={changeProject} /></div>
|
||||
{locked && <Text type="secondary">首条消息已提交,课程版本、批次和学生项目范围不可修改。</Text>}
|
||||
</Card><div className="chat-messages">{detail?.messages?.map((item: any) => <Card key={item.id} size="small" className={`chat-message chat-${item.role}`} title={item.role === 'user' ? '教师' : '智评'}>
|
||||
{item.role === 'assistant' ? <><Tools calls={item.tool_calls} messageId={item.id} legacyEvidence={(item.citations || []).filter((source: any) => source.chunk_id)} /><Answer text={item.content} /><Citations items={item.citations} messageId={item.id} /></> : <Paragraph className="chat-content">{item.content}</Paragraph>}
|
||||
{item.role === 'assistant' ? <><Tools calls={item.tool_calls} /><Answer text={item.content} /><Citations items={item.citations} /></> : <Paragraph className="chat-content">{item.content}</Paragraph>}
|
||||
</Card>)}
|
||||
{detail?.runs?.filter((run: any) => run.status !== 'completed' && (run.tool_calls?.length || run.error || run.status === 'running')).map((run: any) => <Card key={`run-${run.id}`} size="small" className="chat-message chat-assistant" title={<Space>智评 <Tag color={statusColor(run.status)}>{run.status === 'running' ? '生成中' : run.status === 'failed' ? '失败' : '已中断'}</Tag></Space>}>
|
||||
<Tools calls={run.tool_calls} />{run.error && <Alert type="error" message={run.error} />}</Card>)}
|
||||
|
||||
@@ -55,8 +55,6 @@ body { margin: 0; }
|
||||
.citation-heading { display: flex; flex-wrap: wrap; align-items: baseline; gap: 6px; }
|
||||
.citation-card p { margin: 5px 0; color: #44566d; white-space: pre-wrap; }
|
||||
.citation-card summary { cursor: pointer; color: #44566d; overflow-wrap: anywhere; }
|
||||
.legacy-evidence { margin-top: 10px; }
|
||||
.legacy-evidence .citation-grid { max-height: 300px; overflow-y: auto; }
|
||||
.chat-tools { margin-bottom: 12px; padding-bottom: 6px; border-bottom: 1px solid #e2eaf3; }
|
||||
.chat-tool { border: 1px solid #e2e8ef; border-radius: 6px; margin-top: 5px; padding: 6px 9px; }
|
||||
.chat-tool summary { cursor: pointer; list-style-position: inside; overflow-wrap: anywhere; }
|
||||
|
||||
Reference in New Issue
Block a user