Merge branch 'custom_agent'
This commit is contained in:
@@ -0,0 +1,160 @@
|
||||
<template>
|
||||
<div
|
||||
class="agent-avatar"
|
||||
:style="avatarStyle"
|
||||
:class="{ 'agent-avatar-small': size === 'small', 'agent-avatar-large': size === 'large' }"
|
||||
>
|
||||
<!-- 星星装饰 - 融入背景 -->
|
||||
<svg class="agent-sparkles" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<!-- 右上角小星星 -->
|
||||
<path d="M24 5L24.4 6.6C24.45 6.85 24.65 7.05 24.9 7.1L26.5 7.5L24.9 7.9C24.65 7.95 24.45 8.15 24.4 8.4L24 10L23.6 8.4C23.55 8.15 23.35 7.95 23.1 7.9L21.5 7.5L23.1 7.1C23.35 7.05 23.55 6.85 23.6 6.6L24 5Z" fill="rgba(255,255,255,0.6)"/>
|
||||
<!-- 左下角小星星 -->
|
||||
<path d="M7 22L7.4 23.6C7.45 23.85 7.65 24.05 7.9 24.1L9.5 24.5L7.9 24.9C7.65 24.95 7.45 25.15 7.4 25.4L7 27L6.6 25.4C6.55 25.15 6.35 24.95 6.1 24.9L4.5 24.5L6.1 24.1C6.35 24.05 6.55 23.85 6.6 23.6L7 22Z" fill="rgba(255,255,255,0.5)"/>
|
||||
</svg>
|
||||
<span class="agent-avatar-letter" :style="letterStyle">{{ letter }}</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed } from 'vue';
|
||||
|
||||
const props = withDefaults(defineProps<{
|
||||
name: string;
|
||||
size?: 'small' | 'medium' | 'large';
|
||||
}>(), {
|
||||
size: 'medium'
|
||||
});
|
||||
|
||||
// 预定义的渐变色方案 - 现代、柔和、专业
|
||||
const gradients = [
|
||||
{ from: '#667eea', to: '#764ba2' }, // 紫蓝渐变
|
||||
{ from: '#4facfe', to: '#00f2fe' }, // 蓝青渐变
|
||||
{ from: '#43e97b', to: '#38f9d7' }, // 绿青渐变
|
||||
{ from: '#11998e', to: '#38ef7d' }, // 深绿渐变
|
||||
{ from: '#5ee7df', to: '#b490ca' }, // 青紫渐变
|
||||
{ from: '#48c6ef', to: '#6f86d6' }, // 蓝紫渐变
|
||||
{ from: '#a8edea', to: '#fed6e3' }, // 青粉渐变(柔和)
|
||||
{ from: '#667db6', to: '#0082c8' }, // 蓝色渐变
|
||||
{ from: '#36d1dc', to: '#5b86e5' }, // 青蓝渐变
|
||||
{ from: '#56ab2f', to: '#a8e063' }, // 草绿渐变
|
||||
{ from: '#614385', to: '#516395' }, // 深紫蓝渐变
|
||||
{ from: '#02aab0', to: '#00cdac' }, // 青绿渐变
|
||||
{ from: '#6a82fb', to: '#fc5c7d' }, // 蓝粉渐变(柔和)
|
||||
{ from: '#834d9b', to: '#d04ed6' }, // 紫色渐变
|
||||
{ from: '#4776e6', to: '#8e54e9' }, // 蓝紫渐变
|
||||
{ from: '#00b09b', to: '#96c93d' }, // 青绿渐变
|
||||
];
|
||||
|
||||
// 根据名称生成一个稳定的哈希值
|
||||
const hashCode = (str: string): number => {
|
||||
let hash = 0;
|
||||
for (let i = 0; i < str.length; i++) {
|
||||
const char = str.charCodeAt(i);
|
||||
hash = ((hash << 5) - hash) + char;
|
||||
hash = hash & hash;
|
||||
}
|
||||
return Math.abs(hash);
|
||||
};
|
||||
|
||||
// 获取首字母(支持中文)
|
||||
const letter = computed(() => {
|
||||
const name = props.name?.trim() || '';
|
||||
if (!name) return '?';
|
||||
|
||||
// 获取第一个字符
|
||||
const firstChar = name.charAt(0);
|
||||
|
||||
// 如果是英文字母,转大写
|
||||
if (/[a-zA-Z]/.test(firstChar)) {
|
||||
return firstChar.toUpperCase();
|
||||
}
|
||||
|
||||
// 中文或其他字符直接返回
|
||||
return firstChar;
|
||||
});
|
||||
|
||||
// 根据名称选择渐变色
|
||||
const gradient = computed(() => {
|
||||
const hash = hashCode(props.name || '');
|
||||
return gradients[hash % gradients.length];
|
||||
});
|
||||
|
||||
// 生成样式
|
||||
const avatarStyle = computed(() => {
|
||||
const g = gradient.value;
|
||||
return {
|
||||
background: `linear-gradient(135deg, ${g.from} 0%, ${g.to} 100%)`
|
||||
};
|
||||
});
|
||||
|
||||
// 字母样式 - 白色 + 背景色阴影增加层次感
|
||||
const letterStyle = computed(() => {
|
||||
const g = gradient.value;
|
||||
return {
|
||||
textShadow: `0 1px 2px ${g.to}80, 0 0 8px ${g.from}30`
|
||||
};
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.agent-avatar {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 8px;
|
||||
flex-shrink: 0;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
overflow: hidden;
|
||||
|
||||
&.agent-avatar-small {
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
border-radius: 5px;
|
||||
box-shadow: none;
|
||||
|
||||
.agent-avatar-letter {
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.agent-sparkles {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
&.agent-avatar-large {
|
||||
width: 48px;
|
||||
height: 48px;
|
||||
border-radius: 12px;
|
||||
|
||||
.agent-avatar-letter {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.agent-sparkles {
|
||||
opacity: 0.9;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.agent-sparkles {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
pointer-events: none;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.agent-avatar-letter {
|
||||
position: relative;
|
||||
z-index: 1;
|
||||
color: #fff;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,556 @@
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<div v-if="visible" class="agent-selector-overlay" @click="$emit('close')">
|
||||
<div
|
||||
class="agent-selector-dropdown"
|
||||
:style="dropdownStyle"
|
||||
@click.stop
|
||||
>
|
||||
<!-- 头部 -->
|
||||
<div class="agent-selector-header">
|
||||
<span>{{ $t('agent.selectAgent') }}</span>
|
||||
<router-link to="/platform/agents" class="agent-selector-add" @click="$emit('close')">
|
||||
<span class="add-icon">+</span>
|
||||
<span class="add-text">{{ $t('agent.manageAgents') }}</span>
|
||||
</router-link>
|
||||
</div>
|
||||
|
||||
<!-- 内容区域 -->
|
||||
<div class="agent-selector-content">
|
||||
<!-- 内置智能体分组 -->
|
||||
<div class="agent-group">
|
||||
<div class="agent-group-title">{{ $t('agent.builtinAgents') }}</div>
|
||||
<t-popup
|
||||
v-for="agent in builtinAgents"
|
||||
:key="agent.id"
|
||||
placement="right"
|
||||
trigger="hover"
|
||||
:show-arrow="true"
|
||||
:overlay-inner-class-name="'agent-tooltip-popup'"
|
||||
>
|
||||
<div
|
||||
class="agent-option"
|
||||
:class="{ 'selected': currentAgentId === agent.id }"
|
||||
@click="selectAgent(agent)"
|
||||
>
|
||||
<div class="builtin-icon" :class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
|
||||
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="14px" />
|
||||
</div>
|
||||
<span class="agent-option-name">{{ agent.name }}</span>
|
||||
<svg
|
||||
v-if="currentAgentId === agent.id"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
class="check-icon"
|
||||
>
|
||||
<path d="M13.5 4.5L6 12L2.5 8.5L3.5 7.5L6 10L12.5 3.5L13.5 4.5Z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="agent-tooltip-content">
|
||||
<div class="agent-tooltip-header">
|
||||
<div class="builtin-icon" :class="agent.config?.agent_mode === 'smart-reasoning' ? 'agent' : 'normal'">
|
||||
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="14px" />
|
||||
</div>
|
||||
<div class="agent-tooltip-title">
|
||||
<span class="agent-tooltip-name">{{ agent.name }}</span>
|
||||
<span v-if="currentAgentId === agent.id" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="agent-tooltip-desc">{{ agent.description || $t('agent.noDescription') }}</p>
|
||||
<div class="agent-tooltip-capabilities">
|
||||
<div class="capability-item">
|
||||
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="12px" />
|
||||
<span>{{ agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.type.agent') : $t('agent.type.normal') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<!-- 自定义智能体分组 -->
|
||||
<div v-if="customAgents.length > 0" class="agent-group">
|
||||
<div class="agent-group-title">{{ $t('agent.customAgents') }}</div>
|
||||
<t-popup
|
||||
v-for="agent in customAgents"
|
||||
:key="agent.id"
|
||||
placement="right"
|
||||
trigger="hover"
|
||||
:show-arrow="true"
|
||||
:overlay-inner-class-name="'agent-tooltip-popup'"
|
||||
>
|
||||
<div
|
||||
class="agent-option"
|
||||
:class="{ 'selected': currentAgentId === agent.id }"
|
||||
@click="selectAgent(agent)"
|
||||
>
|
||||
<AgentAvatar :name="agent.name" size="small" />
|
||||
<span class="agent-option-name">{{ agent.name }}</span>
|
||||
<svg
|
||||
v-if="currentAgentId === agent.id"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
class="check-icon"
|
||||
>
|
||||
<path d="M13.5 4.5L6 12L2.5 8.5L3.5 7.5L6 10L12.5 3.5L13.5 4.5Z"/>
|
||||
</svg>
|
||||
</div>
|
||||
<template #content>
|
||||
<div class="agent-tooltip-content">
|
||||
<div class="agent-tooltip-header">
|
||||
<AgentAvatar :name="agent.name" size="small" />
|
||||
<div class="agent-tooltip-title">
|
||||
<span class="agent-tooltip-name">{{ agent.name }}</span>
|
||||
<span v-if="currentAgentId === agent.id" class="agent-tooltip-selected">{{ $t('agent.selector.current') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p class="agent-tooltip-desc">{{ agent.description || $t('agent.noDescription') }}</p>
|
||||
<div class="agent-tooltip-capabilities">
|
||||
<div class="capability-item">
|
||||
<TIcon :name="agent.config?.agent_mode === 'smart-reasoning' ? 'control-platform' : 'chat'" size="12px" />
|
||||
<span>{{ agent.config?.agent_mode === 'smart-reasoning' ? $t('agent.type.agent') : $t('agent.type.normal') }}</span>
|
||||
</div>
|
||||
<div v-if="getKbCapability(agent)" class="capability-item">
|
||||
<TIcon name="folder" size="12px" />
|
||||
<span>{{ getKbCapability(agent) }}</span>
|
||||
</div>
|
||||
<div v-if="agent.config?.web_search_enabled" class="capability-item">
|
||||
<TIcon name="internet" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.webSearchOn') }}</span>
|
||||
</div>
|
||||
<div v-if="agent.config?.mcp_services?.length || agent.config?.mcp_selection_mode === 'all'" class="capability-item">
|
||||
<TIcon name="extension" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.mcpEnabled') }}</span>
|
||||
</div>
|
||||
<div v-if="agent.config?.multi_turn_enabled" class="capability-item">
|
||||
<TIcon name="chat-bubble" size="12px" />
|
||||
<span>{{ $t('agent.capabilities.multiTurn') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
</t-popup>
|
||||
</div>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<div v-if="builtinAgents.length === 0 && customAgents.length === 0" class="agent-option empty">
|
||||
{{ $t('agent.noAgents') }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, watch, onMounted, nextTick } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Icon as TIcon, Popup as TPopup } from 'tdesign-vue-next';
|
||||
import { listAgents, type CustomAgent, BUILTIN_QUICK_ANSWER_ID, BUILTIN_SMART_REASONING_ID } from '@/api/agent';
|
||||
import AgentAvatar from '@/components/AgentAvatar.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
const props = defineProps<{
|
||||
visible: boolean;
|
||||
anchorEl?: HTMLElement;
|
||||
currentAgentId: string;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'close'): void;
|
||||
(e: 'select', agent: CustomAgent): void;
|
||||
}>();
|
||||
|
||||
const agents = ref<CustomAgent[]>([]);
|
||||
const dropdownStyle = ref<Record<string, string>>({});
|
||||
|
||||
// 内置智能体
|
||||
const builtinAgents = computed(() => {
|
||||
return [
|
||||
{
|
||||
id: BUILTIN_QUICK_ANSWER_ID,
|
||||
name: t('input.normalMode'),
|
||||
description: t('input.normalModeDesc'),
|
||||
is_builtin: true,
|
||||
config: { agent_mode: 'quick-answer' as const }
|
||||
},
|
||||
{
|
||||
id: BUILTIN_SMART_REASONING_ID,
|
||||
name: t('input.agentMode'),
|
||||
description: t('input.agentModeDesc'),
|
||||
is_builtin: true,
|
||||
config: { agent_mode: 'smart-reasoning' as const }
|
||||
}
|
||||
] as CustomAgent[];
|
||||
});
|
||||
|
||||
// 自定义智能体
|
||||
const customAgents = computed(() => {
|
||||
return agents.value.filter(a => !a.is_builtin);
|
||||
});
|
||||
|
||||
// 获取知识库能力描述
|
||||
const getKbCapability = (agent: CustomAgent): string => {
|
||||
const config = agent.config || {};
|
||||
if (config.kb_selection_mode === 'none') {
|
||||
return '';
|
||||
} else if (config.knowledge_bases && config.knowledge_bases.length > 0) {
|
||||
return t('agent.capabilities.kbCount', { count: config.knowledge_bases.length });
|
||||
} else if (config.kb_selection_mode === 'all') {
|
||||
return t('agent.capabilities.kbAll');
|
||||
}
|
||||
return '';
|
||||
};
|
||||
|
||||
// 加载智能体列表
|
||||
const loadAgents = async () => {
|
||||
try {
|
||||
const response = await listAgents();
|
||||
agents.value = response.data || [];
|
||||
} catch (error) {
|
||||
console.error('Failed to load agents:', error);
|
||||
}
|
||||
};
|
||||
|
||||
// 选择智能体
|
||||
const selectAgent = (agent: CustomAgent) => {
|
||||
emit('select', agent);
|
||||
};
|
||||
|
||||
// 更新下拉框位置(与模型选择器一致)
|
||||
const updateDropdownPosition = () => {
|
||||
if (!props.anchorEl) return;
|
||||
|
||||
const rect = props.anchorEl.getBoundingClientRect();
|
||||
const dropdownWidth = 200;
|
||||
const offsetY = 8;
|
||||
const vh = window.innerHeight;
|
||||
const vw = window.innerWidth;
|
||||
|
||||
// 水平位置:左对齐
|
||||
let left = Math.floor(rect.left);
|
||||
const minLeft = 16;
|
||||
const maxLeft = Math.max(16, vw - dropdownWidth - 16);
|
||||
left = Math.max(minLeft, Math.min(maxLeft, left));
|
||||
|
||||
// 垂直位置
|
||||
const preferredDropdownHeight = 320;
|
||||
const minDropdownHeight = 100;
|
||||
const topMargin = 20;
|
||||
const spaceBelow = vh - rect.bottom;
|
||||
const spaceAbove = rect.top;
|
||||
|
||||
let actualHeight: number;
|
||||
|
||||
if (spaceBelow >= minDropdownHeight + offsetY) {
|
||||
// 向下弹出
|
||||
actualHeight = Math.min(preferredDropdownHeight, spaceBelow - offsetY - 16);
|
||||
const top = Math.floor(rect.bottom + offsetY);
|
||||
|
||||
dropdownStyle.value = {
|
||||
position: 'fixed',
|
||||
width: `${dropdownWidth}px`,
|
||||
left: `${left}px`,
|
||||
top: `${top}px`,
|
||||
maxHeight: `${actualHeight}px`,
|
||||
zIndex: '9999'
|
||||
};
|
||||
} else {
|
||||
// 向上弹出
|
||||
const availableHeight = spaceAbove - offsetY - topMargin;
|
||||
actualHeight = availableHeight >= preferredDropdownHeight
|
||||
? preferredDropdownHeight
|
||||
: Math.max(minDropdownHeight, availableHeight);
|
||||
|
||||
const bottom = vh - rect.top + offsetY;
|
||||
|
||||
dropdownStyle.value = {
|
||||
position: 'fixed',
|
||||
width: `${dropdownWidth}px`,
|
||||
left: `${left}px`,
|
||||
bottom: `${bottom}px`,
|
||||
maxHeight: `${actualHeight}px`,
|
||||
zIndex: '9999'
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
// 监听显示状态
|
||||
watch(() => props.visible, (newVal) => {
|
||||
if (newVal) {
|
||||
loadAgents();
|
||||
nextTick(() => {
|
||||
updateDropdownPosition();
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
if (props.visible) {
|
||||
loadAgents();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.agent-selector-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 9998;
|
||||
background: transparent;
|
||||
touch-action: none;
|
||||
}
|
||||
|
||||
.agent-selector-dropdown {
|
||||
position: fixed;
|
||||
background: var(--td-bg-color-container, #fff);
|
||||
border-radius: 10px;
|
||||
box-shadow: var(--td-shadow-2, 0 6px 28px rgba(15, 23, 42, 0.08));
|
||||
border: 1px solid var(--td-component-border, #e7e9eb);
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.agent-selector-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 8px 12px;
|
||||
border-bottom: 1px solid var(--td-component-stroke, #f0f0f0);
|
||||
background: var(--td-bg-color-container, #fff);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
}
|
||||
|
||||
.agent-selector-add {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid transparent;
|
||||
background: transparent;
|
||||
color: var(--td-brand-color, #07c05f);
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s;
|
||||
text-decoration: none;
|
||||
|
||||
.add-icon {
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
color: var(--td-brand-color-hover, #05a04f);
|
||||
background: var(--td-bg-color-secondarycontainer, #f3f3f3);
|
||||
}
|
||||
}
|
||||
|
||||
.agent-selector-content {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
overscroll-behavior: contain;
|
||||
-webkit-overflow-scrolling: touch;
|
||||
padding: 6px 8px;
|
||||
}
|
||||
|
||||
.agent-group {
|
||||
&:not(:last-child) {
|
||||
margin-bottom: 8px;
|
||||
padding-bottom: 8px;
|
||||
border-bottom: 1px solid var(--td-component-stroke, #f0f0f0);
|
||||
}
|
||||
}
|
||||
|
||||
.agent-group-title {
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-placeholder, #999);
|
||||
padding: 4px 8px 6px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.agent-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 6px 8px;
|
||||
cursor: pointer;
|
||||
transition: background 0.12s;
|
||||
border-radius: 6px;
|
||||
margin-bottom: 4px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover, #f6f8f7);
|
||||
}
|
||||
|
||||
&.selected {
|
||||
background: var(--td-brand-color-light, #eefdf5);
|
||||
|
||||
.agent-option-name {
|
||||
color: #10b981;
|
||||
font-weight: 600;
|
||||
}
|
||||
}
|
||||
|
||||
&.empty {
|
||||
color: var(--td-text-color-disabled, #9aa0a6);
|
||||
cursor: default;
|
||||
text-align: center;
|
||||
padding: 20px 8px;
|
||||
|
||||
&:hover {
|
||||
background: transparent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.agent-option-name {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-primary, #222);
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
line-height: 1.4;
|
||||
}
|
||||
|
||||
.builtin-icon {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 24px;
|
||||
height: 24px;
|
||||
border-radius: 6px;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.normal {
|
||||
background: rgba(7, 192, 95, 0.1);
|
||||
color: #059669;
|
||||
}
|
||||
|
||||
&.agent {
|
||||
background: rgba(124, 77, 255, 0.1);
|
||||
color: #7c4dff;
|
||||
}
|
||||
}
|
||||
|
||||
.check-icon {
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
color: #10b981;
|
||||
flex-shrink: 0;
|
||||
margin-left: 6px;
|
||||
}
|
||||
|
||||
// Tooltip 内容样式
|
||||
.agent-tooltip-content {
|
||||
padding: 4px 0;
|
||||
min-width: 200px;
|
||||
max-width: 280px;
|
||||
}
|
||||
|
||||
.agent-tooltip-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
.builtin-icon {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
}
|
||||
}
|
||||
|
||||
.agent-tooltip-title {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 2px;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.agent-tooltip-name {
|
||||
font-size: 13px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary, #222);
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.agent-tooltip-selected {
|
||||
font-size: 10px;
|
||||
color: #10b981;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.agent-tooltip-desc {
|
||||
font-size: 12px;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
line-height: 1.5;
|
||||
margin: 0 0 10px 0;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.agent-tooltip-capabilities {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
padding-top: 8px;
|
||||
border-top: 1px solid var(--td-component-stroke, #f0f0f0);
|
||||
}
|
||||
|
||||
.capability-item {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 3px 8px;
|
||||
background: var(--td-bg-color-secondarycontainer, #f5f5f5);
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
color: var(--td-text-color-secondary, #666);
|
||||
|
||||
:deep(.t-icon) {
|
||||
color: var(--td-text-color-placeholder, #999);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
|
||||
<!-- 全局样式覆盖 TDesign Popup -->
|
||||
<style lang="less">
|
||||
.agent-tooltip-popup {
|
||||
&.t-popup__content {
|
||||
background: var(--td-bg-color-container, #fff) !important;
|
||||
border: 1px solid var(--td-component-border, #e7e9eb) !important;
|
||||
border-radius: 8px !important;
|
||||
box-shadow: var(--td-shadow-2, 0 6px 28px rgba(15, 23, 42, 0.08)) !important;
|
||||
padding: 10px 12px !important;
|
||||
}
|
||||
|
||||
.t-popup__arrow {
|
||||
&::before {
|
||||
background: var(--td-bg-color-container, #fff) !important;
|
||||
border-color: var(--td-component-border, #e7e9eb) !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,261 @@
|
||||
<template>
|
||||
<div class="prompt-template-selector" :class="{ 'position-corner': position === 'corner' }">
|
||||
<t-popup
|
||||
trigger="click"
|
||||
placement="top-right"
|
||||
:visible="popupVisible"
|
||||
@visible-change="handleVisibleChange"
|
||||
>
|
||||
<template #content>
|
||||
<div class="template-popup">
|
||||
<div class="template-header">
|
||||
<span class="template-title">{{ $t('promptTemplate.selectTemplate') }}</span>
|
||||
</div>
|
||||
<div v-if="loading" class="template-loading">
|
||||
<t-loading size="small" />
|
||||
</div>
|
||||
<div v-else-if="templates.length === 0" class="template-empty">
|
||||
{{ $t('promptTemplate.noTemplates') || '暂无模板' }}
|
||||
</div>
|
||||
<div v-else class="template-list">
|
||||
<div
|
||||
v-for="template in templates"
|
||||
:key="template.id"
|
||||
class="template-item"
|
||||
@click="selectTemplate(template)"
|
||||
>
|
||||
<div class="template-item-header">
|
||||
<span class="template-name">{{ template.name }}</span>
|
||||
<span v-if="template.has_knowledge_base" class="template-tag kb-tag">
|
||||
<t-icon name="folder" size="12px" />
|
||||
{{ $t('promptTemplate.withKnowledgeBase') }}
|
||||
</span>
|
||||
<span v-if="template.has_web_search" class="template-tag web-tag">
|
||||
<t-icon name="internet" size="12px" />
|
||||
{{ $t('promptTemplate.withWebSearch') }}
|
||||
</span>
|
||||
</div>
|
||||
<p class="template-desc">{{ template.description }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<t-button
|
||||
variant="outline"
|
||||
size="small"
|
||||
class="template-trigger-btn"
|
||||
:loading="loading"
|
||||
>
|
||||
<t-icon name="view-module" />
|
||||
<span>{{ $t('promptTemplate.useTemplate') }}</span>
|
||||
</t-button>
|
||||
</t-popup>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue';
|
||||
import { getPromptTemplates, type PromptTemplate, type PromptTemplatesConfig } from '@/api/system';
|
||||
|
||||
const props = defineProps<{
|
||||
type: 'systemPrompt' | 'contextTemplate' | 'rewriteSystem' | 'rewriteUser' | 'fallback';
|
||||
hasKnowledgeBase?: boolean;
|
||||
position?: 'inline' | 'corner'; // inline: 行内显示, corner: 输入框右下角
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
(e: 'select', content: string): void;
|
||||
}>();
|
||||
|
||||
const popupVisible = ref(false);
|
||||
const loading = ref(false);
|
||||
const templatesConfig = ref<PromptTemplatesConfig | null>(null);
|
||||
|
||||
const handleVisibleChange = async (visible: boolean) => {
|
||||
popupVisible.value = visible;
|
||||
// 首次打开时加载模板
|
||||
if (visible && !templatesConfig.value) {
|
||||
await loadTemplates();
|
||||
}
|
||||
};
|
||||
|
||||
const loadTemplates = async () => {
|
||||
if (loading.value) return;
|
||||
loading.value = true;
|
||||
try {
|
||||
const response = await getPromptTemplates();
|
||||
templatesConfig.value = response.data;
|
||||
} catch (error) {
|
||||
console.error('Failed to load prompt templates:', error);
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 根据类型获取对应的模板列表
|
||||
const templates = computed<PromptTemplate[]>(() => {
|
||||
if (!templatesConfig.value) return [];
|
||||
|
||||
switch (props.type) {
|
||||
case 'systemPrompt':
|
||||
return templatesConfig.value.system_prompt || [];
|
||||
case 'contextTemplate':
|
||||
return templatesConfig.value.context_template || [];
|
||||
case 'rewriteSystem':
|
||||
return templatesConfig.value.rewrite_system || [];
|
||||
case 'rewriteUser':
|
||||
return templatesConfig.value.rewrite_user || [];
|
||||
case 'fallback':
|
||||
return templatesConfig.value.fallback || [];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
});
|
||||
|
||||
const selectTemplate = (template: PromptTemplate) => {
|
||||
emit('select', template.content);
|
||||
popupVisible.value = false;
|
||||
};
|
||||
|
||||
// 预加载模板(可选)
|
||||
onMounted(() => {
|
||||
// 可以在这里预加载,也可以等用户点击时再加载
|
||||
// loadTemplates();
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.prompt-template-selector {
|
||||
display: inline-flex;
|
||||
|
||||
&.position-corner {
|
||||
position: absolute;
|
||||
right: 8px;
|
||||
bottom: 8px;
|
||||
z-index: 10;
|
||||
}
|
||||
}
|
||||
|
||||
.template-trigger-btn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: #666;
|
||||
border-color: #d9d9d9;
|
||||
font-size: 12px;
|
||||
height: 26px;
|
||||
padding: 0 8px;
|
||||
background: rgba(255, 255, 255, 0.95);
|
||||
|
||||
&:hover {
|
||||
color: #07c05f;
|
||||
border-color: #07c05f;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
:deep(.t-button__text) {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
:deep(.t-icon) {
|
||||
vertical-align: middle;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.template-popup {
|
||||
width: 420px;
|
||||
max-height: 400px;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.template-header {
|
||||
padding: 12px 16px;
|
||||
border-bottom: 1px solid #e5e7eb;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.template-title {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.template-loading,
|
||||
.template-empty {
|
||||
padding: 40px 16px;
|
||||
text-align: center;
|
||||
color: #999;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.template-list {
|
||||
overflow-y: auto;
|
||||
padding: 8px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.template-item {
|
||||
padding: 12px;
|
||||
border-radius: 8px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
margin-bottom: 4px;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
background: #f5f7fa;
|
||||
}
|
||||
}
|
||||
|
||||
.template-item-header {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.template-name {
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.template-tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
padding: 2px 6px;
|
||||
border-radius: 4px;
|
||||
font-size: 11px;
|
||||
|
||||
&.kb-tag {
|
||||
background: #e6f7ff;
|
||||
color: #1890ff;
|
||||
}
|
||||
|
||||
&.web-tag {
|
||||
background: #f0faf5;
|
||||
color: #07c05f;
|
||||
}
|
||||
}
|
||||
|
||||
.template-desc {
|
||||
font-size: 12px;
|
||||
color: #666;
|
||||
margin: 0;
|
||||
line-height: 1.5;
|
||||
display: -webkit-box;
|
||||
-webkit-line-clamp: 2;
|
||||
-webkit-box-orient: vertical;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
@@ -24,10 +24,6 @@
|
||||
<t-icon name="server" class="menu-icon" />
|
||||
<span>Ollama</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('agent')">
|
||||
<t-icon name="chat" class="menu-icon" />
|
||||
<span>{{ $t('settings.conversationStrategy') }}</span>
|
||||
</div>
|
||||
<div class="menu-item" @click="handleQuickNav('websearch')">
|
||||
<svg
|
||||
width="16"
|
||||
|
||||
@@ -24,6 +24,18 @@
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="showCreateAgentAction">
|
||||
<div class="menu_item kb-action-item" @click.stop="handleCreateAgent">
|
||||
<div class="kb-action-icon-wrapper">
|
||||
<svg class="kb-action-icon" width="18" height="18" viewBox="0 0 18 18" fill="none">
|
||||
<path d="M9 3.75V14.25M3.75 9H14.25" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</div>
|
||||
<div class="kb-action-content">
|
||||
<span class="kb-action-title">{{ t('agent.createAgent') }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<template v-else-if="showDocActions">
|
||||
<div class="menu_item kb-action-item" @click.stop="handleDocUploadClick">
|
||||
<div class="kb-action-icon-wrapper">
|
||||
@@ -138,7 +150,7 @@
|
||||
:class="['menu_item', item.childrenPath && item.childrenPath == currentpath ? 'menu_item_c_active' : isMenuItemActive(item.path) ? 'menu_item_active' : '']">
|
||||
<div class="menu_item-box">
|
||||
<div class="menu_icon">
|
||||
<img class="icon" :src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'logout' ? logoutIcon : item.icon == 'setting' ? settingIcon : prefixIcon)" alt="">
|
||||
<img class="icon" :src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'agent' ? agentIcon : item.icon == 'logout' ? logoutIcon : item.icon == 'setting' ? settingIcon : prefixIcon)" alt="">
|
||||
</div>
|
||||
<span class="menu_title" :title="item.title">{{ item.title }}</span>
|
||||
<t-icon v-if="item.path === 'creatChat'" name="add" class="menu-create-hint" />
|
||||
@@ -253,6 +265,9 @@ const isInCreatChat = computed<boolean>(() => {
|
||||
// 是否在对话详情页
|
||||
const isInChatDetail = computed<boolean>(() => route.name === 'chat');
|
||||
|
||||
// 是否在智能体列表页面
|
||||
const isInAgentList = computed<boolean>(() => route.name === 'agentList');
|
||||
|
||||
// 统一的菜单项激活状态判断
|
||||
const isMenuItemActive = (itemPath: string): boolean => {
|
||||
const currentRoute = route.name;
|
||||
@@ -262,6 +277,8 @@ const isMenuItemActive = (itemPath: string): boolean => {
|
||||
return currentRoute === 'knowledgeBaseList' ||
|
||||
currentRoute === 'knowledgeBaseDetail' ||
|
||||
currentRoute === 'knowledgeBaseSettings';
|
||||
case 'agents':
|
||||
return currentRoute === 'agentList';
|
||||
case 'creatChat':
|
||||
return currentRoute === 'kbCreatChat' || currentRoute === 'globalCreatChat';
|
||||
case 'settings':
|
||||
@@ -290,13 +307,13 @@ const getIconActiveState = (itemPath: string) => {
|
||||
// 分离上下两部分菜单
|
||||
const topMenuItems = computed<MenuItem[]>(() => {
|
||||
return (menuArr.value as unknown as MenuItem[]).filter((item: MenuItem) =>
|
||||
item.path === 'knowledge-bases' || item.path === 'creatChat'
|
||||
item.path === 'knowledge-bases' || item.path === 'agents' || item.path === 'creatChat'
|
||||
);
|
||||
});
|
||||
|
||||
const bottomMenuItems = computed<MenuItem[]>(() => {
|
||||
return (menuArr.value as unknown as MenuItem[]).filter((item: MenuItem) => {
|
||||
if (item.path === 'knowledge-bases' || item.path === 'creatChat') {
|
||||
if (item.path === 'knowledge-bases' || item.path === 'agents' || item.path === 'creatChat') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -325,12 +342,14 @@ const showKbActions = computed(() =>
|
||||
(isInKnowledgeBase.value && !!currentKbInfo.value) ||
|
||||
isInKnowledgeBaseList.value ||
|
||||
isInCreatChat.value ||
|
||||
isInChatDetail.value
|
||||
isInChatDetail.value ||
|
||||
isInAgentList.value
|
||||
)
|
||||
const currentKbType = computed(() => currentKbInfo.value?.type || 'document')
|
||||
const showDocActions = computed(() => showKbActions.value && isInKnowledgeBase.value && currentKbType.value !== 'faq')
|
||||
const showFaqActions = computed(() => showKbActions.value && isInKnowledgeBase.value && currentKbType.value === 'faq')
|
||||
const showCreateKbAction = computed(() => showKbActions.value && (isInKnowledgeBaseList.value || isInCreatChat.value || isInChatDetail.value))
|
||||
const showCreateAgentAction = computed(() => showKbActions.value && isInAgentList.value)
|
||||
|
||||
// 时间分组函数
|
||||
const getTimeCategory = (dateStr: string): string => {
|
||||
@@ -570,16 +589,21 @@ let knowledgeIcon = ref('zhishiku-green.svg');
|
||||
let prefixIcon = ref('prefixIcon.svg');
|
||||
let logoutIcon = ref('logout.svg');
|
||||
let settingIcon = ref('setting.svg'); // 设置图标
|
||||
let agentIcon = ref('agent.svg'); // 智能体图标
|
||||
let pathPrefix = ref(route.name)
|
||||
const getIcon = (path: string) => {
|
||||
// 根据当前路由状态更新所有图标
|
||||
const kbActiveState = getIconActiveState('knowledge-bases');
|
||||
const creatChatActiveState = getIconActiveState('creatChat');
|
||||
const settingsActiveState = getIconActiveState('settings');
|
||||
const agentsActiveState = route.name === 'agentList';
|
||||
|
||||
// 知识库图标:只在知识库页面显示绿色
|
||||
knowledgeIcon.value = kbActiveState.isKbActive ? 'zhishiku-green.svg' : 'zhishiku.svg';
|
||||
|
||||
// 智能体图标:只在智能体页面显示绿色
|
||||
agentIcon.value = agentsActiveState ? 'agent-green.svg' : 'agent.svg';
|
||||
|
||||
// 对话图标:只在对话创建页面显示绿色,在知识库页面显示灰色,其他情况显示默认
|
||||
prefixIcon.value = creatChatActiveState.isCreatChatActive ? 'prefixIcon-green.svg' :
|
||||
kbActiveState.isKbActive ? 'prefixIcon-grey.svg' :
|
||||
@@ -601,6 +625,9 @@ const handleMenuClick = async (path: string) => {
|
||||
} else {
|
||||
router.push('/platform/knowledge-bases')
|
||||
}
|
||||
} else if (path === 'agents') {
|
||||
// 智能体菜单项:跳转到智能体列表
|
||||
router.push('/platform/agents')
|
||||
} else if (path === 'settings') {
|
||||
// 设置菜单项:打开设置弹窗并跳转路由
|
||||
uiStore.openSettings()
|
||||
@@ -1238,6 +1265,13 @@ const handleCreateKnowledgeBase = () => {
|
||||
uiStore.openCreateKB()
|
||||
}
|
||||
|
||||
const handleCreateAgent = () => {
|
||||
// 触发创建智能体事件,由 AgentList 页面监听处理
|
||||
window.dispatchEvent(new CustomEvent('openAgentEditor', {
|
||||
detail: { mode: 'create' }
|
||||
}))
|
||||
}
|
||||
|
||||
</script>
|
||||
<style lang="less" scoped>
|
||||
.aside_box {
|
||||
|
||||
Reference in New Issue
Block a user