test: harden AI analysis path
This commit is contained in:
@@ -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