feat(agent): 增强 Agent 配置,新增结构化字段与聊天功能支持

This commit is contained in:
hugo committed 2026-07-07 11:10:32 +08:00
1 parent ac4262cd75
commit c8ce77199e
183 files changed
+11690 -2300

No files matched your search

@@ -3,11 +3,10 @@
*
* 用途:管理控制台的应用管理页,提供应用列表、创建/编辑弹窗、测试与授权入口。
* 依赖:useAgentsAdmin 业务编排、AgentFormModal/AgentTestModal/AgentPermissionModal 弹窗。
* 逻辑:页面加载后拉取应用/用户/排程数据;主区域展示应用列表,新增和编辑通过弹窗表单完成。
* 逻辑:页面加载后拉取应用/用户/排程数据;列表支持表头列宽拖拽并 localStorage 持久化。
*/
<script setup lang="ts">
import { ref, onMounted } from 'vue';
import { computed, ref, onMounted } from 'vue';
import { useI18n } from 'vue-i18n';
import { Bot, Plus, SquarePen, Trash2, Users } from 'lucide-vue-next';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
@@ -15,19 +14,19 @@ import AgentFormModal from './components/AgentFormModal.vue';
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 || '—';
};
import { useAgentsTableColumnResize } from './composables/useAgentsTableColumnResize';
import type { AgentRow } from '@/features/admin/types/agent.types';
const { t } = useI18n();
const {
agents,
typeCatalog,
runtimeProviders,
conversationModes,
syncContentProfileFromIntentRoutes,
intentRouteOptions,
contentProfileOptions,
scheduleTasks,
trainingExamPdfGuides,
activeUsers,
@@ -67,6 +66,74 @@ const {
confirmDelete,
} = useAgentsAdmin();
const {
columnWidths,
tableMinWidth,
startColumnResize,
resetColumnWidths,
} = useAgentsTableColumnResize();
const tableHeaderColumns = computed(() => [
{ key: 'name', label: t('admin.agent.headers.name'), align: 'left' as const },
{ key: 'type', label: t('admin.agent.headers.type'), align: 'left' as const },
{ key: 'category', label: t('admin.agent.headers.category'), align: 'left' as const },
{ key: 'config', label: t('admin.agent.headers.config'), align: 'left' as const },
{ key: 'status', label: t('admin.agent.headers.status'), align: 'left' as const },
{ key: 'actions', label: t('admin.agent.headers.actions'), align: 'right' as const },
]);
const formatAgentCode = (agent: AgentRow) => agent.agent_code || 'generic';
/** 分类主行:一级分类 */
const formatAgentCategoryPrimary = (agent: AgentRow) => {
const category = String(agent.category || '').trim();
return category || '—';
};
/** 分类副行:二级分类 */
const formatAgentCategorySecondary = (agent: AgentRow) => {
const subCategory = String(agent.sub_category || '').trim();
return subCategory || '—';
};
/** 配置列主行:Dify App ID 或 Iframe URL 摘要。 */
const formatAgentConfigPrimary = (agent: AgentRow) => {
if (agent.runtime_provider === 'iframe' || agent.type === 'iframe') {
const url = String(agent.iframe_url || '').trim();
return url || '—';
}
const appId = String(agent.dify_app_id || '').trim();
return appId || '—';
};
/** 配置列副行:配置类型说明。 */
const formatAgentConfigSecondary = (agent: AgentRow) => {
if (agent.runtime_provider === 'iframe' || agent.type === 'iframe') {
return t('admin.agent.fields.types.iframe');
}
const appType = agent.dify_app_type === 'workflow' ? 'Workflow' : 'Chatflow';
return `${t('admin.agent.fields.types.api')} · ${appType}`;
};
/**
* 列表「类型」列主文案:优先 Catalog 中文 label,否则 agent_code。
*/
const formatAgentTypeLabel = (agent: AgentRow) => {
const code = formatAgentCode(agent);
const entry = typeCatalog.value.find((item) => item.agent_code === code);
return entry?.label || code;
};
/**
* 列表「类型」列副文案:runtime_provider 四语言展示。
*/
const formatRuntimeProviderLabel = (agent: AgentRow) => {
const provider = agent.runtime_provider || (agent.type === 'iframe' ? 'iframe' : 'dify');
const key = `admin.agent.fields.runtimeProviders.${provider}`;
const translated = t(key);
return translated === key ? provider : translated;
};
const showFormDialog = ref(false);
/**
@@ -124,23 +191,36 @@ onMounted(() => {
<Bot class="w-12 h-12 mx-auto text-muted mb-3" />
<p class="text-lg text-secondary">{{ t('admin.agent.noAgents') }}</p>
</div>
<table v-else class="admin-table table-fixed w-full">
<table
v-else
class="admin-table agent-list-table table-fixed w-full"
:style="{ minWidth: `${tableMinWidth}px` }"
>
<colgroup>
<col class="w-64" />
<col class="w-[4.5rem]" />
<col class="w-36" />
<col class="w-32" />
<col class="w-[5.5rem]" />
<col />
<col
v-for="(width, index) in columnWidths"
:key="`col-${index}`"
:style="{ width: `${width}px` }"
/>
</colgroup>
<thead>
<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>
<th
v-for="(column, index) in tableHeaderColumns"
:key="column.key"
class="relative px-4 py-3 text-xs"
:class="column.align === 'right' ? 'text-right' : 'text-left'"
>
<span class="truncate pr-2">{{ column.label }}</span>
<button
v-if="index < tableHeaderColumns.length - 1"
type="button"
class="agent-col-resize-handle"
:title="t('admin.agent.resizeColumn')"
@mousedown.prevent="startColumnResize(index, $event)"
@dblclick.prevent="resetColumnWidths"
/>
</th>
</tr>
</thead>
<tbody>
@@ -151,36 +231,59 @@ onMounted(() => {
:class="{ 'bg-blue-50/50': selectedAgentId === agent.id }"
@click="openEditDialog(agent)"
>
<td class="px-4 py-5 max-w-72">
<div class="font-bold text-primary text-base truncate" :title="agent.name">{{ agent.name }}</div>
<div class="section-desc mt-1 truncate" :title="agent.description">{{ agent.description }}</div>
<td class="px-4 py-4 align-middle">
<div class="agent-list-cell">
<p class="truncate text-sm font-semibold text-primary" :title="agent.name">{{ agent.name }}</p>
<p class="truncate text-xs text-muted" :title="agent.description || ''">
{{ agent.description || '—' }}
</p>
</div>
</td>
<td class="px-2 py-5 whitespace-nowrap">
<span class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-medium bg-surface-soft text-primary uppercase tracking-wide">
{{ agent.type }}
</span>
<td class="px-4 py-4 align-middle">
<div class="agent-list-cell">
<p class="truncate text-sm text-primary" :title="formatAgentTypeLabel(agent)">
{{ formatAgentTypeLabel(agent) }}
</p>
<p class="truncate text-xs text-muted" :title="formatRuntimeProviderLabel(agent)">
{{ formatRuntimeProviderLabel(agent) }}
</p>
</div>
</td>
<td class="px-2 py-5 text-xs text-secondary max-w-36 truncate" :title="formatAgentCategory(agent)">
{{ formatAgentCategory(agent) }}
<td class="px-4 py-4 align-middle">
<div class="agent-list-cell">
<p class="truncate text-sm text-secondary" :title="formatAgentCategoryPrimary(agent)">
{{ formatAgentCategoryPrimary(agent) }}
</p>
<p class="truncate text-xs text-muted" :title="formatAgentCategorySecondary(agent)">
{{ formatAgentCategorySecondary(agent) }}
</p>
</div>
</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 }}
</span>
<span v-else class="truncate block" :title="String(agent.extra_config?.iframe_url || '')">
<span class="text-muted">{{ t('admin.agent.urlLabel') }}:</span> {{ agent.extra_config?.iframe_url }}
</span>
<td class="px-4 py-4 align-middle">
<div class="agent-list-cell">
<p
class="truncate font-mono text-sm text-primary"
:title="formatAgentConfigPrimary(agent)"
>
{{ formatAgentConfigPrimary(agent) }}
</p>
<p class="truncate text-xs text-muted">
{{ formatAgentConfigSecondary(agent) }}
</p>
</div>
</td>
<td class="px-2 py-5 whitespace-nowrap">
<span
class="inline-flex shrink-0 items-center gap-1.5 px-2.5 py-1 rounded-full text-xs font-medium border whitespace-nowrap"
:class="agent.is_active ? 'bg-green-50 text-green-700 border-green-100' : 'bg-surface-soft text-secondary border-default'"
>
<span class="w-2 h-2 shrink-0 rounded-full" :class="agent.is_active ? 'bg-green-500' : 'bg-surface-strong'" />
{{ agent.is_active ? t('admin.status.active') : t('admin.status.disabled') }}
</span>
<td class="px-4 py-4 align-middle">
<div class="agent-list-cell">
<span
class="inline-flex w-fit items-center gap-1.5 rounded-full border px-2.5 py-0.5 text-xs font-medium"
:class="agent.is_active ? 'border-green-100 bg-green-50 text-green-700' : 'border-default bg-surface-soft text-secondary'"
>
<span class="h-1.5 w-1.5 shrink-0 rounded-full" :class="agent.is_active ? 'bg-green-500' : 'bg-surface-strong'" />
{{ agent.is_active ? t('admin.status.active') : t('admin.status.disabled') }}
</span>
</div>
</td>
<td class="px-4 py-5 text-right whitespace-nowrap">
<td class="px-4 py-4 align-middle text-right">
<div class="inline-flex items-center justify-end gap-2">
<button
type="button"
@@ -240,6 +343,12 @@ onMounted(() => {
:form="form"
:schedule-tasks="scheduleTasks"
:training-exam-pdf-guides="trainingExamPdfGuides"
:type-catalog="typeCatalog"
:intent-route-options="intentRouteOptions"
:content-profile-options="contentProfileOptions"
:runtime-providers="runtimeProviders"
:conversation-modes="conversationModes"
:sync-content-profile-from-intent-routes="syncContentProfileFromIntentRoutes"
@close="showFormDialog = false"
@save="saveAgentForm"
@add-suggested-question="addSuggestedQuestion"
@@ -270,3 +379,36 @@ onMounted(() => {
/>
</section>
</template>
<style scoped>
.agent-list-table {
table-layout: fixed;
}
.agent-list-cell {
display: flex;
min-height: 2.5rem;
min-width: 0;
flex-direction: column;
justify-content: center;
gap: 0.125rem;
}
.agent-col-resize-handle {
position: absolute;
top: 0;
right: 0;
z-index: 1;
width: 8px;
height: 100%;
cursor: col-resize;
border: none;
background: transparent;
padding: 0;
}
.agent-col-resize-handle:hover,
.agent-col-resize-handle:active {
background-color: color-mix(in srgb, var(--border-default) 65%, transparent);
}
</style>