Merge branch 'dev' into hugo-shipping-notice

This commit is contained in:
hugo committed 2026-06-26 22:08:58 +08:00
commit d6af566601
91 files changed
+3869 -3097

No files matched your search

@@ -5,11 +5,10 @@
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { BookOpen, History, LayoutGrid } from 'lucide-vue-next';
import AgentCategoryList from '@/shared/components/AgentCategoryList.vue';
import type { AgentWithCategory } from '@/shared/utils/agent-category.utils';
export interface ChatMobileHeaderAgent {
id: number;
name: string;
}
export interface ChatMobileHeaderAgent extends AgentWithCategory {}
defineProps<{
agentName: string;
@@ -99,21 +98,12 @@ onBeforeUnmount(() => {
class="absolute right-4 top-12 z-50 w-72 rounded-2xl border border-default bg-surface p-3 shadow-xl"
>
<div class="mb-2 text-xs font-medium text-muted">{{ $t('chat.agents') }}</div>
<div class="grid grid-cols-2 gap-2">
<button
v-for="agent in userAgents"
:key="agent.id"
type="button"
class="flex flex-col items-center gap-1.5 rounded-xl px-2 py-3 text-center transition-colors hover-surface-soft"
@click="onSwitchAgent(agent)"
>
<div class="flex h-9 w-9 items-center justify-center rounded-lg bg-brand-50 text-sm font-bold text-brand-600">
{{ agent.name.charAt(0) }}
</div>
<span class="w-full truncate text-xs font-medium text-secondary">{{ agent.name }}</span>
</button>
</div>
<div v-if="userAgents.length === 0" class="py-3 text-center text-xs text-muted">{{ $t('chat.noOtherAgents') }}</div>
<AgentCategoryList
v-if="userAgents.length > 0"
:agents="userAgents"
@select="onSwitchAgent"
/>
<div v-else class="py-3 text-center text-xs text-muted">{{ $t('chat.noOtherAgents') }}</div>
</div>
</header>
</template>
@@ -20,13 +20,11 @@ import {
X,
} from 'lucide-vue-next';
import LocaleToggleButton from '@/shared/components/LocaleToggleButton.vue';
import AgentCategoryList from '@/shared/components/AgentCategoryList.vue';
import type { AgentWithCategory } from '@/shared/utils/agent-category.utils';
import type { DisplayHistoryItem } from '../types/chat.types';
export interface ChatSidebarAgent {
id: number;
name: string;
icon_url?: string;
}
export interface ChatSidebarAgent extends AgentWithCategory {}
const collapsed = defineModel<boolean>('collapsed', { required: true });
const agentPanelOpen = defineModel<boolean>('agentPanelOpen', { required: true });
@@ -227,29 +225,26 @@ const userInitial = (fallback: string) => {
</div>
<div class="mt-auto flex flex-col p-4">
<div v-if="userAgents.length > 0 && agentPanelOpen" class="chat-agent-panel">
<div class="mb-2 flex items-center gap-1.5 text-xs font-semibold text-muted">
<LayoutGrid class="h-3.5 w-3.5" /> {{ $t('chat.agents') }}
</div>
<div class="grid grid-cols-2 gap-x-2 gap-y-1.5">
<div v-if="userAgents.length > 0" class="chat-agent-panel">
<div class="mb-2 flex items-center justify-between gap-2">
<div class="flex items-center gap-1.5 text-xs font-semibold text-muted">
<LayoutGrid class="h-3.5 w-3.5" /> {{ $t('chat.agents') }}
<span class="font-normal opacity-70">({{ userAgents.length }})</span>
</div>
<button
v-for="agent in userAgents"
:key="agent.id"
type="button"
class="grid w-full min-w-0 grid-cols-[1rem_1fr] items-center gap-1.5 rounded-xl px-2 py-2 text-left text-xs font-medium text-secondary transition-colors hover-surface-soft hover:shadow-sm"
@click="emit('switch-agent', agent)"
class="text-[10px] font-medium text-brand-600 hover:text-brand-700"
@click="agentPanelOpen = !agentPanelOpen"
>
<div
v-if="agent.icon_url"
class="h-4 w-4 shrink-0 rounded bg-contain bg-center bg-no-repeat"
:style="{ backgroundImage: `url(${agent.icon_url})` }"
/>
<div v-else class="flex h-4 w-4 shrink-0 items-center justify-center rounded bg-brand-100 text-[9px] font-bold text-brand-600">
{{ agent.name.charAt(0) }}
</div>
<span class="min-w-0 truncate">{{ agent.name }}</span>
{{ agentPanelOpen ? $t('chat.collapseAgents') : $t('chat.expandAgents') }}
</button>
</div>
<AgentCategoryList
v-show="agentPanelOpen"
:agents="userAgents"
compact
@select="emit('switch-agent', $event)"
/>
</div>
<div ref="userMenuRef" class="relative flex items-center justify-between text-muted">
@@ -6,6 +6,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 { setLastChatAgentId } from '@/shared/utils/lastChatAgent';
import { sortAgentsByCategory } from '@/shared/utils/agent-category.utils';
import type { ChatDeps } from './chat.deps';
import type { UseChatGuidesReturn } from './useChatGuides';
@@ -75,7 +76,16 @@ export function useChatAgent(options: UseChatAgentOptions) {
const { t, msg, router } = deps;
const currentAgent = ref<any>(null);
const userAgents = ref<Array<{ id: number; name: string; description: string; icon_url?: string; dify_app_type?: 'chatflow' | 'workflow' }>>([]);
const userAgents = ref<Array<{
id: number;
name: string;
description: string;
icon_url?: string;
dify_app_type?: 'chatflow' | 'workflow';
category?: string | null;
sub_category?: string | null;
sort_order?: number;
}>>([]);
const showAgentPanel = ref(true);
const selectedKb = ref(DEFAULT_KB);
const kbOptions = [DEFAULT_KB, ERP_KB];
@@ -162,12 +172,12 @@ export function useChatAgent(options: UseChatAgentOptions) {
const loadUserAgents = async () => {
try {
const agents = await listUserAgents();
userAgents.value = Array.isArray(agents)
const filtered = Array.isArray(agents)
? agents.filter((a: any) => a.id !== currentAgentId.value && (a.dify_app_type || 'chatflow') === 'chatflow')
: [];
if (userAgents.value.length === 0) {
showAgentPanel.value = false;
}
userAgents.value = sortAgentsByCategory(filtered);
// [STEP 1] 有可切换智能体时默认展开面板;避免切换 Agent 后列表「消失」
showAgentPanel.value = userAgents.value.length > 0;
} catch {
userAgents.value = [];
showAgentPanel.value = false;