refactor(backend): 重构后端代码 wave 3

This commit is contained in:
sophie committed 2026-07-29 19:12:49 +08:00
1 parent affe139bf9
commit 8415653365
97 files changed
+4673 -6164

No files matched your search

@@ -4,7 +4,7 @@
*/
import { computed, ref, watch, type ComputedRef } from 'vue';
import { BusinessError } from '@/shared/api/client';
import { getUserAgent, listUserAgents } from '@/features/auth/api/user.api';
import { getUserAgent, listUserAgents } from '@/features/user';
import { setLastChatAgentId } from '@/shared/utils/lastChatAgent';
import { sortAgentsByCategory } from '@/shared/utils/agent-category.utils';
import {
@@ -51,31 +51,33 @@ export interface UseChatAgentOptions {
chatGuides: Pick<UseChatGuidesReturn, 'loadGuides' | 'clearGuides'>;
}
type ChatAgentOption = AgentRegistryFields & {
id: number;
name: string;
description: string;
icon_url?: string;
dify_app_type?: 'chatflow' | 'workflow';
category?: string | null;
sub_category?: string | null;
sort_order?: number;
is_aggregate?: boolean;
directory_members?: Array<AgentRegistryFields & {
id: number;
name: string;
description?: string | null;
icon_url?: string;
category?: string | null;
sub_category?: string | null;
sort_order?: number;
}>;
};
export function useChatAgent(options: UseChatAgentOptions) {
const { deps, currentAgentId, currentUser, chatGuides } = options;
const { t, msg, router } = deps;
const currentAgent = ref<AgentRegistryFields | null>(null);
const userAgents = ref<Array<AgentRegistryFields & {
id: number;
name: string;
description: string;
icon_url?: string;
dify_app_type?: 'chatflow' | 'workflow';
category?: string | null;
sub_category?: string | null;
sort_order?: number;
is_aggregate?: boolean;
directory_members?: Array<AgentRegistryFields & {
id: number;
name: string;
description?: string | null;
icon_url?: string;
category?: string | null;
sub_category?: string | null;
sort_order?: number;
}>;
}>>([]);
const userAgents = ref<ChatAgentOption[]>([]);
const showAgentPanel = ref(true);
const selectedKb = ref(DEFAULT_KB);
const kbOptions = [DEFAULT_KB, ERP_KB];
@@ -162,7 +164,7 @@ export function useChatAgent(options: UseChatAgentOptions) {
const loadAgent = async () => {
try {
currentAgent.value = await getUserAgent(currentAgentId.value);
currentAgent.value = await getUserAgent<AgentRegistryFields>(currentAgentId.value);
await chatGuides.loadGuides();
} catch (e) {
if (e instanceof BusinessError && e.status === 403) {
@@ -178,9 +180,9 @@ export function useChatAgent(options: UseChatAgentOptions) {
const loadUserAgents = async () => {
try {
const agents = await listUserAgents();
const agents = await listUserAgents<ChatAgentOption>();
const filtered = Array.isArray(agents)
? agents.filter((a: any) => (a.dify_app_type || 'chatflow') === 'chatflow')
? agents.filter((agent) => (agent.dify_app_type || 'chatflow') === 'chatflow')
: [];
userAgents.value = sortAgentsByCategory(filtered);
showAgentPanel.value = userAgents.value.length > 0;
@@ -3,7 +3,7 @@
* Agent 学习之窗:指南列表加载与弹窗状态。
*/
import { computed, ref, type ComputedRef } from 'vue';
import { listAgentGuides } from '@/features/auth/api/user.api';
import { listAgentGuides } from '@/features/user';
export interface AgentGuide {
id: number;
@@ -8,7 +8,7 @@
* - leave-result:OA 提交结果
*/
import { computed, type ComputedRef, type Ref } from 'vue';
import { getUserProfile } from '@/features/auth/api/user.api';
import { getUserProfile } from '@/features/user';
import { canUseLeaveFeature as resolveLeaveFeatureEnabled } from '@/shared/utils/agent-registry.utils';
import type { AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
import { LEAVE_TYPES } from '../constants/leave';