mirror of
https://github.com/Ed1s0nZ/CyberStrikeAI.git
synced 2026-10-20 14:37:20 +02:00
fix: retain knowledge indexing errors and explain failure causes
This commit is contained in:
1 parent
bb96a084e0
commit
5dc9cb1541
7 files changed
+94
-11
No files matched your search
@@ -0,0 +1,15 @@
|
||||
const fs=require('node:fs'),vm=require('node:vm'),test=require('node:test'),assert=require('node:assert/strict');
|
||||
const source=fs.readFileSync('web/static/js/knowledge.js','utf8');
|
||||
const c=vm.createContext({});vm.runInContext(source.slice(0,source.indexOf('\n\n',source.indexOf('return \'请根据'))+2),c);
|
||||
test('embedding failures give the matching configuration or service advice',()=>{
|
||||
for(const [error,expected] of [['status code: 401 Incorrect API key provided','API 密钥'],['403 Forbidden','访问权限'],['429 rate limit','请求频率'],['context deadline exceeded','超时'],['dial: no such host','DNS'],['unknown error','上方错误']]) assert.ok(c.knowledgeIndexErrorAdvice(error).includes(expected));
|
||||
});
|
||||
|
||||
test('actual status renderer shows specific advice even with zero items',async()=>{
|
||||
const container={style:{},innerHTML:''};
|
||||
const ctx=vm.createContext({apiFetch:async()=>({ok:true,json:async()=>({total_items:0,last_error:'401 Unauthorized test-only failure'})}),document:{getElementById:()=>container},escapeHtml:s=>s,indexProgressInterval:null,clearInterval(){},showNotification(){},console});
|
||||
vm.runInContext(source.slice(0,source.indexOf('\n\n',source.indexOf('return \'请根据'))+2),ctx);
|
||||
vm.runInContext(source.slice(source.indexOf('async function updateIndexProgress('),source.indexOf('function stopIndexProgressPolling(')),ctx);
|
||||
await ctx.updateIndexProgress();
|
||||
assert.equal(container.style.display,'block');assert.match(container.innerHTML,/API 密钥/);assert.match(container.innerHTML,/401 Unauthorized/);
|
||||
});
|
||||
@@ -1,3 +1,13 @@
|
||||
function knowledgeIndexErrorAdvice(error) {
|
||||
const text = String(error || '');
|
||||
if (/\b401\b|incorrect api key|invalid api key|unauthorized/i.test(text)) return '嵌入服务拒绝认证。请检查知识库嵌入配置的 API 密钥及服务地址,保存后重试。';
|
||||
if (/\b403\b|forbidden/i.test(text)) return '嵌入服务拒绝访问。请检查账号权限及所选嵌入模型的访问权限。';
|
||||
if (/\b429\b|rate limit|quota/i.test(text)) return '嵌入服务限制请求。请检查请求频率及账号可用额度,稍后重试。';
|
||||
if (/timeout|deadline exceeded/i.test(text)) return '嵌入服务请求超时。请检查服务可用性、网络和代理配置后重试。';
|
||||
if (/connection refused|no such host|network is unreachable/i.test(text)) return '无法连接嵌入服务。请检查服务地址、DNS、网络和代理配置。';
|
||||
return '请根据上方错误检查嵌入模型和服务配置,修正后重试。';
|
||||
}
|
||||
|
||||
// 知识库管理相关功能
|
||||
function _t(key, opts) {
|
||||
return typeof window.t === 'function' ? window.t(key, opts) : key;
|
||||
@@ -464,7 +474,7 @@ async function updateIndexProgress() {
|
||||
// 检查是否正在重建索引(优先使用重建状态)
|
||||
const isRebuilding = status.is_rebuilding || false;
|
||||
|
||||
if (totalItems === 0) {
|
||||
if (totalItems === 0 && !lastError) {
|
||||
// 没有知识项,隐藏进度条
|
||||
progressContainer.style.display = 'none';
|
||||
if (indexProgressInterval) {
|
||||
@@ -495,7 +505,7 @@ async function updateIndexProgress() {
|
||||
${escapeHtml(lastError)}
|
||||
</div>
|
||||
<div style="color: #999; font-size: 12px; margin-bottom: 12px;">
|
||||
可能的原因:嵌入模型配置错误、API密钥无效、余额不足等。请检查配置后重试。
|
||||
${escapeHtml(knowledgeIndexErrorAdvice(lastError))}
|
||||
</div>
|
||||
<div style="display: flex; gap: 8px; flex-wrap: wrap;">
|
||||
<button onclick="buildKnowledgeIndex()" style="
|
||||
|
||||
Reference in new issue
Block a user