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

@@ -16,6 +16,14 @@ import AgentPermissionModal from './components/AgentPermissionModal.vue';
import AgentTestModal from './components/AgentTestModal.vue';
import { useAgentsAdmin } from './composables/useAgentsAdmin';
const formatAgentCategory = (agent: { extra_config?: Record<string, unknown> }) => {
const extra = agent.extra_config && typeof agent.extra_config === 'object' ? agent.extra_config : {};
const category = String(extra.category || '').trim();
const subCategory = String(extra.sub_category || '').trim();
if (category && subCategory) return `${category} / ${subCategory}`;
return category || subCategory || '—';
};
const { t } = useI18n();
const {
@@ -111,8 +119,9 @@ onMounted(() => {
</div>
<table v-else class="admin-table table-fixed w-full">
<colgroup>
<col class="w-72" />
<col class="w-64" />
<col class="w-[4.5rem]" />
<col class="w-36" />
<col class="w-32" />
<col class="w-[5.5rem]" />
<col />
@@ -121,6 +130,7 @@ onMounted(() => {
<tr>
<th class="px-4 py-4 text-sm">{{ t('admin.agent.headers.name') }}</th>
<th class="px-2 py-4 text-sm">{{ t('admin.agent.headers.type') }}</th>
<th class="px-2 py-4 text-sm">{{ t('admin.agent.headers.category') }}</th>
<th class="px-2 py-4 text-sm">{{ t('admin.agent.headers.config') }}</th>
<th class="px-2 py-4 text-sm">{{ t('admin.agent.headers.status') }}</th>
<th class="px-4 py-4 text-sm text-right">{{ t('admin.agent.headers.actions') }}</th>
@@ -143,6 +153,9 @@ onMounted(() => {
{{ agent.type }}
</span>
</td>
<td class="px-2 py-5 text-xs text-secondary max-w-36 truncate" :title="formatAgentCategory(agent)">
{{ formatAgentCategory(agent) }}
</td>
<td class="px-2 py-5 font-mono text-xs text-muted max-w-32 truncate">
<span v-if="agent.type === 'api'" class="truncate" :title="String(agent.dify_app_id)">
<span class="text-muted">{{ t('admin.agent.idLabel') }}:</span> {{ agent.dify_app_id }}
@@ -107,6 +107,41 @@ const { t } = useI18n();
/>
</div>
<div class="col-span-1 md:col-span-2 rounded-2xl border border-default bg-surface-soft/40 p-4">
<div class="mb-4 text-xs font-bold uppercase tracking-wider text-muted">{{ t('admin.agent.sections.category') }}</div>
<div class="grid grid-cols-1 gap-4 md:grid-cols-3">
<div class="space-y-2">
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.fields.category') }}</label>
<input
v-model="form.category"
type="text"
class="w-full input-field text-sm"
:placeholder="t('admin.agent.fields.categoryPlaceholder')"
/>
</div>
<div class="space-y-2">
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.fields.subCategory') }}</label>
<input
v-model="form.sub_category"
type="text"
class="w-full input-field text-sm"
:placeholder="t('admin.agent.fields.subCategoryPlaceholder')"
/>
</div>
<div class="space-y-2">
<label class="text-xs font-semibold text-secondary">{{ t('admin.agent.fields.sortOrder') }}</label>
<input
v-model.number="form.sort_order"
type="number"
min="0"
step="1"
class="w-full input-field text-sm"
:placeholder="t('admin.agent.fields.sortOrderPlaceholder')"
/>
</div>
</div>
</div>
<div class="col-span-1 md:col-span-2 space-y-3">
<div class="flex flex-wrap items-center justify-between gap-3">
<label class="text-xs font-bold text-muted uppercase tracking-wider">常见问题</label>
@@ -91,6 +91,28 @@ const applyToolRunProgressToExtra = (extraConfig: Record<string, unknown>, form:
delete extraConfig.tool_run_progress;
};
/**
* 将表单分类字段写入 extra_config(P1 轻量方案)。
*/
const applyAgentCategoryToExtra = (extraConfig: Record<string, unknown>, form: AgentFormState): void => {
const category = String(form.category || '').trim();
const subCategory = String(form.sub_category || '').trim();
const sortRaw = Number(form.sort_order);
const sortOrder = Number.isFinite(sortRaw) && sortRaw >= 0 ? Math.floor(sortRaw) : 0;
if (category) {
extraConfig.category = category;
} else {
delete extraConfig.category;
}
if (subCategory) {
extraConfig.sub_category = subCategory;
} else {
delete extraConfig.sub_category;
}
extraConfig.sort_order = sortOrder;
};
export function useAgentsAdmin() {
const { t } = useI18n();
const msg = useMessage();
@@ -177,6 +199,11 @@ export function useAgentsAdmin() {
suggested_questions_style: agent.extra_config?.suggested_questions_style === 'styled' ? 'styled' : 'plain',
suggested_questions: normalizeSuggestedQuestions(agent.extra_config?.suggested_questions),
is_active: agent.is_active,
category: String(extra.category || ''),
sub_category: String(extra.sub_category || ''),
sort_order: Number(extra.sort_order) >= 0 && Number.isFinite(Number(extra.sort_order))
? Math.floor(Number(extra.sort_order))
: 0,
...toolRunProgress,
};
isEditing.value = true;
@@ -252,6 +279,7 @@ export function useAgentsAdmin() {
} else {
applyToolRunProgressToExtra(extra_config, { ...form.value, tool_run_progress_enabled: false });
}
applyAgentCategoryToExtra(extra_config, form.value);
try {
const editingId = isEditing.value ? Number(form.value.id) : null;
@@ -7,16 +7,23 @@ import { onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { Download, FileText, Users } from 'lucide-vue-next';
import BatchPermissionModal from '@/features/admin/modules/users/components/BatchPermissionModal.vue';
import PaginationBar from '@/shared/components/PaginationBar.vue';
import { usePermissionsAdmin } from './composables/usePermissionsAdmin';
const { t } = useI18n();
const {
agents,
permissionFilters,
selectedUserIds,
filteredUsers,
isLoading,
const {
agents,
permissionFilters,
selectedUserIds,
paginatedUsers,
permissionPage,
permissionPageSize,
permissionPageSizeOptions,
permissionTotalRows,
permissionTotalPages,
allUsersSelectedOnPage,
isLoading,
isSaving,
showBatchPermissionModal,
batchPermissionForm,
@@ -102,7 +109,7 @@ onMounted(() => {
<input
type="checkbox"
class="w-4 h-4 rounded text-brand-600 focus:ring-brand-500"
:checked="selectedUserIds.length > 0 && selectedUserIds.length === filteredUsers.length"
:checked="allUsersSelectedOnPage"
@change="toggleAllUsers"
/>
</th>
@@ -131,7 +138,7 @@ onMounted(() => {
</tr>
</thead>
<tbody>
<tr v-for="user in filteredUsers" :key="user.id">
<tr v-for="user in paginatedUsers" :key="user.id">
<td class="px-4 py-4 text-center sticky left-0 admin-table-sticky-cell z-20">
<input
type="checkbox"
@@ -180,6 +187,15 @@ onMounted(() => {
</tbody>
</table>
</div>
<PaginationBar
v-model:page="permissionPage"
v-model:page-size="permissionPageSize"
:total="permissionTotalRows"
:pages="permissionTotalPages"
:page-size-options="permissionPageSizeOptions"
class="mt-5"
/>
</template>
<BatchPermissionModal
@@ -2,7 +2,7 @@
* features/admin/modules/permissions/composables/usePermissionsAdmin.ts
* 用户权限矩阵:筛选、单格切换、批量分配、CSV 导入导出。
*/
import { computed, ref } from 'vue';
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import * as XLSX from 'xlsx';
import {
@@ -30,6 +30,9 @@ export function usePermissionsAdmin() {
const selectedUserIds = ref<number[]>([]);
const isLoading = ref(true);
const isSaving = ref(false);
const permissionPage = ref(1);
const permissionPageSize = ref(10);
const permissionPageSizeOptions = [10, 20, 50, 100];
const showBatchPermissionModal = ref(false);
const batchPermissionForm = ref<BatchPermissionForm>({ agent_ids: [], action: 'add' });
@@ -55,6 +58,32 @@ export function usePermissionsAdmin() {
}),
);
const permissionTotalRows = computed(() => filteredUsers.value.length);
const permissionTotalPages = computed(() => {
const size = Math.max(1, Number(permissionPageSize.value) || 10);
return Math.max(1, Math.ceil(permissionTotalRows.value / size));
});
const paginatedUsers = computed(() => {
const safePage = Math.min(Math.max(1, permissionPage.value), permissionTotalPages.value);
const size = Math.max(1, Number(permissionPageSize.value) || 10);
const start = (safePage - 1) * size;
return filteredUsers.value.slice(start, start + size);
});
const allUsersSelectedOnPage = computed(() => {
const ids = paginatedUsers.value.map((u) => u.id);
return ids.length > 0 && ids.every((id) => selectedUserIds.value.includes(id));
});
watch([permissionFilters, permissionPageSize], () => {
permissionPage.value = 1;
}, { deep: true });
watch(filteredUsers, () => {
if (permissionPage.value > permissionTotalPages.value) {
permissionPage.value = permissionTotalPages.value;
}
});
const loadUsers = async (): Promise<void> => {
try {
users.value = await listAdminUsers();
@@ -89,11 +118,13 @@ export function usePermissionsAdmin() {
};
const toggleAllUsers = (): void => {
if (selectedUserIds.value.length === filteredUsers.value.length) {
selectedUserIds.value = [];
} else {
selectedUserIds.value = filteredUsers.value.map((u) => u.id);
const pageIds = paginatedUsers.value.map((u) => u.id);
const allSelected = pageIds.length > 0 && pageIds.every((id) => selectedUserIds.value.includes(id));
if (allSelected) {
selectedUserIds.value = selectedUserIds.value.filter((id) => !pageIds.includes(id));
return;
}
selectedUserIds.value = Array.from(new Set([...selectedUserIds.value, ...pageIds]));
};
const openBatchPermissionModal = (): void => {
@@ -188,6 +219,13 @@ export function usePermissionsAdmin() {
permissionFilters,
selectedUserIds,
filteredUsers,
paginatedUsers,
permissionPage,
permissionPageSize,
permissionPageSizeOptions,
permissionTotalRows,
permissionTotalPages,
allUsersSelectedOnPage,
isLoading,
isSaving,
showBatchPermissionModal,
@@ -29,12 +29,11 @@ import type { AdminReportTableId } from '@/features/admin/types/admin.types';
const CHAT_LOGS_REPORT_KEYS = [
'agent_name',
'username',
'real_name',
'created_at',
'query',
'answer',
'session_id',
'tokens_used',
'message_type',
] as const;
const CHAT_LOGS_TABLE_KEYS = ['id', ...CHAT_LOGS_REPORT_KEYS] as const;
@@ -46,6 +46,12 @@ export interface AgentFormState {
suggested_questions_style: 'plain' | 'styled';
suggested_questions: AgentSuggestedQuestionItem[];
is_active: boolean;
/** 一级分类,写入 extra_config.category */
category: string;
/** 二级分类,写入 extra_config.sub_category */
sub_category: string;
/** 排序权重,写入 extra_config.sort_order */
sort_order: number;
/** 是否启用 extra_config.capabilities 中的 tool_run_progress */
tool_run_progress_enabled: boolean;
/** 对应 ScheduleTask.id,写入 extra_config.tool_run_progress.schedule_task_id */
@@ -66,6 +72,9 @@ export const createEmptyAgentForm = (): AgentFormState => ({
suggested_questions_style: 'plain',
suggested_questions: [],
is_active: true,
category: '',
sub_category: '',
sort_order: 0,
tool_run_progress_enabled: false,
schedule_task_id: null,
poll_interval_seconds: 2,
@@ -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;
@@ -16,6 +16,12 @@ import {
type WorkspaceUser,
} from '../types/workspace.types';
import type { WorkspaceDeps } from './workspace.deps';
import {
extractAgentCategories,
filterAgentsByQuery,
normalizeAgentCategoryFields,
sortAgentsByCategory,
} from '@/shared/utils/agent-category.utils';
interface HomeOptions {
currentUser: Ref<WorkspaceUser | null>;
@@ -41,6 +47,7 @@ export function useWorkspaceHome(deps: WorkspaceDeps, options: HomeOptions) {
{ id: 'all_agents', visible: true, collapsed: false, title: 'workspace.availableAgents' },
]);
const searchQuery = ref('');
const selectedCategory = ref<string | null>(null);
const showAnnouncementModal = ref(false);
const selectedAnnouncement = ref<WorkspaceAnnouncement | null>(null);
const userReport = ref<unknown>(null);
@@ -53,13 +60,18 @@ export function useWorkspaceHome(deps: WorkspaceDeps, options: HomeOptions) {
const favoriteAgents = computed(() => agents.value.filter((a) => favoriteAgentIds.value.includes(a.id)));
const chatflowAgents = computed(() =>
sortAgentsByCategory(agents.value.filter((a) => (a.dify_app_type || 'chatflow') === 'chatflow')),
);
const agentCategories = computed(() => extractAgentCategories(chatflowAgents.value));
const otherAgents = computed(() => {
const chatflowAgents = agents.value.filter((a) => (a.dify_app_type || 'chatflow') === 'chatflow');
if (!searchQuery.value.trim()) return chatflowAgents;
const q = searchQuery.value.toLowerCase();
return chatflowAgents.filter(
(a) => a.name.toLowerCase().includes(q) || a.description.toLowerCase().includes(q),
);
let list = chatflowAgents.value;
if (selectedCategory.value) {
list = list.filter((a) => normalizeAgentCategoryFields(a).category === selectedCategory.value);
}
return filterAgentsByQuery(list, searchQuery.value);
});
const filteredQuickQuestions = computed(() => {
@@ -85,6 +97,7 @@ export function useWorkspaceHome(deps: WorkspaceDeps, options: HomeOptions) {
favoriteAgentIds.value = [];
embeddedAgents.value = [];
userReport.value = null;
selectedCategory.value = null;
};
const fetchHome = async () => {
@@ -322,6 +335,8 @@ export function useWorkspaceHome(deps: WorkspaceDeps, options: HomeOptions) {
SECTION_TITLE_KEY_MAP,
layoutSections,
searchQuery,
selectedCategory,
agentCategories,
showAnnouncementModal,
selectedAnnouncement,
userReport,
@@ -161,6 +161,26 @@ const ws = inject(WORKSPACE_KEY)! as any;
<!-- Content: All Agents -->
<div v-if="section.id === 'all_agents'">
<div class="mb-4 flex flex-wrap gap-2">
<button
type="button"
class="rounded-full px-3 py-1.5 text-xs font-medium transition-colors"
:class="!ws.selectedCategory ? 'bg-brand-600 text-white' : 'bg-surface-soft text-secondary hover:bg-slate-100'"
@click="ws.selectedCategory = null"
>
{{ $t('workspace.agentCategory.all') }}
</button>
<button
v-for="category in ws.agentCategories"
:key="category"
type="button"
class="rounded-full px-3 py-1.5 text-xs font-medium transition-colors"
:class="ws.selectedCategory === category ? 'bg-brand-600 text-white' : 'bg-surface-soft text-secondary hover:bg-slate-100'"
@click="ws.selectedCategory = category"
>
{{ category }}
</button>
</div>
<div class="mb-6">
<input v-model="ws.searchQuery" type="text" :placeholder="$t('workspace.search')" class="input-field max-w-md shadow-sm" />
</div>
@@ -29,6 +29,9 @@ export interface WorkspaceAgent {
description: string;
icon_url?: string;
dify_app_type?: 'chatflow' | 'workflow';
category?: string | null;
sub_category?: string | null;
sort_order?: number;
}
export interface WorkspaceQuickQuestion {
+12 -1
View File
@@ -143,6 +143,7 @@
"headers": {
"name": "Name",
"type": "Type",
"category": "Category",
"config": "Configuration",
"status": "Status",
"actions": "Actions"
@@ -161,9 +162,18 @@
"baseUrlPlaceholder": "Default: Dify Config",
"iframeUrl": "Iframe URL",
"description": "Description",
"descPlaceholder": "Briefly describe what this agent does..."
"descPlaceholder": "Briefly describe what this agent does...",
"category": "Primary category",
"categoryPlaceholder": "e.g. R&D Systems",
"subCategory": "Subcategory",
"subCategoryPlaceholder": "e.g. System Documents (optional)",
"sortOrder": "Sort order",
"sortOrderPlaceholder": "Lower numbers appear first (default 0)"
},
"confirmDelete": "Are you sure you want to delete this agent?",
"sections": {
"category": "Display category"
},
"manageAccess": "Manage Access",
"test": "Test",
"delete": "Delete Agent",
@@ -665,6 +675,7 @@
"api_base_url": "API Base URL",
"agent_id": "Agent ID",
"agent_name": "Agent Name",
"real_name": "Real Name",
"conversation_id": "Conversation ID",
"attribution_parts": "Attribution Parts",
"session_id": "Session ID",
+5
View File
@@ -187,6 +187,11 @@
"clearOneRecord": "Clear This Record",
"agents": "Agents",
"noOtherAgents": "No other agents",
"agentCategory": {
"searchPlaceholder": "Search agents…",
"noResults": "No matching agents",
"uncategorized": "Knowledge Base Q&A"
},
"noAvailableAgents": "No available agents",
"collapseAgents": "Collapse agents",
"expandAgents": "Expand agents",
+4
View File
@@ -51,6 +51,10 @@
"favorites": "Favorites",
"myAgents": "My Agents",
"availableAgents": "Available Agents",
"agentCategory": {
"all": "All",
"uncategorized": "Knowledge Base Q&A"
},
"noAgents": "No agents available",
"noPublicAgents": "No public agents available, please contact admin.",
"requestPermission": "Request Access",
+11 -1
View File
@@ -143,6 +143,7 @@
"headers": {
"name": "ชื่อ",
"type": "ประเภท",
"category": "หมวดหมู่",
"config": "การกำหนดค่า",
"status": "สถานะ",
"actions": "การกระทำ"
@@ -161,9 +162,18 @@
"baseUrlPlaceholder": "ค่าเริ่มต้น: ใช้การตั้งค่า Dify",
"iframeUrl": "Iframe URL",
"description": "คำอธิบาย",
"descPlaceholder": "อธิบายสั้นๆ เกี่ยวกับตัวแทนนี้..."
"descPlaceholder": "อธิบายสั้นๆ เกี่ยวกับตัวแทนนี้...",
"category": "หมวดหมู่หลัก",
"categoryPlaceholder": "เช่น ระบบวิจัยและพัฒนา",
"subCategory": "หมวดหมู่ย่อย",
"subCategoryPlaceholder": "เช่น เอกสารระบบ (ไม่บังคับ)",
"sortOrder": "ลำดับการแสดง",
"sortOrderPlaceholder": "ตัวเลขน้อยแสดงก่อน (ค่าเริ่มต้น 0)"
},
"confirmDelete": "คุณแน่ใจหรือไม่ว่าต้องการลบตัวแทนนี้?",
"sections": {
"category": "หมวดหมู่การแสดงผล"
},
"manageAccess": "จัดการสิทธิ์",
"test": "ทดสอบ",
"delete": "ลบแอป",
+5
View File
@@ -187,6 +187,11 @@
"clearOneRecord": "ลบรายการนี้",
"agents": "ตัวแทน",
"noOtherAgents": "ไม่มีตัวแทนอื่น",
"agentCategory": {
"searchPlaceholder": "ค้นหาตัวแทน…",
"noResults": "ไม่พบตัวแทนที่ตรงกัน",
"uncategorized": "ฐานความรู้ Q&A"
},
"noAvailableAgents": "ไม่มีตัวแทนที่ใช้ได้",
"collapseAgents": "ย่อตัวแทน",
"expandAgents": "ขยายตัวแทน",
+4
View File
@@ -51,6 +51,10 @@
"favorites": "รายการโปรด",
"myAgents": "ตัวแทนของฉัน",
"availableAgents": "ตัวแทนที่ใช้ได้",
"agentCategory": {
"all": "ทั้งหมด",
"uncategorized": "ฐานความรู้ Q&A"
},
"noAgents": "ไม่มีตัวแทนที่ใช้ได้",
"noFavorites": "ไม่มีรายการโปรด",
"noPublicAgents": "ไม่มีตัวแทนสาธารณะที่ใช้ได้ โปรดติดต่อผู้ดูแลระบบ",
+12 -1
View File
@@ -144,6 +144,7 @@
"headers": {
"name": "名称",
"type": "类型",
"category": "分类",
"config": "配置",
"status": "状态",
"actions": "操作"
@@ -162,9 +163,18 @@
"baseUrlPlaceholder": "默认:使用 Dify 配置",
"iframeUrl": "Iframe URL",
"description": "描述",
"descPlaceholder": "简要描述该应用的功能..."
"descPlaceholder": "简要描述该应用的功能...",
"category": "一级分类",
"categoryPlaceholder": "例如:研发体系",
"subCategory": "二级分类",
"subCategoryPlaceholder": "例如:体系文件(选填)",
"sortOrder": "排序权重",
"sortOrderPlaceholder": "数字越小越靠前,默认 0"
},
"confirmDelete": "确定要删除该应用吗?",
"sections": {
"category": "展示分类"
},
"manageAccess": "管理权限",
"test": "测试",
"delete": "删除应用",
@@ -666,6 +676,7 @@
"api_base_url": "API 基础 URL",
"agent_id": "应用 ID",
"agent_name": "应用名称",
"real_name": "真实姓名",
"conversation_id": "会话 ID",
"attribution_parts": "归因片段",
"session_id": "会话 ID",
+5
View File
@@ -193,6 +193,11 @@
"clearOneRecord": "清除该记录",
"agents": "智能体",
"noOtherAgents": "暂无其他智能体",
"agentCategory": {
"searchPlaceholder": "搜索智能体…",
"noResults": "未找到匹配的智能体",
"uncategorized": "知识库问答"
},
"noAvailableAgents": "暂无可用智能体",
"collapseAgents": "收起智能体",
"expandAgents": "展开智能体",
@@ -51,6 +51,10 @@
"favorites": "收藏应用",
"myAgents": "我的应用",
"availableAgents": "可用应用",
"agentCategory": {
"all": "全部",
"uncategorized": "知识库问答"
},
"noAgents": "暂无可用应用",
"noFavorites": "暂无收藏",
"noPublicAgents": "暂无公开应用,请联系管理员。",
+12 -1
View File
@@ -143,6 +143,7 @@
"headers": {
"name": "名稱",
"type": "類型",
"category": "分類",
"config": "配置",
"status": "狀態",
"actions": "操作"
@@ -161,9 +162,18 @@
"baseUrlPlaceholder": "預設:使用 Dify 配置",
"iframeUrl": "Iframe URL",
"description": "描述",
"descPlaceholder": "簡要描述該應用的功能..."
"descPlaceholder": "簡要描述該應用的功能...",
"category": "一級分類",
"categoryPlaceholder": "例如:研發體系",
"subCategory": "二級分類",
"subCategoryPlaceholder": "例如:體系文件(選填)",
"sortOrder": "排序權重",
"sortOrderPlaceholder": "數字越小越靠前,預設 0"
},
"confirmDelete": "確定要刪除該應用嗎?",
"sections": {
"category": "展示分類"
},
"manageAccess": "管理權限",
"test": "測試",
"delete": "刪除應用",
@@ -670,6 +680,7 @@
"api_base_url": "API 基礎 URL",
"agent_id": "應用 ID",
"agent_name": "應用名稱",
"real_name": "真實姓名",
"conversation_id": "會話 ID",
"attribution_parts": "歸因片段",
"session_id": "會話 ID",
+5
View File
@@ -189,6 +189,11 @@
"clearOneRecord": "清除此記錄",
"agents": "智能體",
"noOtherAgents": "暫無其他智能體",
"agentCategory": {
"searchPlaceholder": "搜尋智能體…",
"noResults": "未找到符合的智能體",
"uncategorized": "知識庫問答"
},
"noAvailableAgents": "暫無可用智能體",
"collapseAgents": "收起智能體",
"expandAgents": "展開智能體",
@@ -51,6 +51,10 @@
"favorites": "收藏應用",
"myAgents": "我的應用",
"availableAgents": "可用應用",
"agentCategory": {
"all": "全部",
"uncategorized": "知識庫問答"
},
"noAgents": "暫無可用應用",
"noFavorites": "暫無收藏",
"noPublicAgents": "暫無公開應用,請聯繫管理員。",
@@ -0,0 +1,144 @@
/**
* shared/components/AgentCategoryList.vue
* 用途:按一级/二级分类展示可切换的 Agent 列表,支持搜索与折叠分组。
* 依赖:agent-category.utils、vue-i18n。
* 逻辑:ChatSidebar、ChatMobileHeader 等入口传入 agents 与 select 事件即可复用。
*/
<script setup lang="ts">
import { computed, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { ChevronDown, ChevronRight, Search } from 'lucide-vue-next';
import {
filterAgentsByQuery,
groupAgentsByCategory,
type AgentWithCategory,
} from '@/shared/utils/agent-category.utils';
const props = withDefaults(defineProps<{
agents: AgentWithCategory[];
compact?: boolean;
showSearch?: boolean;
defaultExpanded?: boolean;
}>(), {
compact: false,
showSearch: true,
defaultExpanded: true,
});
const emit = defineEmits<{
select: [agent: AgentWithCategory];
}>();
const { t } = useI18n();
const searchQuery = ref('');
const collapsedCategories = ref<Set<string>>(new Set());
const uncategorizedLabel = computed(() => t('chat.agentCategory.uncategorized'));
const filteredAgents = computed(() => filterAgentsByQuery(props.agents, searchQuery.value));
const categoryGroups = computed(() =>
groupAgentsByCategory(filteredAgents.value, uncategorizedLabel.value),
);
/**
* 同步分类折叠态:新增分类默认展开,移除已不存在的折叠记录。
*/
const syncCollapsedState = () => {
const keys = new Set(categoryGroups.value.map((group) => group.category));
const next = new Set<string>();
for (const key of collapsedCategories.value) {
if (keys.has(key)) next.add(key);
}
if (!props.defaultExpanded) {
for (const group of categoryGroups.value) {
if (!next.has(group.category)) next.add(group.category);
}
}
collapsedCategories.value = next;
};
watch(categoryGroups, syncCollapsedState, { immediate: true });
const toggleCategory = (category: string) => {
const next = new Set(collapsedCategories.value);
if (next.has(category)) {
next.delete(category);
} else {
next.add(category);
}
collapsedCategories.value = next;
};
const isCategoryCollapsed = (category: string) => collapsedCategories.value.has(category);
const onSelect = (agent: AgentWithCategory) => {
emit('select', agent);
};
</script>
<template>
<div class="space-y-2">
<div v-if="showSearch" class="relative">
<Search class="pointer-events-none absolute left-2 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted" />
<input
v-model="searchQuery"
type="search"
class="w-full rounded-lg border border-default bg-surface py-1.5 pl-7 pr-2 text-xs text-primary placeholder:text-muted focus:border-brand-400 focus:outline-none focus:ring-1 focus:ring-brand-400"
:placeholder="t('chat.agentCategory.searchPlaceholder')"
/>
</div>
<div v-if="categoryGroups.length === 0" class="py-2 text-center text-xs text-muted">
{{ t('chat.agentCategory.noResults') }}
</div>
<div v-else class="max-h-48 space-y-2 overflow-y-auto scrollbar-thin">
<section v-for="group in categoryGroups" :key="group.category" class="space-y-1">
<button
type="button"
class="flex w-full items-center gap-1 rounded-md px-1 py-0.5 text-left text-[11px] font-semibold text-muted transition-colors hover:text-secondary"
@click="toggleCategory(group.category)"
>
<ChevronDown v-if="!isCategoryCollapsed(group.category)" class="h-3 w-3 shrink-0" />
<ChevronRight v-else class="h-3 w-3 shrink-0" />
<span class="min-w-0 flex-1 truncate">{{ group.category }}</span>
<span class="shrink-0 text-[10px] font-normal opacity-70">({{ group.agents.length }})</span>
</button>
<div v-show="!isCategoryCollapsed(group.category)" class="space-y-2 pl-1">
<template v-for="subGroup in group.subGroups" :key="`${group.category}-${subGroup.subCategory || '_'}`">
<div
v-if="subGroup.subCategory && group.subGroups.length > 1"
class="px-1 text-[10px] font-medium text-muted"
>
{{ subGroup.subCategory }}
</div>
<div :class="compact ? 'grid grid-cols-2 gap-x-2 gap-y-1.5' : 'grid grid-cols-2 gap-2'">
<button
v-for="agent in subGroup.agents"
: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="onSelect(agent)"
>
<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>
</button>
</div>
</template>
</div>
</section>
</div>
</div>
</template>
@@ -0,0 +1,126 @@
/**
* shared/utils/agent-category.utils.ts
* 用途:Agent P1 分类(extra_config.category / sub_category / sort_order)的解析、排序与分组。
* 依赖:无;供 Chat 侧栏、工作台、管理端列表复用。
* 逻辑:分类暂存 extra_config;P2 迁移独立表后本工具仅改数据来源。
*/
export interface AgentCategoryFields {
category?: string | null;
sub_category?: string | null;
sort_order?: number;
}
export interface AgentWithCategory extends AgentCategoryFields {
id: number;
name: string;
icon_url?: string;
description?: string;
}
export interface AgentCategorySubGroup<T extends AgentWithCategory = AgentWithCategory> {
subCategory: string;
agents: T[];
}
export interface AgentCategoryGroup<T extends AgentWithCategory = AgentWithCategory> {
category: string;
subGroups: AgentCategorySubGroup<T>[];
agents: T[];
}
const UNCATEGORIZED_KEY = '';
/**
* 规范化分类字段,去除空白并将 sort_order 转为非负整数。
*/
export function normalizeAgentCategoryFields(
agent: AgentCategoryFields,
): { category: string; subCategory: string; sortOrder: number } {
const category = String(agent.category || '').trim();
const subCategory = String(agent.sub_category || '').trim();
const raw = Number(agent.sort_order);
const sortOrder = Number.isFinite(raw) && raw >= 0 ? Math.floor(raw) : 0;
return { category, subCategory, sortOrder };
}
/**
* 按 sort_order → category → sub_category → name 排序 Agent 列表。
*/
export function sortAgentsByCategory<T extends AgentWithCategory>(agents: T[]): T[] {
return [...agents].sort((a, b) => {
const left = normalizeAgentCategoryFields(a);
const right = normalizeAgentCategoryFields(b);
if (left.sortOrder !== right.sortOrder) return left.sortOrder - right.sortOrder;
const catA = left.category || '\uffff';
const catB = right.category || '\uffff';
if (catA !== catB) return catA.localeCompare(catB, 'zh-CN');
const subA = left.subCategory || '\uffff';
const subB = right.subCategory || '\uffff';
if (subA !== subB) return subA.localeCompare(subB, 'zh-CN');
return a.name.localeCompare(b.name, 'zh-CN');
});
}
/**
* 将 Agent 列表按一级 category、二级 sub_category 分组。
* @param uncategorizedLabel - 未配置 category 时的默认分组名(i18n:知识库问答)
*/
export function groupAgentsByCategory<T extends AgentWithCategory>(
agents: T[],
uncategorizedLabel: string,
): AgentCategoryGroup<T>[] {
const sorted = sortAgentsByCategory(agents);
const categoryMap = new Map<string, AgentCategoryGroup<T>>();
for (const agent of sorted) {
const { category, subCategory } = normalizeAgentCategoryFields(agent);
const categoryKey = category || UNCATEGORIZED_KEY;
const displayCategory = category || uncategorizedLabel;
if (!categoryMap.has(categoryKey)) {
categoryMap.set(categoryKey, {
category: displayCategory,
subGroups: [],
agents: [],
});
}
const group = categoryMap.get(categoryKey)!;
group.agents.push(agent);
const subKey = subCategory || UNCATEGORIZED_KEY;
let subGroup = group.subGroups.find((item) => (item.subCategory || UNCATEGORIZED_KEY) === subKey);
if (!subGroup) {
subGroup = { subCategory, agents: [] };
group.subGroups.push(subGroup);
}
subGroup.agents.push(agent);
}
return Array.from(categoryMap.values());
}
/**
* 提取去重且已排序的一级分类名称(不含未分类)。
*/
export function extractAgentCategories<T extends AgentWithCategory>(agents: T[]): string[] {
const set = new Set<string>();
for (const agent of agents) {
const { category } = normalizeAgentCategoryFields(agent);
if (category) set.add(category);
}
return Array.from(set).sort((a, b) => a.localeCompare(b, 'zh-CN'));
}
/**
* 按关键词过滤 Agent(名称、一级/二级分类)。
*/
export function filterAgentsByQuery<T extends AgentWithCategory>(agents: T[], query: string): T[] {
const q = query.trim().toLowerCase();
if (!q) return agents;
return agents.filter((agent) => {
const { category, subCategory } = normalizeAgentCategoryFields(agent);
const haystack = [agent.name, category, subCategory].join(' ').toLowerCase();
return haystack.includes(q);
});
}