feat(branch-statement-button): 增加前端显示时在检索失败分支语句结尾处添加一个按钮。按钮名为【知识库内容清单】
This commit is contained in:
1 parent
6c47d0639c
commit
e421d2607d
18 files changed
+344
-4
No files matched your search
@@ -5,12 +5,19 @@
|
||||
* 逻辑:由 ChatMessageList 按消息逐条挂载;货代履约写按钮不在气泡内渲染,仅展示只读卡与深链通知。
|
||||
* 用户附件区支持 summaryOnly:下方已有抽取进度卡时只显示附件摘要。
|
||||
* 兼容:同时承接采购合同审查、库存映射、订单提取和 Mermaid 展示。
|
||||
* 知识库未命中兜底回复按原始 content 检测触发标记,在正文下方渲染【知识库内容清单】按钮,
|
||||
* 点击后弹窗展示常用问题「能力清单条目」标准答案。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onMounted, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Check, Copy, Download, Edit2, Eye, LayoutGrid, MessageSquareText, RotateCw, X } from 'lucide-vue-next';
|
||||
import { BookOpen, Check, Copy, Download, Edit2, Eye, LayoutGrid, MessageSquareText, RotateCw, X } from 'lucide-vue-next';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import { useChatStore } from '../../stores/chat.store';
|
||||
import { getAgentCapabilityList } from '../../api/chat.api';
|
||||
import { hasCapabilityListTrigger } from '../../utils/capabilityList';
|
||||
import type { ChatCapabilityListEntry } from '../../types/chat.types';
|
||||
import LeaveMessageBlock, { type LeaveMessageHandlers } from './LeaveMessageBlock.vue';
|
||||
import ChatMessageAttachmentList from './ChatMessageAttachmentList.vue';
|
||||
import MaintenanceDeviceResultCard from './MaintenanceDeviceResultCard.vue';
|
||||
@@ -214,6 +221,45 @@ watch(renderedMarkdown, () => { void renderMermaidCharts(); });
|
||||
const inlineDownloadFiles = computed(() => (
|
||||
message.role === 'assistant' ? handlers.getInlineDownloadFiles(message.content).files : []
|
||||
));
|
||||
|
||||
// [知识库内容清单]:触发检测基于原始 content(标记剥离只发生在展示文本层),历史会话同样生效。
|
||||
const chatStore = useChatStore();
|
||||
const { error: showCapabilityError } = useMessage();
|
||||
const capabilityListButtonVisible = computed(() => (
|
||||
message.role === 'assistant' && hasCapabilityListTrigger(message.content)
|
||||
));
|
||||
const capabilityListLoading = ref(false);
|
||||
const capabilityListEntry = ref<ChatCapabilityListEntry | null>(null);
|
||||
|
||||
/**
|
||||
* 拉取并打开知识库内容清单弹窗。
|
||||
* AI 触发时机:知识库未命中兜底回复正文下方的【知识库内容清单】按钮被点击时调用。
|
||||
* 核心逻辑:按当前会话应用(chatStore.currentAgentId)请求常用问题「能力清单条目」标准答案,
|
||||
* 成功后以弹窗展示;失败时优先复用 requestJson 抛出 BusinessError 的错误码本地化文案。
|
||||
* 参数约束:agentId 一律取自路由级 chat store,组件不接收外部传入的应用 ID,禁止跨应用查询。
|
||||
*/
|
||||
async function openCapabilityListDialog(): Promise<void> {
|
||||
if (capabilityListLoading.value) return;
|
||||
const agentId = Number(chatStore.currentAgentId || 0);
|
||||
if (!agentId) {
|
||||
showCapabilityError(t('chat.capabilityList.notFound'));
|
||||
return;
|
||||
}
|
||||
capabilityListLoading.value = true;
|
||||
try {
|
||||
capabilityListEntry.value = await getAgentCapabilityList(agentId);
|
||||
} catch (error) {
|
||||
showCapabilityError(error instanceof Error ? error.message : t('chat.capabilityList.notFound'));
|
||||
} finally {
|
||||
capabilityListLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
/** 关闭知识库内容清单弹窗并清空条目,避免下次打开闪现旧内容。 */
|
||||
function closeCapabilityListDialog(): void {
|
||||
capabilityListEntry.value = null;
|
||||
}
|
||||
|
||||
const shippingParseReviewHandlers = computed<ShippingParseReviewHandlers>(() => ({
|
||||
getPayload: shippingHandlers.getParseReviewPayload,
|
||||
updateHeader: shippingHandlers.updateHeader,
|
||||
@@ -863,6 +909,18 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-if="capabilityListButtonVisible" class="mt-4">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center gap-2 rounded-xl border border-brand-200 bg-brand-50 px-3 py-2 text-xs font-medium text-brand-700 transition hover:bg-brand-100 disabled:cursor-not-allowed disabled:opacity-60"
|
||||
:disabled="capabilityListLoading"
|
||||
@click="openCapabilityListDialog"
|
||||
>
|
||||
<BookOpen class="h-3.5 w-3.5" />
|
||||
{{ $t('chat.capabilityList.button') }}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1133,6 +1191,31 @@ function handleInlineDownload(file: InlineDownloadFile): void {
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
<Teleport to="body">
|
||||
<div
|
||||
v-if="capabilityListEntry"
|
||||
class="dialog-overlay z-[130] items-center"
|
||||
@click.self="closeCapabilityListDialog"
|
||||
>
|
||||
<div class="dialog-panel flex max-h-[88vh] w-[min(96vw,760px)] flex-col">
|
||||
<div class="dialog-header">
|
||||
<div>
|
||||
<h3 class="section-title">{{ $t('chat.capabilityList.dialogTitle') }}</h3>
|
||||
<p class="section-desc mt-1">{{ capabilityListEntry.title }}</p>
|
||||
</div>
|
||||
<button type="button" class="btn-icon-ds" :aria-label="$t('common.close')" @click="closeCapabilityListDialog">
|
||||
<X class="h-5 w-5" />
|
||||
</button>
|
||||
</div>
|
||||
<div class="dialog-body min-h-0 flex-1 overflow-auto border-t-0 pt-4">
|
||||
<div
|
||||
class="markdown-body chat-markdown min-w-0 break-words text-sm leading-relaxed"
|
||||
v-html="handlers.renderMarkdown(capabilityListEntry.answer)"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
Reference in new issue
Block a user