初步完成ai插件对接

This commit is contained in:
2026-08-26 22:10:04 +08:00
parent 26192167f3
commit f5176ada20
13 changed files with 4367 additions and 3540 deletions
+23 -3
View File
@@ -3,6 +3,7 @@ import { ref, computed } from 'vue';
import { useAppStore } from '@/store/modules/app';
import { Icon } from '@iconify/vue'
import { useThemeStore } from '@/store/modules/theme';
import { aiKnowledgeIngest, pollTask, AiError } from '@/service/api/ai';
const appStore = useAppStore();
const themeStore = useThemeStore();
@@ -29,8 +30,26 @@ const preview = (d:any) => {
const download = (d:any) => {
window.$message?.success(`演示:下载 ${d.name}`)
}
const call = (d:any) => {
window.$message?.success(`演示:已将「${d.name}」调用为当前变更的 AI 知识来源(调用记录留痕)`)
// 已纳入 AI 知识库的条目(name -> true)与摄入中状态
const ingested = ref<Record<string, boolean>>({});
const ingesting = ref<Record<string, boolean>>({});
const call = async (d:any) => {
if (ingesting.value[d.name] || ingested.value[d.name]) return;
ingesting.value[d.name] = true;
try {
const { task_id } = await aiKnowledgeIngest({ name: d.name, version: d.ver, category: d.cat });
await pollTask(task_id, {});
ingested.value[d.name] = true;
window.$message?.success(`已将「${d.name}」纳入 AI 知识库(调用记录留痕)`);
} catch (e: any) {
if (e instanceof AiError) {
window.$message?.warning(`AI 知识摄入失败:${e.message},可稍后重试`);
} else {
window.$message?.warning('AI 知识摄入失败,可稍后重试');
}
} finally {
ingesting.value[d.name] = false;
}
}
interface LibDoc { name: string; ver: string; date: string }
interface LibFolder { label: string; docs: LibDoc[] }
@@ -210,7 +229,8 @@ const libCur = computed(() => LIB_ORGS.find((o) => o.org === libSel.value.org)?.
<div class="flex shrink-0 gap-3 text-xs">
<NButton type="primary" text class="hover:underline text-xs" @click="preview(d)">查看</NButton>
<NButton type="primary" text class="hover:underline text-xs" @click="download(d)">下载</NButton>
<NButton type="primary" text class="hover:underline text-xs" @click="call(d)">调用</NButton>
<NTag v-if="ingested[d.name]" size="small" type="success" class="text-[10px]">已纳入 AI 知识库</NTag>
<NButton v-else type="primary" text class="hover:underline text-xs" :loading="!!ingesting[d.name]" @click="call(d)">调用</NButton>
</div>
</div>
</div>