fix(agent): gate web search controls by provider readiness

This commit is contained in:
wizardchen
2026-07-08 00:22:46 +08:00
committed by lyingbug
parent 3209ed77fd
commit 15b81d1581
8 changed files with 277 additions and 53 deletions
+120 -15
View File
@@ -131,9 +131,6 @@
</span>
<span v-if="getKbCapability(activeDetail.agent)" class="detail-tag">{{ getKbCapability(activeDetail.agent)
}}</span>
<span v-if="activeDetail.agent.config?.web_search_enabled" class="detail-tag">{{
$t('agent.capabilities.webSearchOn')
}}</span>
<span v-if="getMcpCapability(activeDetail.agent)" class="detail-tag">{{ getMcpCapability(activeDetail.agent)
}}</span>
<span v-if="activeDetail.agent.config?.multi_turn_enabled" class="detail-tag">{{
@@ -141,6 +138,24 @@
}}</span>
</div>
<div class="detail-tag-group">
<div class="detail-tag-group-title">{{ $t('agent.selector.capabilitiesSection') }}</div>
<div class="detail-tags detail-tags--capabilities">
<span class="detail-tag detail-capability-tag"
:class="isWebSearchReadyForAgent(activeDetail.agent) ? 'detail-tag--on' : 'detail-tag--off'">
<TIcon :name="isWebSearchReadyForAgent(activeDetail.agent) ? 'check' : 'close'" size="12px"
class="detail-capability-icon" />
<span>{{ getWebSearchCapability(activeDetail.agent) }}</span>
</span>
<span class="detail-tag detail-capability-tag"
:class="isImageUploadEnabledForAgent(activeDetail.agent) ? 'detail-tag--on' : 'detail-tag--off'">
<TIcon :name="isImageUploadEnabledForAgent(activeDetail.agent) ? 'check' : 'close'" size="12px"
class="detail-capability-icon" />
<span>{{ getImageUploadCapability(activeDetail.agent) }}</span>
</span>
</div>
</div>
<div v-if="activeDetail.sharedMeta?.org_name || activeDetail.sharedMeta?.shared_by_username"
class="detail-meta">
<div v-if="activeDetail.sharedMeta.org_name" class="detail-meta-row">
@@ -178,11 +193,17 @@ import {
type AgentNotReadyReasonKey,
} from '@/utils/agent-readiness';
import { formatLocalizedList } from '@/utils/format-list';
import { useChatResourcesStore } from '@/stores/chatResources';
import {
isAgentWebSearchEnabled,
isAgentWebSearchReady,
} from '@/utils/agentWebSearch';
const { t, locale } = useI18n();
const router = useRouter();
const orgStore = useOrganizationStore();
const settingsStore = useSettingsStore();
const chatResources = useChatResourcesStore();
const props = defineProps<{
visible: boolean;
@@ -216,10 +237,11 @@ const detailPanelStyle = ref<Record<string, string>>({});
let detailHideTimer: ReturnType<typeof setTimeout> | null = null;
const DETAIL_PANEL_WIDTH = 200;
const DETAIL_BRIDGE_OVERLAP = 10;
const DETAIL_PANEL_GAP = 8;
const DETAIL_HIDE_DELAY_MS = 400;
const agentsList = computed(() => props.agents ?? []);
const webSearchProviders = computed(() => chatResources.webSearchProviders);
const builtinAgents = computed(() => {
const apiBuiltins = agentsList.value.filter(a => a.is_builtin);
@@ -289,6 +311,35 @@ const getKbCapability = (agent: CustomAgent): string => {
return '';
};
const isWebSearchEnabledForAgent = (agent: CustomAgent): boolean => {
return isAgentWebSearchEnabled(agent.config);
};
const isWebSearchReadyForAgent = (agent: CustomAgent): boolean => {
return isAgentWebSearchReady(agent.config, webSearchProviders.value);
};
const isImageUploadEnabledForAgent = (agent: CustomAgent): boolean => {
const config = agent.config || {};
return config.image_upload_enabled === true;
};
const getWebSearchCapability = (agent: CustomAgent): string => {
if (!isWebSearchEnabledForAgent(agent)) {
return t('agent.capabilities.webSearchOff');
}
if (!isWebSearchReadyForAgent(agent)) {
return t('agent.capabilities.webSearchUnconfigured');
}
return t('agent.capabilities.webSearchOn');
};
const getImageUploadCapability = (agent: CustomAgent): string => {
return isImageUploadEnabledForAgent(agent)
? t('agent.capabilities.imageUploadOn')
: t('agent.capabilities.imageUploadOff');
};
const getMcpCapability = (agent: CustomAgent): string => {
const config = agent.config || {};
if (config.mcp_selection_mode === 'none' || (!config.mcp_services?.length && config.mcp_selection_mode !== 'all')) {
@@ -359,8 +410,8 @@ const updateDetailPanelPosition = () => {
const rowRect = rectToCssPx(el.getBoundingClientRect(), zoom);
const { width: vw, height: vh } = cssViewportSize(zoom);
// 向左重叠一段透明区域,避免鼠标从选项移向浮层时经过空隙触发 mouseleave
let left = rowRect.right - DETAIL_BRIDGE_OVERLAP;
// 浮层显示在列表右侧,保留小间隙;透明桥接区覆盖间隙,避免鼠标移入时浮层消失
let left = rowRect.right + DETAIL_PANEL_GAP;
if (left + DETAIL_PANEL_WIDTH > vw - 8) {
left = Math.max(8, vw - DETAIL_PANEL_WIDTH - 8);
}
@@ -478,7 +529,7 @@ const updateDropdownPosition = () => {
const rect = rectToCssPx(props.anchorEl.getBoundingClientRect(), zoom);
const { width: vw, height: vh } = cssViewportSize(zoom);
const dropdownWidth = 196;
const dropdownWidth = 220;
const offsetY = 6;
let left = Math.floor(rect.left);
@@ -524,6 +575,7 @@ const updateDropdownPosition = () => {
watch(() => props.visible, (newVal) => {
if (newVal) {
nextTick(() => updateDropdownPosition());
chatResources.ensureWebSearchProviders();
} else {
hideDetailPanel();
}
@@ -583,8 +635,8 @@ watch(activeDetail, (detail) => {
align-items: center;
justify-content: space-between;
gap: 8px;
min-height: 32px;
padding: 0 8px;
min-height: 36px;
padding: 8px 12px;
border-bottom: .5px solid var(--td-component-stroke);
font-size: 12px;
font-weight: 500;
@@ -618,7 +670,7 @@ watch(activeDetail, (detail) => {
overflow-y: auto;
overscroll-behavior: contain;
-webkit-overflow-scrolling: touch;
padding: 4px 0;
padding: 6px 4px 8px;
}
.agent-group {
@@ -632,7 +684,7 @@ watch(activeDetail, (detail) => {
.agent-group-title {
font-size: 11px;
color: var(--td-text-color-placeholder);
padding: 6px 8px 4px;
padding: 8px 12px 4px;
font-weight: 600;
line-height: 16px;
}
@@ -641,8 +693,9 @@ watch(activeDetail, (detail) => {
display: flex;
align-items: center;
gap: 8px;
min-height: 32px;
padding: 0 8px;
min-height: 34px;
margin: 0 4px;
padding: 6px 8px;
cursor: pointer;
transition: background 0.12s;
border-radius: 5px;
@@ -761,14 +814,16 @@ watch(activeDetail, (detail) => {
.agent-detail-panel {
box-sizing: border-box;
position: relative;
--detail-panel-gap: 8px;
--detail-bridge-width: 8px;
// 左侧透明桥接区:承接从选项移入的鼠标,避免经过间隙时浮层消失
&::before {
content: '';
position: absolute;
left: -12px;
left: calc(-1 * (var(--detail-bridge-width) + var(--detail-panel-gap)));
top: 0;
width: 12px;
width: calc(var(--detail-bridge-width) + var(--detail-panel-gap));
height: 100%;
}
}
@@ -913,6 +968,25 @@ watch(activeDetail, (detail) => {
gap: 6px;
padding-top: 8px;
border-top: .5px solid var(--td-component-stroke);
&--capabilities {
padding-top: 0;
border-top: none;
}
}
.detail-tag-group {
margin-top: 8px;
padding-top: 8px;
border-top: .5px solid var(--td-component-stroke);
}
.detail-tag-group-title {
font-size: 11px;
font-weight: 600;
line-height: 16px;
color: var(--td-text-color-placeholder);
margin-bottom: 6px;
}
.detail-tag {
@@ -927,6 +1001,37 @@ watch(activeDetail, (detail) => {
background: var(--td-bg-color-secondarycontainer);
}
.detail-capability-tag {
gap: 4px;
padding: 3px 8px;
&--on {
color: var(--td-text-color-secondary);
border-color: var(--td-component-border);
background: var(--td-bg-color-secondarycontainer);
.detail-capability-icon {
color: var(--td-text-color-primary);
}
}
&--off {
color: var(--td-text-color-placeholder);
border-style: dashed;
border-color: var(--td-component-stroke);
background: transparent;
.detail-capability-icon {
color: var(--td-text-color-placeholder);
}
}
}
.detail-capability-icon {
flex-shrink: 0;
line-height: 1;
}
.detail-meta {
margin-top: 8px;
padding-top: 8px;
+45 -38
View File
@@ -28,6 +28,11 @@ import {
toolsConsumeFiles,
type ScopeCapabilities,
} from '@/utils/tool-capabilities';
import {
isAgentWebSearchEnabled,
isAgentWebSearchReady,
isTenantWebSearchReady,
} from '@/utils/agentWebSearch';
import {
getAgentNotReadyReasonKeys,
resolveAgentNotReadySection,
@@ -258,20 +263,15 @@ watch([selectedAgentId, () => settingsStore.selectedAgentSourceTenantId], async
}
}, { immediate: true });
// 智能体是否启用了网络搜索
const agentWebSearchEnabled = computed(() => {
if (!hasAgentConfig.value) return null; // null 表示不受智能体控制
return currentAgentConfig.value?.web_search_enabled ?? true;
// 智能体是否启用了网络搜索(仅显式开启才算支持)
const isWebSearchEnabledByAgent = computed(() => {
if (!hasAgentConfig.value) return null;
return isAgentWebSearchEnabled(currentAgentConfig.value);
});
const agentWebSearchProviderId = computed(() => {
if (!hasAgentConfig.value) return '';
return currentAgentConfig.value?.web_search_provider_id || '';
});
// 网络搜索是否被智能体禁用(只读状态)- 只有明确设置为 false 时才禁用
// 网络搜索是否被智能体禁用
const isWebSearchDisabledByAgent = computed(() => {
return hasAgentConfig.value && agentWebSearchEnabled.value === false;
return hasAgentConfig.value && isWebSearchEnabledByAgent.value !== true;
});
// 知识库选择是否被智能体锁定
@@ -433,6 +433,15 @@ const isImageUploadEnabledByAgent = computed(() => {
return currentAgentConfig.value?.image_upload_enabled === true;
});
// Input 工具栏:仅当智能体已启用且搜索引擎可用时才显示
const showWebSearchButton = computed(() => {
if (!hasAgentConfig.value) {
return isTenantWebSearchReady(webSearchProviders.value);
}
return isAgentWebSearchReady(currentAgentConfig.value, webSearchProviders.value);
});
const showImageUploadButton = computed(() => isImageUploadEnabledByAgent.value);
// 模型选择是否被智能体锁定 - 已移除锁定逻辑,允许用户自由切换模型
const isModelLockedByAgent = computed(() => {
return false;
@@ -791,12 +800,10 @@ watch(selectedFileIds, () => {
}, { immediate: true });
const isWebSearchConfigured = computed(() => {
const agentProviderId = agentWebSearchProviderId.value;
if (agentProviderId) {
return webSearchProviders.value.some(p => p.id === agentProviderId);
if (hasAgentConfig.value) {
return isAgentWebSearchReady(currentAgentConfig.value, webSearchProviders.value);
}
return webSearchProviders.value.some(p => p.is_default);
return isTenantWebSearchReady(webSearchProviders.value);
});
const loadWebSearchConfig = async (force = false) => {
@@ -2215,6 +2222,14 @@ const handleGoToWebSearchSettings = () => {
}
};
const handleGoToWebSearchConfig = () => {
if (hasAgentConfig.value && selectedAgent.value) {
handleGoToAgentSettings('websearch');
return;
}
handleGoToWebSearchSettings();
};
const handleGoToAgentSettings = (section?: string) => {
const agent = selectedAgent.value;
if (!agent) {
@@ -2343,7 +2358,7 @@ const toggleWebSearch = () => {
href: '#',
onClick: (e: Event) => {
e.preventDefault();
handleGoToWebSearchSettings();
handleGoToWebSearchConfig();
},
style: 'color: var(--td-brand-color); text-decoration: none; font-weight: 500; cursor: pointer; align-self: flex-start;',
onMouseenter: (e: Event) => {
@@ -2352,7 +2367,7 @@ const toggleWebSearch = () => {
onMouseleave: (e: Event) => {
(e.target as HTMLElement).style.textDecoration = 'none';
}
}, t('input.goToSettings'))
}, t('input.goToAgentSettings'))
]);
MessagePlugin.warning({
content: () => messageContent,
@@ -2485,24 +2500,20 @@ defineExpose({
:currentAgentId="selectedAgentId" :agents="enabledAgents" :all-models="allModels"
@close="closeAgentModeSelector" @select="handleSelectAgent" @not-ready="handleAgentNotReady" />
<!-- WebSearch 开关按钮 -->
<t-tooltip placement="top" theme="light" :popupProps="{ overlayClassName: 'input-field-tooltip' }">
<!-- WebSearch 开关按钮(智能体未启用时不显示) -->
<t-tooltip v-if="showWebSearchButton" placement="top" theme="light"
:popupProps="{ overlayClassName: 'input-field-tooltip' }">
<template #content>
<div v-if="isWebSearchDisabledByAgent" class="tooltip-with-link">
<span>{{ $t('input.webSearchDisabledByAgent') }}</span>
<a href="#" @click.prevent="handleGoToAgentSettings('websearch')">{{ $t('input.goToAgentSettings')
}}</a>
</div>
<span v-else-if="isWebSearchConfigured">{{ isWebSearchEnabled ? $t('input.webSearch.toggleOff') :
<span v-if="isWebSearchConfigured">{{ isWebSearchEnabled ? $t('input.webSearch.toggleOff') :
$t('input.webSearch.toggleOn') }}</span>
<div v-else class="tooltip-with-link">
<span>{{ $t('input.webSearch.notConfigured') }}</span>
<a href="#" @click.prevent="handleGoToWebSearchSettings">{{ $t('input.goToSettings') }}</a>
<a href="#" @click.prevent="handleGoToWebSearchConfig">{{ $t('input.goToAgentSettings') }}</a>
</div>
</template>
<div class="control-btn websearch-btn" :class="{
'active': isWebSearchEnabled && isWebSearchConfigured,
'disabled': !isWebSearchConfigured || isWebSearchDisabledByAgent
'disabled': !isWebSearchConfigured
}" @click.stop="toggleWebSearch">
<svg width="18" height="18" viewBox="0 0 18 18" fill="none" xmlns="http://www.w3.org/2000/svg"
class="control-icon websearch-icon" :class="{ 'active': isWebSearchEnabled && isWebSearchConfigured }">
@@ -2517,19 +2528,15 @@ defineExpose({
</div>
</t-tooltip>
<!-- 图片上传按钮 -->
<t-tooltip placement="top" theme="light" :popupProps="{ overlayClassName: 'input-field-tooltip' }">
<!-- 图片上传按钮(智能体未启用时不显示) -->
<t-tooltip v-if="showImageUploadButton" placement="top" theme="light"
:popupProps="{ overlayClassName: 'input-field-tooltip' }">
<template #content>
<div v-if="!isImageUploadEnabledByAgent" class="tooltip-with-link">
<span>{{ $t('input.imageUploadDisabledByAgent') }}</span>
<a href="#" @click.prevent="handleGoToAgentSettings('model')">{{ $t('input.goToAgentSettings') }}</a>
</div>
<span v-else>{{ $t('chat.imageUploadTooltip') }}</span>
<span>{{ $t('chat.imageUploadTooltip') }}</span>
</template>
<div class="control-btn image-upload-btn" :class="{
'active': uploadedImages.length > 0,
'disabled': !isImageUploadEnabledByAgent
}" @click.stop="isImageUploadEnabledByAgent && triggerImageUpload()">
'active': uploadedImages.length > 0
}" @click.stop="triggerImageUpload()">
<svg width="18" height="18" viewBox="0 0 1024 1024" fill="currentColor" class="control-icon">
<path
d="M896 128H128c-35.3 0-64 28.7-64 64v640c0 35.3 28.7 64 64 64h768c35.3 0 64-28.7 64-64V192c0-35.3-28.7-64-64-64zM128 832V192h768l0.1 640H128z" />
+4
View File
@@ -924,6 +924,9 @@ export default {
rerankSpecified: 'ReRank model specified',
webSearchOn: 'Web search enabled',
webSearchOff: 'Web search disabled',
webSearchUnconfigured: 'Search engine not configured',
imageUploadOn: 'Image upload supported',
imageUploadOff: 'Image upload not supported',
hasPrompt: 'Custom prompt',
default: 'Default configuration',
mcpEnabled: 'MCP services enabled',
@@ -1151,6 +1154,7 @@ export default {
notReadyMissing: 'Missing: {items}',
configureAction: 'Configure',
sharedNotReadyContact: 'Ask the sharing organization admin to finish setup',
capabilitiesSection: 'Capabilities',
},
// Built-in agent information
builtinInfo: {
+4
View File
@@ -1929,6 +1929,9 @@ export default {
rerankSpecified: "ReRank 모델 지정",
webSearchOn: "웹 검색 활성화",
webSearchOff: "웹 검색 비활성화",
webSearchUnconfigured: "검색 엔진 미구성",
imageUploadOn: "이미지 업로드 지원",
imageUploadOff: "이미지 업로드 미지원",
hasPrompt: "맞춤 프롬프트",
default: "기본 구성",
mcpEnabled: "MCP 서비스 활성화",
@@ -2166,6 +2169,7 @@ export default {
notReadyMissing: "누락: {items}",
configureAction: "구성",
sharedNotReadyContact: "공유한 조직 관리자에게 구성을 요청하세요",
capabilitiesSection: "능력",
},
// 내장 에이전트 정보
builtinInfo: {
+4
View File
@@ -968,6 +968,9 @@ export default {
rerankSpecified: 'ReRank model specified',
webSearchOn: 'Web search enabled',
webSearchOff: 'Web search disabled',
webSearchUnconfigured: 'Поисковая система не настроена',
imageUploadOn: 'Загрузка изображений поддерживается',
imageUploadOff: 'Загрузка изображений не поддерживается',
hasPrompt: 'Custom prompt',
default: 'Default configuration',
mcpEnabled: 'MCP services enabled',
@@ -1065,6 +1068,7 @@ export default {
notReadyMissing: 'Missing: {items}',
configureAction: 'Configure',
sharedNotReadyContact: 'Ask the sharing organization admin to finish setup',
capabilitiesSection: 'Возможности',
},
builtinInfo: {
quickAnswer: {
+4
View File
@@ -1935,6 +1935,9 @@ export default {
rerankSpecified: "指定 ReRank 模型",
webSearchOn: "启用网络搜索",
webSearchOff: "禁用网络搜索",
webSearchUnconfigured: "未配置搜索引擎",
imageUploadOn: "支持图片上传",
imageUploadOff: "不支持图片上传",
hasPrompt: "自定义提示词",
default: "默认配置",
mcpEnabled: "启用 MCP 服务",
@@ -2162,6 +2165,7 @@ export default {
notReadyMissing: "缺少 {items}",
configureAction: "去配置",
sharedNotReadyContact: "请联系分享方管理员完成配置",
capabilitiesSection: "能力",
},
// 内置智能体信息
builtinInfo: {
@@ -0,0 +1,59 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import {
resolveAgentWebSearchProviderId,
isAgentWebSearchReady,
isTenantWebSearchReady,
} from './agentWebSearch.ts';
const providers = [
{ id: 'p1', name: 'Keenable', is_default: false },
{ id: 'p2', name: 'Default', is_default: true },
];
test('resolveAgentWebSearchProviderId uses explicit agent provider', () => {
assert.equal(
resolveAgentWebSearchProviderId({ web_search_provider_id: 'p1' }, providers),
'p1',
);
});
test('resolveAgentWebSearchProviderId falls back to tenant default', () => {
assert.equal(
resolveAgentWebSearchProviderId({ web_search_provider_id: '' }, providers),
'p2',
);
});
test('resolveAgentWebSearchProviderId returns null when default missing', () => {
const noDefault = [{ id: 'p1', name: 'Keenable', is_default: false }];
assert.equal(
resolveAgentWebSearchProviderId({ web_search_provider_id: '' }, noDefault),
null,
);
});
test('isAgentWebSearchReady requires enabled flag and resolvable provider', () => {
assert.equal(
isAgentWebSearchReady({ web_search_enabled: true }, providers),
true,
);
assert.equal(
isAgentWebSearchReady({ web_search_enabled: true, web_search_provider_id: '' }, [
{ id: 'p1', name: 'Keenable', is_default: false },
]),
false,
);
assert.equal(
isAgentWebSearchReady({ web_search_enabled: false }, providers),
false,
);
});
test('isTenantWebSearchReady checks default provider only', () => {
assert.equal(isTenantWebSearchReady(providers), true);
assert.equal(
isTenantWebSearchReady([{ id: 'p1', name: 'Keenable', is_default: false }]),
false,
);
});
+37
View File
@@ -0,0 +1,37 @@
import type { WebSearchProviderEntity } from '@/api/web-search-provider';
export type AgentWebSearchConfig = {
web_search_enabled?: boolean;
web_search_provider_id?: string;
};
/** 解析智能体实际会使用的搜索引擎 ID(与后端 agent > tenant default 逻辑一致) */
export function resolveAgentWebSearchProviderId(
config: AgentWebSearchConfig | undefined,
providers: WebSearchProviderEntity[],
): string | null {
const explicitId = config?.web_search_provider_id?.trim();
if (explicitId) {
return providers.some((p) => p.id === explicitId) ? explicitId : null;
}
const defaultProvider = providers.find((p) => p.is_default);
return defaultProvider?.id ?? null;
}
export function isAgentWebSearchEnabled(config: AgentWebSearchConfig | undefined): boolean {
return config?.web_search_enabled === true;
}
/** 智能体已启用网络搜索,且能解析到可用搜索引擎 */
export function isAgentWebSearchReady(
config: AgentWebSearchConfig | undefined,
providers: WebSearchProviderEntity[],
): boolean {
if (!isAgentWebSearchEnabled(config)) return false;
return resolveAgentWebSearchProviderId(config, providers) !== null;
}
/** 租户级默认搜索引擎是否可用(无智能体约束时) */
export function isTenantWebSearchReady(providers: WebSearchProviderEntity[]): boolean {
return providers.some((p) => p.is_default);
}