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

@@ -14,6 +14,7 @@ import {
Mic,
Paperclip,
Send,
Square,
X,
} from 'lucide-vue-next';
import type { PendingAttachment } from '../types/shipping.types';
@@ -51,6 +52,7 @@ const props = defineProps<{
const emit = defineEmits<{
send: [];
stop: [];
'voice-click': [];
'remove-attachment': [id: string];
'local-files-selected': [event: Event];
@@ -386,6 +388,17 @@ watch(
</div>
<button
v-if="isThinking && !isUploadingAttachments"
type="button"
class="flex h-10 w-10 items-center justify-center rounded-full border border-rose-300 bg-rose-50 text-rose-600 shadow-sm transition-all duration-200 hover:scale-105 hover:bg-rose-100 active:scale-95"
:title="$t('chat.stopGenerating')"
:aria-label="$t('chat.stopGenerating')"
@click="emit('stop')"
>
<Square class="h-4 w-4 fill-current" />
</button>
<button
v-else
type="button"
:disabled="!canSendMessage"
class="flex h-10 w-10 items-center justify-center rounded-full border shadow-sm transition-all duration-200 disabled:cursor-not-allowed disabled:opacity-50"
@@ -394,7 +407,7 @@ watch(
: 'border-brand-500 bg-brand-500 text-white shadow-[0_0_0_4px_rgba(59,130,246,0.18)] hover:scale-105 hover:bg-brand-600 hover:shadow-[0_0_0_6px_rgba(59,130,246,0.24)] active:scale-95'"
@click="emit('send')"
>
<Loader2 v-if="isUploadingAttachments || isThinking" class="h-4 w-4 animate-spin" />
<Loader2 v-if="isUploadingAttachments" class="h-4 w-4 animate-spin" />
<Send v-else class="h-4 w-4" />
</button>
</div>
@@ -5,7 +5,7 @@
* 逻辑:由聊天页面传入当前 Agent、历史记录与用户可用 Agent;通过事件把新会话、切换 Agent、反馈等操作回传给页面。
*/
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref } from 'vue';
import { computed, onBeforeUnmount, onMounted, ref } from 'vue';
import {
BookOpen,
Briefcase,
@@ -25,6 +25,7 @@ import {
} from 'lucide-vue-next';
import LocaleToggleButton from '@/shared/components/LocaleToggleButton.vue';
import AgentCategoryList from '@/shared/components/AgentCategoryList.vue';
import { isHrFocusedAgent, type AgentRegistryFields } from '@/shared/utils/agent-registry.utils';
import type { AgentWithCategory } from '@/shared/utils/agent-category.utils';
import type { DisplayHistoryItem } from '../types/chat.types';
@@ -33,9 +34,9 @@ export interface ChatSidebarAgent extends AgentWithCategory {}
const collapsed = defineModel<boolean>('collapsed', { required: true });
const agentPanelOpen = defineModel<boolean>('agentPanelOpen', { required: true });
const { currentUser } = defineProps<{
const props = defineProps<{
isOpen: boolean;
currentAgent: { name?: string } | null;
currentAgent: AgentRegistryFields | null;
currentAgentId: number;
agentDescription: string;
hasAgentGuides: boolean;
@@ -95,8 +96,10 @@ const onGoAdmin = () => {
emit('go-admin');
};
const agentAvatarLabel = computed(() => (isHrFocusedAgent(props.currentAgent) ? 'HR' : 'AI'));
const userInitial = (fallback: string) => {
const name = String(currentUser?.username ?? '').trim();
const name = String(props.currentUser?.username ?? '').trim();
return (name || fallback).charAt(0).toUpperCase();
};
</script>
@@ -143,7 +146,7 @@ const userInitial = (fallback: string) => {
<div class="flex items-center justify-between p-4">
<div class="flex w-full min-w-0 items-center gap-3">
<div class="flex h-8 w-8 shrink-0 items-center justify-center rounded-xl bg-gradient-to-br from-brand-500 via-brand-600 to-sky-600 text-sm font-bold text-white shadow-sm shadow-brand-500/25">
{{ currentAgent?.name === '人事规章' ? 'HR' : 'AI' }}
{{ agentAvatarLabel }}
</div>
<div class="group relative flex min-w-0 flex-1 flex-col justify-center">
<div class="flex items-center gap-2">
@@ -20,12 +20,16 @@ import LedgerConfigPanel from '@/features/maintenance/components/LedgerConfigPan
import MaintenanceRecordManagerPanel from '@/features/maintenance/components/MaintenanceRecordManagerPanel.vue';
import { useChatPageContext } from '@/features/chat/composables/chat.context';
import { matchesTrainingAgent } from '@/features/chat/training/trainingWorkspace.utils';
import { agentHasIntentUiProfile } from '@/shared/utils/agent-registry.utils';
const page = useChatPageContext();
const isTrainingAgentPage = computed(() => matchesTrainingAgent(page.currentAgent));
const isMaintenanceAgentPage = computed(() => {
const name = String(page.currentAgent?.name || '').trim();
return name === '设备维保助手' || (name.includes('设备维保') && name.includes('助手'));
const isMaintenanceAgentPage = computed(() => agentHasIntentUiProfile(page.currentAgent, 'maintenance'));
const embeddedIframeSrc = computed(() => {
const agent = page.currentAgent;
if (!agent) return undefined;
const url = agent.iframe_url;
return url ? String(url) : undefined;
});
const hideWelcomePanel = computed(() => isTrainingAgentPage.value);
const isTrainingWorkspaceExpanded = ref(false);
@@ -132,9 +136,9 @@ watch(() => page.currentAgentId, () => {
<p class="text-sm animate-pulse text-muted">{{ $t('chat.loadingAgent') }}</p>
</div>
<div v-else-if="page.currentAgent.type === 'iframe'" class="relative h-full w-full flex-1">
<div v-else-if="page.currentAgent.runtime_provider === 'iframe' || page.currentAgent.conversation_mode === 'embedded'" class="relative h-full w-full flex-1">
<iframe
:src="page.currentAgent.extra_config?.iframe_url"
:src="embeddedIframeSrc"
class="h-full w-full border-0 bg-surface"
allow="microphone; camera; clipboard-read; clipboard-write"
/>
@@ -227,6 +231,7 @@ watch(() => page.currentAgentId, () => {
:shipping-notice-picker-ref-holder="page.shippingNoticePickerRefHolder"
:get-kb-label="page.getKbLabel"
@send="page.handleSend()"
@stop="page.stopActiveGeneration()"
@voice-click="page.handleVoiceFeatureClick"
@remove-attachment="page.removeAttachment"
@local-files-selected="page.handleLocalFilesSelected"
@@ -85,6 +85,21 @@ const isResumableTask = (task: ShippingTaskSummary | ShippingTaskDetail) =>
const resolveWorkspaceActionButtons = (task: ShippingTaskSummary | ShippingTaskDetail): ShippingChatAction[] =>
resolveShippingWorkspaceActionButtons(task);
const rpaRuntimeMode = (task: ShippingTaskSummary | ShippingTaskDetail) =>
String(task.rpa_runtime?.mode || '').trim().toLowerCase();
const rpaRuntimeLabel = (task: ShippingTaskSummary | ShippingTaskDetail) => {
const mode = rpaRuntimeMode(task);
if (mode === 'mock') return t('chat.shippingNoticeUi.rpaModeMock');
if (mode === 'browser') return t('chat.shippingNoticeUi.rpaModeBrowser');
return String(task.rpa_runtime?.label || '').trim() || t('chat.shippingNoticeUi.rpaModeUnknown');
};
const rpaRuntimeBadgeClass = (task: ShippingTaskSummary | ShippingTaskDetail) =>
rpaRuntimeMode(task) === 'mock'
? 'border-amber-200 bg-amber-50 text-amber-700'
: 'border-emerald-200 bg-emerald-50 text-emerald-700';
/**
* 渲染工作台任务卡中的辅助动作按钮样式。
* 核心逻辑:把“聚焦当前任务 / 查询缺口明细”降级成轻量辅助入口,避免与后端主业务动作抢视觉权重。
@@ -503,7 +518,16 @@ const handleSwitchBatch = (batchNo: string) => {
<div class="mt-0.5 truncate text-xs text-muted">
{{ task.source_file_name || task.customer_name || t('chat.shippingNoticeUi.currentNotice') }}
</div>
<div class="mt-1 text-xs font-medium text-secondary">{{ taskStepHeadline(task) }}</div>
<div class="mt-1 flex flex-wrap items-center gap-1.5 text-xs font-medium text-secondary">
<span>{{ taskStepHeadline(task) }}</span>
<span
v-if="task.rpa_runtime"
class="rounded border px-1.5 py-0.5 text-[10px] font-bold leading-none"
:class="rpaRuntimeBadgeClass(task)"
>
{{ rpaRuntimeLabel(task) }}
</span>
</div>
</div>
<span class="rounded border px-2 py-1 text-[10px] font-bold" :class="resolveTaskStateMeta(task).className">
{{ resolveTaskStateMeta(task).text }}