fix: 修复智能体聊天图片能力判断

This commit is contained in:
2026-08-31 15:10:40 +08:00
parent 0cedf85729
commit f28e3919ac
5 changed files with 74 additions and 17 deletions

View File

@@ -2,6 +2,13 @@ import type { AgentInfo } from '../agents/types';
import { api } from '#/api/request'; import { api } from '#/api/request';
export type AgentChatAgentOption = Pick<
AgentInfo,
'avatar' | 'description' | 'id' | 'interactionConfigJson' | 'name'
> & {
supportImage?: boolean | null;
};
export interface RequestResult<T = any> { export interface RequestResult<T = any> {
data: T; data: T;
errorCode: number; errorCode: number;
@@ -74,9 +81,12 @@ export interface AgentChatCapabilityPayload {
} }
export function getPublishedAgents() { export function getPublishedAgents() {
return api.get<RequestResult<AgentInfo[]>>('/api/v1/agent/session/options', { return api.get<RequestResult<AgentChatAgentOption[]>>(
params: { publishedOnly: true }, '/api/v1/agent/session/options',
}); {
params: { publishedOnly: true },
},
);
} }
export function generateAgentSessionId() { export function generateAgentSessionId() {

View File

@@ -0,0 +1,32 @@
import { describe, expect, it } from 'vitest';
import {
AGENT_CHAT_ATTACHMENT_ACCEPT,
AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE,
AGENT_IMAGE_UNSUPPORTED_MESSAGE,
supportsAgentImageInput,
} from './imageCapability';
describe('agent chat image capability', () => {
it('仅允许明确启用图片能力的发布模型', () => {
expect(supportsAgentImageInput(true)).toBe(true);
expect(supportsAgentImageInput(false)).toBe(false);
expect(supportsAgentImageInput(null)).toBe(false);
expect(supportsAgentImageInput(undefined)).toBe(false);
});
it('附件选择器同时展示文档和图片格式', () => {
expect(AGENT_CHAT_ATTACHMENT_ACCEPT).toContain('.pdf');
expect(AGENT_CHAT_ATTACHMENT_ACCEPT).toContain('.png');
expect(AGENT_CHAT_ATTACHMENT_ACCEPT).toContain('image/png');
});
it('为视觉能力限制提供明确反馈', () => {
expect(AGENT_IMAGE_UNSUPPORTED_MESSAGE).toBe(
'当前大模型不支持视觉,无法上传图片',
);
expect(AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE).toBe(
'当前大模型不支持视觉,已添加的图片无法发送,请先移除',
);
});
});

View File

@@ -0,0 +1,14 @@
export const AGENT_CHAT_ATTACHMENT_ACCEPT =
'.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.md,.png,.jpg,.jpeg,.webp,.gif,.bmp,image/png,image/jpeg,image/webp,image/gif,image/bmp';
export const AGENT_IMAGE_UNSUPPORTED_MESSAGE =
'当前大模型不支持视觉,无法上传图片';
export const AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE =
'当前大模型不支持视觉,已添加的图片无法发送,请先移除';
export function supportsAgentImageInput(
supportImage?: boolean | null,
): boolean {
return supportImage === true;
}

View File

@@ -8,8 +8,7 @@ import type {
ChatTimelineToolApprovalPayload, ChatTimelineToolApprovalPayload,
} from '@easyflow/common-ui'; } from '@easyflow/common-ui';
import type { AgentInfo } from '../agents/types'; import type { AgentChatAgentOption, AgentChatSessionView } from './api';
import type { AgentChatSessionView } from './api';
import type { import type {
ChatInputTriggerGroup, ChatInputTriggerGroup,
@@ -78,6 +77,12 @@ import {
renameAgentSession, renameAgentSession,
saveAgentSessionExtraKnowledges, saveAgentSessionExtraKnowledges,
} from './api'; } from './api';
import {
AGENT_CHAT_ATTACHMENT_ACCEPT,
AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE,
AGENT_IMAGE_UNSUPPORTED_MESSAGE,
supportsAgentImageInput,
} from './imageCapability';
import { import {
isMissingAgentSessionError, isMissingAgentSessionError,
resolveAgentSessionErrorMessage, resolveAgentSessionErrorMessage,
@@ -86,7 +91,7 @@ import {
const route = useRoute(); const route = useRoute();
const router = useRouter(); const router = useRouter();
const agents = ref<AgentInfo[]>([]); const agents = ref<AgentChatAgentOption[]>([]);
const sessions = ref<AgentChatSessionView[]>([]); const sessions = ref<AgentChatSessionView[]>([]);
const timelineItems = ref<ChatTimelineItem[]>([]); const timelineItems = ref<ChatTimelineItem[]>([]);
const selectedAgentId = ref(''); const selectedAgentId = ref('');
@@ -122,9 +127,7 @@ const selectedAgent = computed(() =>
agents.value.find((agent) => String(agent.id) === selectedAgentId.value), agents.value.find((agent) => String(agent.id) === selectedAgentId.value),
); );
const selectedAgentImageSupport = computed(() => const selectedAgentImageSupport = computed(() =>
Boolean( supportsAgentImageInput(selectedAgent.value?.supportImage),
selectedAgent.value?.publishedSnapshotJson?.modelSummary?.supportImage,
),
); );
const supportedAttachmentFormats = computed(() => const supportedAttachmentFormats = computed(() =>
selectedAgentImageSupport.value === false selectedAgentImageSupport.value === false
@@ -614,7 +617,7 @@ async function handleAgentChange() {
selectedAgentImageSupport.value === false && selectedAgentImageSupport.value === false &&
composer.images.items.value.length > 0 composer.images.items.value.length > 0
) { ) {
ElMessage.warning('当前智能体不支持图片,请先移除图片'); ElMessage.warning(AGENT_IMAGE_REMOVE_REQUIRED_MESSAGE);
} }
} }
@@ -822,7 +825,7 @@ async function addImageFiles(files: File[]) {
if (selectedAgentImageSupport.value === false) { if (selectedAgentImageSupport.value === false) {
ElMessage.warning({ ElMessage.warning({
grouping: true, grouping: true,
message: `当前智能体不支持图片,支持:${CHAT_DOCUMENT_SUPPORTED_FORMATS}`, message: AGENT_IMAGE_UNSUPPORTED_MESSAGE,
}); });
return; return;
} }
@@ -1395,11 +1398,7 @@ onBeforeUnmount(() => {
ref="attachmentFileInputRef" ref="attachmentFileInputRef"
class="agent-chat__image-file-input" class="agent-chat__image-file-input"
type="file" type="file"
:accept=" :accept="AGENT_CHAT_ATTACHMENT_ACCEPT"
selectedAgentImageSupport === false
? '.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.md'
: '.pdf,.doc,.docx,.ppt,.pptx,.xls,.xlsx,.txt,.md,.png,.jpg,.jpeg,.webp,.gif,.bmp,image/png,image/jpeg,image/webp,image/gif,image/bmp'
"
multiple multiple
@change="handleAttachmentFiles" @change="handleAttachmentFiles"
/> />

View File

@@ -49,7 +49,9 @@ export function buildInteractionConfigPayload(
}; };
} }
export function resolveInteractionDisplay(agent?: AgentInfo) { export function resolveInteractionDisplay(
agent?: Pick<AgentInfo, 'interactionConfigJson' | 'name'>,
) {
const config = buildInteractionConfigPayload(agent?.interactionConfigJson); const config = buildInteractionConfigPayload(agent?.interactionConfigJson);
const agentName = String(agent?.name || '').trim() || '智能体'; const agentName = String(agent?.name || '').trim() || '智能体';
return { return {