Merge branch 'dev' into hugo-shipping-notice
This commit is contained in:
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 {
|
||||
|
||||
Reference in new issue
Block a user