test: harden AI analysis path
This commit is contained in:
@@ -181,12 +181,18 @@ export function ElderAiAnalysisDialog({ elder, onClose, open }: ElderAiAnalysisD
|
||||
</Card>
|
||||
) : latest ? (
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>最新记录</CardTitle>
|
||||
<CardDescription>{formatDateTime(latest.createdAt)}</CardDescription>
|
||||
<CardHeader className="gap-2">
|
||||
<div className="flex items-center justify-between gap-2">
|
||||
<div>
|
||||
<CardTitle>最新记录</CardTitle>
|
||||
<CardDescription>{formatDateTime(latest.createdAt)}</CardDescription>
|
||||
</div>
|
||||
<Badge variant={latest.status === "failed" ? "destructive" : "secondary"}>{latest.status === "failed" ? "生成失败" : "受限"}</Badge>
|
||||
</div>
|
||||
</CardHeader>
|
||||
<CardContent className="text-sm text-muted-foreground">
|
||||
{latest.restricted ? "当前角色缺少该分析所使用数据范围的读取权限。" : latest.errorReason ?? "暂无可展示分析。"}
|
||||
<CardContent className="grid gap-2 text-sm text-muted-foreground">
|
||||
<p>{latest.restricted ? "当前角色缺少该分析所使用数据范围的读取权限。" : latest.errorReason ?? "暂无可展示分析。"}</p>
|
||||
{latest.status === "failed" ? <p>失败记录仅保存脱敏原因,不包含提示词、住民上下文或供应商原始错误。</p> : null}
|
||||
</CardContent>
|
||||
</Card>
|
||||
) : (
|
||||
|
||||
@@ -66,6 +66,13 @@ function matchesEntry(entry: KnowledgeEntry, query: string): boolean {
|
||||
return [entry.title, entry.category, entry.tags, entry.body].join(" ").toLowerCase().includes(normalized);
|
||||
}
|
||||
|
||||
function formatKnowledgeFailureReason(reason: string): string {
|
||||
if (reason.includes("AI_API_KEY") || reason.includes("向量生成失败")) {
|
||||
return `保存知识需要可用的 AI 向量配置:${reason}`;
|
||||
}
|
||||
return reason;
|
||||
}
|
||||
|
||||
export function KnowledgeManagementClient({ initialEntries, permissions }: KnowledgeManagementClientProps): React.ReactElement {
|
||||
const [entries, setEntries] = useState(initialEntries);
|
||||
const [query, setQuery] = useState("");
|
||||
@@ -135,7 +142,7 @@ export function KnowledgeManagementClient({ initialEntries, permissions }: Knowl
|
||||
const result = (await response.json()) as ApiResult<{ entry: KnowledgeEntry }>;
|
||||
setIsPending(false);
|
||||
if (!result.success) {
|
||||
setMessage(result.reason);
|
||||
setMessage(formatKnowledgeFailureReason(result.reason));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -173,7 +180,7 @@ export function KnowledgeManagementClient({ initialEntries, permissions }: Knowl
|
||||
});
|
||||
const result = (await response.json()) as ApiResult<{ entry: KnowledgeEntry }>;
|
||||
if (!result.success) {
|
||||
setMessage(result.reason);
|
||||
setMessage(formatKnowledgeFailureReason(result.reason));
|
||||
return;
|
||||
}
|
||||
await refreshEntries();
|
||||
|
||||
Reference in New Issue
Block a user