fix: 优化一些配置

This commit is contained in:
sophie committed 2026-07-30 16:49:27 +08:00
1 parent ac7b53a523
commit eb21af5949
17 files changed
+117 -208

No files matched your search

@@ -1,16 +1,15 @@
/**
* features/chat/composables/useChatAgent.ts
* 当前 Agent 元数据、知识库选项、推荐问题与用户可切换 Agent 列表。
* 当前 Agent 元数据、发送时默认知识库类型、推荐问题与用户可切换 Agent 列表。
* 依赖:user API、agent-registry / agent-category utils、training 题库工具、ChatDeps。
* 逻辑:Chat 页面通过 useChatPage 调用;selectedKb 固定为企业知识库供发消息透传,输入栏不再展示知识库下拉。
*/
import { computed, ref, watch, type ComputedRef } from 'vue';
import { computed, ref, type ComputedRef } from 'vue';
import { BusinessError } from '@/shared/api/client';
import { getUserAgent, listUserAgents } from '@/features/user';
import { setLastChatAgentId } from '@/shared/utils/lastChatAgent';
import { sortAgentsByCategory } from '@/shared/utils/agent-category.utils';
import {
agentHasErpKb,
type AgentRegistryFields,
} from '@/shared/utils/agent-registry.utils';
import type { AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
import { matchesTrainingAgent } from '../training/trainingWorkspace.utils';
import { resolveTrainingRoleChatQuestions } from '../training/trainingChatQuestions';
import type { ChatDeps } from './chat.deps';
@@ -21,8 +20,8 @@ export type AgentSuggestedQuestionItem = {
group: string;
};
/** 发消息时透传给后端的默认 kb_type;聊天输入栏已不再提供切换入口 */
const DEFAULT_KB = '企业知识库';
const ERP_KB = 'ERP知识库';
const normalizeAgentSuggestedQuestions = (value: unknown): AgentSuggestedQuestionItem[] => {
if (!Array.isArray(value)) return [];
@@ -77,36 +76,11 @@ export function useChatAgent(options: UseChatAgentOptions) {
const userAgents = ref<ChatAgentOption[]>([]);
const showAgentPanel = ref(true);
const selectedKb = ref(DEFAULT_KB);
const kbOptions = [DEFAULT_KB, ERP_KB];
const getKbLabel = (kb: string) => {
if (kb === DEFAULT_KB) return t('chat.kb.enterprise');
if (kb === ERP_KB) return t('chat.kb.erp');
return kb;
};
const canSelectErpKnowledgeBase = computed(() => agentHasErpKb(currentAgent.value));
const availableKbOptions = computed(() => (
canSelectErpKnowledgeBase.value
? kbOptions
: kbOptions.filter((option) => option !== ERP_KB)
));
const kbDropdownDisabled = computed(() => availableKbOptions.value.length <= 1);
const isTrainingAdminViewer = computed(() => Boolean(
(currentUser.value as { feature_permissions?: { training_hr_manage?: boolean } } | null)
?.feature_permissions?.training_hr_manage,
));
watch(canSelectErpKnowledgeBase, (allowed) => {
if (allowed) {
selectedKb.value = DEFAULT_KB;
return;
}
if (selectedKb.value === ERP_KB) {
selectedKb.value = DEFAULT_KB;
}
}, { immediate: true });
const agentDescription = computed(() => {
const welcome = String(currentAgent.value?.welcome_message || '').trim();
if (welcome) return welcome;
@@ -200,9 +174,6 @@ export function useChatAgent(options: UseChatAgentOptions) {
userAgents,
showAgentPanel,
selectedKb,
getKbLabel,
availableKbOptions,
kbDropdownDisabled,
agentDescription,
suggestedQuestionsStyle,
agentSuggestedQuestions,