feat: Enhance agent settings and UI components

- Updated the Input-field component to improve styling and consistency with new color scheme.
- Added model recommendation section in AgentSettings with localized content for better user guidance.
- Enhanced AgentStreamDisplay to conditionally show timeline based on event types, improving user experience.
- Updated botmsg and docInfo components for better display of web search references and document information.
- Improved fallback response handling in session management, allowing for more flexible user interactions.
- Introduced deduplication and scoring mechanisms in grep_chunks and knowledge_search tools to enhance search result relevance and diversity.
This commit is contained in:
wizardchen
2025-11-25 13:28:21 +08:00
parent 55d6bc7274
commit 9f6f5f5773
15 changed files with 1336 additions and 222 deletions
+12 -12
View File
@@ -1121,7 +1121,7 @@ const getImgSrc = (url: string) => {
padding: 0 10px;
min-width: auto;
font-weight: 500;
border: 1.5px solid transparent;
border: 1px solid transparent;
transition: background 0.12s, border-color 0.12s;
position: relative;
@@ -1132,7 +1132,7 @@ const getImgSrc = (url: string) => {
box-shadow: 0 2px 6px rgba(16, 185, 129, 0.12);
.agent-mode-text {
color: #10b981;
color: #07C05F;
font-weight: 600;
}
@@ -1141,7 +1141,7 @@ const getImgSrc = (url: string) => {
}
.dropdown-arrow {
color: #10b981;
color: #07C05F;
}
&:hover {
@@ -1195,7 +1195,7 @@ const getImgSrc = (url: string) => {
&.active {
background: rgba(16, 185, 129, 0.1);
color: #10b981;
color: #07C05F;
&:hover {
background: rgba(16, 185, 129, 0.15);
@@ -1211,7 +1211,7 @@ const getImgSrc = (url: string) => {
}
.kb-btn.active .kb-btn-text {
color: #10b981;
color: #07C05F;
}
.websearch-btn {
@@ -1227,7 +1227,7 @@ const getImgSrc = (url: string) => {
background: rgba(16, 185, 129, 0.1);
.websearch-icon {
color: #10b981;
color: #07C05F;
}
&:hover {
@@ -1355,7 +1355,7 @@ const getImgSrc = (url: string) => {
height: 28px;
padding: 0;
background: rgba(16, 185, 129, 0.08);
color: #10b981;
color: #07C05F;
border: 1.5px solid rgba(16, 185, 129, 0.2);
position: relative;
display: flex;
@@ -1364,7 +1364,7 @@ const getImgSrc = (url: string) => {
&:hover {
background: rgba(16, 185, 129, 0.12);
border-color: #10b981;
border-color: #07C05F;
}
&:active {
@@ -1379,7 +1379,7 @@ const getImgSrc = (url: string) => {
content: '';
width: 12px;
height: 12px;
background: #10b981;
background: #07C05F;
border-radius: 50%;
display: block;
}
@@ -1389,7 +1389,7 @@ const getImgSrc = (url: string) => {
width: 28px;
height: 28px;
padding: 0;
background-color: #10b981;
background-color: #07C05F;
&:hover:not(.disabled) {
background-color: #059669;
@@ -1446,7 +1446,7 @@ const getImgSrc = (url: string) => {
flex: 1;
font-size: 12px;
font-weight: 600;
color: #10b981;
color: #07C05F;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
@@ -1455,7 +1455,7 @@ const getImgSrc = (url: string) => {
.model-dropdown-arrow {
width: 10px;
height: 10px;
color: #10b981;
color: #07C05F;
flex-shrink: 0;
transition: transform 0.12s;
+4
View File
@@ -1397,6 +1397,10 @@ export default {
agentSettings: {
title: 'Agent Settings',
description: 'Configure the default behavior and parameters for the AI Agent. These settings apply to all chats with Agent mode enabled.',
modelRecommendation: {
title: 'Model Recommendation',
content: 'For better Agent experience, we recommend using large language models with FunctionCalling support and long context windows, such as deepseek-v3.1-terminus',
},
status: {
label: 'Agent Status',
ready: 'Ready',
+4
View File
@@ -1395,6 +1395,10 @@ export default {
title: "Agent 配置",
description:
"配置 AI Agent 的默认行为和参数,这些设置将应用于所有启用 Agent 模式的对话",
modelRecommendation: {
title: "模型推荐",
content: "为获得更好的 Agent 体验,建议使用支持 FunctionCalling 的长上下文大语言模型,如 deepseek-v3.1-terminus 等",
},
status: {
label: "Agent 状态",
ready: "可用",
@@ -16,7 +16,7 @@
<!-- Event Stream -->
<template v-for="(event, index) in displayEvents" :key="getEventKey(event, index)">
<div v-if="event && event.type" class="event-item" :data-event-index="index" :class="{ 'event-last': index === displayEvents.length - 1 }">
<div v-if="event && event.type" class="event-item" :data-event-index="index" :class="{ 'event-last': index === displayEvents.length - 1, 'no-timeline': !shouldShowTimeline }">
<!-- Plan Task Change Event -->
<div v-if="event.type === 'plan_task_change'" class="plan-task-change-event">
@@ -167,7 +167,7 @@
</template>
<!-- Loading Indicator -->
<div v-if="!isConversationDone && eventStream.length > 0" class="loading-indicator">
<div v-if="!isConversationDone && eventStream.length > 0" class="loading-indicator" :class="{ 'no-timeline': !shouldShowTimeline }">
<!-- 方案1: 三个跳动的圆点 -->
<!-- <div class="loading-dots">
<span></span>
@@ -341,6 +341,26 @@ marked.use({
// Event stream
const eventStream = computed(() => props.session?.agentEventStream || []);
// Check if should show timeline (only show when there are tool calls or thinking events)
const shouldShowTimeline = computed(() => {
// Only show timeline in agent mode and when there are intermediate steps
if (props.session?.isAgentMode !== true) {
return false;
}
const stream = eventStream.value;
if (!stream || stream.length === 0) {
return false;
}
// Check if there are any tool calls or thinking events (not just simple answer)
const hasToolCalls = stream.some((e: any) => e.type === 'tool_call');
const hasThinking = stream.some((e: any) => e.type === 'thinking');
// Only show timeline if there are tool calls or thinking events
return hasToolCalls || hasThinking;
});
// Expanded events tracking (for tool calls)
// Initialize with thinking tools expanded by default
const expandedEvents = ref<Set<string>>(new Set());
@@ -1669,6 +1689,42 @@ const handleAddToKnowledge = (answerEvent: any) => {
border-radius: 2px;
box-shadow: 0 1px 3px rgba(7, 192, 95, 0.2);
}
// 普通模式下隐藏时间轴(放在最后以确保优先级)
&.no-timeline {
padding-left: 0 !important;
&::before,
&::after {
display: none !important;
content: none !important;
visibility: hidden !important;
opacity: 0 !important;
width: 0 !important;
height: 0 !important;
}
// 确保所有事件类型的时间轴都被隐藏(使用更强的选择器)
&.event-last::before,
&.event-last::after,
&:first-child::before,
&:first-child::after,
&:has(.thinking-event)::before,
&:has(.thinking-event)::after,
&:has(.answer-event)::before,
&:has(.answer-event)::after,
&:has(.tool-event)::before,
&:has(.tool-event)::after,
&:has(.plan-task-change-event)::before,
&:has(.plan-task-change-event)::after {
display: none !important;
content: none !important;
visibility: hidden !important;
opacity: 0 !important;
width: 0 !important;
height: 0 !important;
}
}
}
.intermediate-steps-collapsed {
@@ -1753,7 +1809,6 @@ const handleAddToKnowledge = (answerEvent: any) => {
}
&.thinking-active {
border-color: #07c05f;
box-shadow: 0 1px 3px rgba(7, 192, 95, 0.06);
}
}
@@ -2805,6 +2860,10 @@ const handleAddToKnowledge = (answerEvent: any) => {
position: relative;
animation: fadeInUp 0.3s ease-out;
&.no-timeline {
padding-left: 0;
}
// 方案1: 三个跳动的圆点
.loading-dots {
display: flex;
@@ -209,7 +209,6 @@ onMounted(async () => {
background: #ffffff;
border-radius: 8px;
padding: 1px 14px;
border-left: 3px solid #07c05f;
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
animation: fadeInUp 0.3s ease-out;
+72 -15
View File
@@ -11,15 +11,30 @@
</div>
<div class="refer_box" v-show="showReferBox">
<div v-for="(item, index) in session.knowledge_references" :key="index">
<t-popup overlayClassName="refer-to-layer" placement="bottom-left" width="400" :showArrow="false"
trigger="click">
<template #content>
<ContentPopup :content="safeProcessContent(item.content)" :is-html="true" />
</template>
<span class="doc">
{{ session.knowledge_references.length < 2 ? item.knowledge_title : `${index +
1}.${item.knowledge_title}` }} </span>
</t-popup>
<!-- Web search references: show URL and make it clickable -->
<template v-if="item.chunk_type === 'web_search'">
<a
:href="getWebSearchUrl(item)"
target="_blank"
rel="noopener noreferrer"
class="doc doc-web"
@click.stop
>
{{ session.knowledge_references.length < 2 ? getWebSearchDisplayText(item) : `${index + 1}.${getWebSearchDisplayText(item)}` }}
</a>
</template>
<!-- Regular knowledge references: show title with popup -->
<template v-else>
<t-popup overlayClassName="refer-to-layer" placement="bottom-left" width="400" :showArrow="false"
trigger="click">
<template #content>
<ContentPopup :content="safeProcessContent(item.content)" :is-html="true" />
</template>
<span class="doc">
{{ session.knowledge_references.length < 2 ? item.knowledge_title : `${index +
1}.${item.knowledge_title}` }} </span>
</t-popup>
</template>
</div>
</div>
</div>
@@ -52,16 +67,49 @@ const safeProcessContent = (content) => {
return sanitized.replace(/\n/g, '<br/>');
};
// 获取 web_search 类型的 URL
const getWebSearchUrl = (item) => {
// 优先使用 metadata.url,其次使用 id(如果 id 是 URL)
if (item.metadata?.url) {
return item.metadata.url;
}
if (item.id && (item.id.startsWith('http://') || item.id.startsWith('https://'))) {
return item.id;
}
return '#';
};
// 获取 web_search 类型的显示文本
const getWebSearchDisplayText = (item) => {
// 优先使用 knowledge_title,其次使用 metadata.title,最后使用 URL 的域名
if (item.knowledge_title) {
return item.knowledge_title;
}
if (item.metadata?.title) {
return item.metadata.title;
}
// 如果都没有,使用 URL 的域名部分
const url = getWebSearchUrl(item);
if (url && url !== '#') {
try {
const urlObj = new URL(url);
return urlObj.hostname;
} catch {
return url;
}
}
return 'Web Search Result';
};
</script>
<style lang="less" scoped>
.refer {
display: flex;
flex-direction: column;
font-size: 14px;
font-size: 12px;
width: 100%;
border-radius: 8px;
background-color: #ffffff;
border-left: 3px solid #07c05f;
box-shadow: 0 2px 4px rgba(7, 192, 95, 0.08);
overflow: hidden;
box-sizing: border-box;
@@ -72,7 +120,7 @@ const safeProcessContent = (content) => {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 14px;
padding: 6px 14px;
color: #333333;
font-weight: 500;
@@ -90,7 +138,7 @@ const safeProcessContent = (content) => {
span {
white-space: nowrap;
font-size: 14px;
font-size: 12px;
}
}
@@ -107,7 +155,7 @@ const safeProcessContent = (content) => {
}
.refer_box {
padding: 4px 14px 10px 14px;
padding: 4px 14px 4px 14px;
flex-direction: column;
border-top: 1px solid #f0f0f0;
}
@@ -135,13 +183,22 @@ const safeProcessContent = (content) => {
text-overflow: ellipsis;
line-height: 20px;
padding: 2px 0;
font-weight: 500;
transition: all 0.2s ease;
border-bottom: 1px solid transparent;
&:hover {
border-bottom-color: #07c05f;
}
&.doc-web {
// Web search links can be longer, allow wrapping if needed
white-space: normal;
word-break: break-all;
&:hover {
text-decoration: underline;
}
}
}
</style>
@@ -44,6 +44,17 @@
</div>
</div>
<!-- 模型推荐提示 -->
<div class="model-recommendation-box">
<div class="recommendation-header">
<t-icon name="info-circle" class="recommendation-icon" />
<span class="recommendation-title">{{ $t('agentSettings.modelRecommendation.title') }}</span>
</div>
<div class="recommendation-content">
<p>{{ $t('agentSettings.modelRecommendation.content') }}</p>
</div>
</div>
<div class="settings-group">
<!-- 最大迭代次数 -->
@@ -1969,6 +1980,44 @@ const handleConversationRerankModelChange = async (value: string) => {
}
}
.model-recommendation-box {
margin: 20px 0;
background: #f0fdf6;
border: 1px solid #d1fae5;
border-left: 3px solid #07C05F;
border-radius: 6px;
padding: 16px;
.recommendation-header {
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 8px;
.recommendation-icon {
font-size: 16px;
color: #07C05F;
flex-shrink: 0;
}
.recommendation-title {
font-size: 14px;
font-weight: 500;
color: #059669;
}
}
.recommendation-content {
font-size: 13px;
line-height: 1.6;
color: #065f46;
p {
margin: 0;
}
}
}
.settings-group {
display: flex;
flex-direction: column;