feat: implement image upload and multimodal support

- Added functionality for image uploads in chat, allowing users to attach images for multimodal Q&A.
- Enhanced the input field to handle image selection via drag-and-drop and paste, with validation for file types and sizes.
- Updated the backend to process images alongside text queries, including support for image analysis.
- Introduced new UI components for image previews and management, improving user interaction with uploaded content.
- Added localization strings for image upload features and error messages, enhancing accessibility for users in multiple languages.

These changes significantly improve the chat experience by enabling users to incorporate images into their queries, facilitating richer interactions and responses.
This commit is contained in:
wizardchen
2026-03-11 17:17:32 +08:00
parent 8de1cfb6b5
commit 991bd29a14
42 changed files with 1554 additions and 226 deletions
+5
View File
@@ -35,6 +35,11 @@ export interface CustomAgentConfig {
// false: 根据 kb_selection_mode 自动检索知识库
retrieve_kb_only_when_mentioned?: boolean;
// ===== 图片上传/多模态设置 =====
image_upload_enabled?: boolean; // 是否启用图片上传(默认: false)
vlm_model_id?: string; // VLM模型ID(图片分析用)
image_storage_provider?: string; // 图片存储提供商
// ===== 文件类型限制 =====
// 支持的文件类型(如 ["csv", "xlsx", "xls"])
// 为空表示支持所有文件类型
+5 -1
View File
@@ -29,7 +29,7 @@ export function useStream() {
let renderTimer: number | null = null
// 启动流式请求
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; enable_memory?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; method: string; url: string }) => {
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; agent_id?: string; web_search_enabled?: boolean; enable_memory?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; mentioned_items?: Array<{id: string; name: string; type: string; kb_type?: string}>; images?: Array<{data: string}>; method: string; url: string }) => {
// 重置状态
output.value = '';
error.value = null;
@@ -114,6 +114,10 @@ export function useStream() {
if (params.mentioned_items !== undefined && params.mentioned_items.length > 0) {
postBody.mentioned_items = params.mentioned_items;
}
// Include images if provided (base64 data URIs for multimodal chat)
if (params.images !== undefined && params.images.length > 0) {
postBody.images = params.images;
}
await fetchEventSource(url, {
method: params.method,
+1
View File
@@ -22,6 +22,7 @@ export interface ModelConfig {
interface_type?: 'ollama' | 'openai'; // VLLM专用
parameter_size?: string; // Ollama模型参数大小 (e.g., "7B", "13B", "70B")
extra_config?: Record<string, string>; // Provider-specific configuration
supports_vision?: boolean; // Whether the model accepts image/multimodal input
};
is_default?: boolean;
is_builtin?: boolean;
+214 -2
View File
@@ -29,6 +29,48 @@ const { t } = useI18n();
let query = ref("");
const showKbSelector = ref(false);
// Image upload state
const uploadedImages = ref<Array<{ file: File; preview: string }>>([]);
const imageInputRef = ref<HTMLInputElement>();
const imageUploading = ref(false);
const handleImageSelect = (event: Event) => {
const input = event.target as HTMLInputElement;
if (!input.files) return;
addImageFiles(Array.from(input.files));
input.value = '';
};
const addImageFiles = (files: File[]) => {
if (!isImageUploadEnabledByAgent.value) return;
const allowed = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
const maxSize = 10 * 1024 * 1024;
for (const file of files) {
if (uploadedImages.value.length >= 5) {
MessagePlugin.warning(t('chat.imageTooMany'));
break;
}
if (!allowed.includes(file.type)) {
MessagePlugin.warning(t('chat.imageTypeSizeError'));
continue;
}
if (file.size > maxSize) {
MessagePlugin.warning(t('chat.imageTypeSizeError'));
continue;
}
uploadedImages.value.push({ file, preview: URL.createObjectURL(file) });
}
};
const removeImage = (index: number) => {
const removed = uploadedImages.value.splice(index, 1);
if (removed.length > 0) URL.revokeObjectURL(removed[0].preview);
};
const triggerImageUpload = () => {
imageInputRef.value?.click();
};
const atButtonRef = ref<HTMLElement>();
const showAgentModeSelector = ref(false);
const agentModeButtonRef = ref<HTMLElement>();
@@ -115,6 +157,11 @@ watch([selectedAgentId, agentKnowledgeBases, agentKBSelectionMode], ([newAgentId
if (showMention.value) {
loadMentionItems(mentionQuery.value, true);
}
// Clear images when switching to an agent that doesn't support image upload
if (!isImageUploadEnabledByAgent.value && uploadedImages.value.length > 0) {
uploadedImages.value.forEach(img => URL.revokeObjectURL(img.preview));
uploadedImages.value = [];
}
}
}, { immediate: true });
@@ -177,6 +224,12 @@ const agentSupportedFileTypes = computed(() => {
return currentAgentConfig.value?.supported_file_types || [];
});
// 智能体是否启用了图片上传(多模态)
const isImageUploadEnabledByAgent = computed(() => {
if (!hasAgentConfig.value) return false;
return currentAgentConfig.value?.image_upload_enabled === true;
});
// 模型选择是否被智能体锁定 - 已移除锁定逻辑,允许用户自由切换模型
const isModelLockedByAgent = computed(() => {
return false;
@@ -1321,7 +1374,11 @@ const createSession = async (val: string) => {
type: item.type,
kb_type: item.type === 'kb' ? (item.kbType || 'document') : undefined
}));
emit('send-msg', val, selectedModelId.value, mentionedItems);
const imageFiles = uploadedImages.value.map(img => img.file);
emit('send-msg', val, selectedModelId.value, mentionedItems, imageFiles);
// Clean up image previews
uploadedImages.value.forEach(img => URL.revokeObjectURL(img.preview));
uploadedImages.value = [];
clearvalue();
}
@@ -1554,6 +1611,36 @@ const onKeydown = (val: string, event: { e: { preventDefault(): unknown; keyCode
}
}
const onPaste = (e: ClipboardEvent) => {
const items = e.clipboardData?.items;
if (!items) return;
const imageFiles: File[] = [];
for (const item of items) {
if (item.type.startsWith('image/')) {
const file = item.getAsFile();
if (file) imageFiles.push(file);
}
}
if (imageFiles.length > 0 && isImageUploadEnabledByAgent.value) {
e.preventDefault();
addImageFiles(imageFiles);
}
};
const onDrop = (e: DragEvent) => {
e.preventDefault();
const files = e.dataTransfer?.files;
if (!files) return;
const imageFiles = Array.from(files).filter(f => f.type.startsWith('image/'));
if (imageFiles.length > 0 && isImageUploadEnabledByAgent.value) {
addImageFiles(imageFiles);
}
};
const onDragOver = (e: DragEvent) => {
e.preventDefault();
};
const handleGoToWebSearchSettings = () => {
uiStore.openSettings('websearch');
if (route.path !== '/platform/settings') {
@@ -1732,9 +1819,25 @@ onBeforeRouteUpdate((to, from, next) => {
</script>
<template>
<div class="answers-input">
<div class="answers-input" @drop="onDrop" @dragover="onDragOver">
<!-- Hidden file input for image upload -->
<input
ref="imageInputRef"
type="file"
accept="image/jpeg,image/png,image/gif,image/webp"
multiple
style="display:none"
@change="handleImageSelect"
/>
<!-- 富文本输入框容器 -->
<div class="rich-input-container">
<!-- 图片预览区域 -->
<div v-if="uploadedImages.length > 0" class="image-preview-bar">
<div v-for="(img, idx) in uploadedImages" :key="idx" class="image-preview-item">
<img :src="img.preview" class="image-preview-thumb" />
<span class="image-preview-remove" @click="removeImage(idx)">×</span>
</div>
</div>
<!-- 选中的知识库和文件标签(显示在输入框内顶部) -->
<div v-if="allSelectedItems.length > 0" class="selected-tags-inline">
<span
@@ -1771,6 +1874,7 @@ onBeforeRouteUpdate((to, from, next) => {
@input="onInput"
@compositionstart="onCompositionStart"
@compositionend="onCompositionEnd"
@paste="onPaste"
/>
</div>
@@ -1867,6 +1971,32 @@ onBeforeRouteUpdate((to, from, next) => {
</div>
</t-tooltip>
<!-- 图片上传按钮 -->
<t-tooltip 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>
</template>
<div
class="control-btn image-upload-btn"
:class="{
'active': uploadedImages.length > 0,
'disabled': !isImageUploadEnabledByAgent
}"
@click.stop="isImageUploadEnabledByAgent && 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"/>
<path d="M352 448a96 96 0 1 0 0-192 96 96 0 0 0 0 192z"/>
<path d="M128 768l224-288 160 160 192-256L896 640v128H128z"/>
</svg>
<span v-if="uploadedImages.length > 0" class="image-count">{{ uploadedImages.length }}</span>
</div>
</t-tooltip>
<!-- @ 知识库/文件选择按钮 -->
<t-tooltip placement="top" theme="light" :popupProps="{ overlayClassName: 'input-field-tooltip' }">
<template #content>
@@ -2379,6 +2509,88 @@ const getImgSrc = (url: string) => {
color: var(--td-brand-color);
}
/* Image upload */
.image-upload-btn {
width: 28px;
height: 28px;
padding: 0;
min-width: auto;
display: flex;
align-items: center;
justify-content: center;
position: relative;
color: var(--td-text-color-secondary, #666);
&:hover {
background: var(--td-bg-color-secondarycontainer-hover, #f0f0f0);
color: var(--td-text-color-primary, #333);
}
&.active {
background: rgba(16, 185, 129, 0.1);
color: #07C05F;
}
.image-count {
position: absolute;
top: -2px;
right: -2px;
background: #07C05F;
color: #fff;
font-size: 10px;
width: 14px;
height: 14px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
line-height: 1;
}
}
.image-preview-bar {
display: flex;
gap: 8px;
padding: 8px 12px 4px;
flex-wrap: wrap;
}
.image-preview-item {
position: relative;
width: 60px;
height: 60px;
border-radius: 8px;
overflow: hidden;
border: 1px solid var(--td-border-level-1-color, #e7e7e7);
.image-preview-thumb {
width: 100%;
height: 100%;
object-fit: cover;
}
.image-preview-remove {
position: absolute;
top: 2px;
right: 2px;
width: 16px;
height: 16px;
background: rgba(0, 0, 0, 0.5);
color: #fff;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
font-size: 12px;
cursor: pointer;
line-height: 1;
&:hover {
background: rgba(0, 0, 0, 0.7);
}
}
}
.websearch-btn {
width: 28px;
height: 28px;
+14 -2
View File
@@ -230,6 +230,15 @@
</p>
</div>
<!-- Chat/VLLM: supports vision toggle -->
<div v-if="modelType === 'chat' || modelType === 'vllm'" class="form-item">
<label class="form-label">{{ $t('model.editor.supportsVisionLabel') }}</label>
<div style="display: flex; align-items: center; gap: 8px;">
<t-switch v-model="formData.supportsVision" />
<span class="form-desc">{{ $t('model.editor.supportsVisionDesc') }}</span>
</div>
</div>
</t-form>
</div>
@@ -266,6 +275,7 @@ interface ModelFormData {
dimension?: number
interfaceType?: 'ollama' | 'openai'
isDefault: boolean
supportsVision?: boolean
}
interface Props {
@@ -455,7 +465,8 @@ const formData = ref<ModelFormData>({
apiKey: '',
dimension: undefined,
interfaceType: 'ollama',
isDefault: false
isDefault: false,
supportsVision: false
})
const rules = computed(() => ({
@@ -597,7 +608,8 @@ const resetForm = () => {
apiKey: '',
dimension: undefined, // 默认不填,让用户手动输入或通过检测按钮获取
interfaceType: undefined,
isDefault: false
isDefault: false,
supportsVision: false
}
modelChecked.value = false
modelAvailable.value = false
+25
View File
@@ -279,6 +279,7 @@ export default {
agent: {
taskLabel: 'Task:',
think: 'Thinking',
copy: 'Copy',
addToKnowledgeBase: 'Add to Knowledge Base',
updatePlan: 'Update Plan',
@@ -1291,6 +1292,7 @@ export default {
cannotRemoveAgentKb: 'Cannot remove knowledge base configured by agent',
agentConfiguredKb: 'Configured by agent, cannot be removed',
modelLockedByAgent: 'Model selection is locked by the current agent',
imageUploadDisabledByAgent: 'Image upload is not enabled for this agent',
goToAgentSettings: 'Go to agent settings'
},
createChat: {
@@ -1778,6 +1780,9 @@ export default {
noAnswerContent: '(No answer content)',
noMatchFound: 'No matching content found',
deleteSessionFailed: 'Delete failed, please try again later!',
imageTooMany: 'Maximum 5 images allowed',
imageTypeSizeError: 'Only JPG/PNG/GIF/WEBP under 10MB supported',
imageUploadTooltip: 'Upload image (paste/drop supported)',
},
tenant: {
title: 'Tenant Information',
@@ -2025,6 +2030,8 @@ export default {
dimensionDetected: 'Detection succeeded. Vector dimension: {value}',
dimensionFailed: 'Detection failed, please enter the dimension manually',
remoteDimensionDetected: 'Detected vector dimension: {value}',
supportsVisionLabel: 'Supports Vision / Multimodal',
supportsVisionDesc: 'Whether the model accepts image and multimodal input',
dimensionHint: 'Model selected. Click "Detect Dimension" to fetch the vector dimension automatically.',
loadModelListFailed: 'Failed to load model list',
listRefreshed: 'List refreshed',
@@ -3106,6 +3113,7 @@ export default {
todoWrite: 'Plan Management',
knowledgeGraphExtract: 'Knowledge Graph Extraction',
thinking: 'Thinking',
imageAnalysis: 'Image Analysis',
},
summary: {
searchKb: 'Searched knowledge base <strong>{count}</strong> time(s)',
@@ -3153,6 +3161,9 @@ export default {
thinkingFailed: 'Thinking failed',
updateTodos: 'Updating task list',
updateTodosFailed: 'Failed to update task list',
imageAnalyzing: 'Viewing image content...',
imageAnalysisDone: 'Image content viewed',
imageAnalysisFailed: 'Image viewing failed',
called: 'Called {name}',
calledFailed: 'Failed to call {name}',
},
@@ -3240,6 +3251,20 @@ export default {
selectDesc: 'Select MCP services to enable',
selectPlaceholder: 'Select MCP services',
},
imageUpload: {
label: 'Image Upload',
desc: 'Allow users to upload images for multimodal Q&A in conversations',
vlmModel: 'VLM Model',
vlmModelDesc: 'Vision language model for image analysis',
vlmModelPlaceholder: 'Select VLM model',
vlmModelRequired: 'VLM model is required when image upload is enabled',
storageProvider: 'Image Storage',
storageProviderDesc: 'Storage engine for uploaded images. Leave empty to use system default',
storageProviderPlaceholder: 'Select storage engine',
storageDefault: 'System Default',
notConfigured: 'Not Configured',
goStorageSettings: 'Go to Storage Settings',
},
faq: {
title: 'FAQ Priority Strategy',
tooltip: 'When the knowledge base contains FAQ (Q&A pairs), enable this strategy to prioritize FAQ answers over regular documents',
+25
View File
@@ -387,6 +387,9 @@ export default {
noAnswerContent: "(无回答内容)",
noMatchFound: "未找到匹配的内容",
deleteSessionFailed: "删除失败,请稍后再试!",
imageTooMany: "最多上传5张图片",
imageTypeSizeError: "仅支持 JPG/PNG/GIF/WEBP 格式,单张不超过 10MB",
imageUploadTooltip: "上传图片(支持粘贴/拖拽)",
},
settings: {
title: "设置",
@@ -968,6 +971,7 @@ export default {
},
agent: {
taskLabel: "任务:",
think: "思考",
copy: "复制",
addToKnowledgeBase: "添加到知识库",
updatePlan: "更新计划",
@@ -1484,6 +1488,8 @@ export default {
dimensionDetected: "检测成功,向量维度:{value}",
dimensionFailed: "检测失败,请手动输入维度",
remoteDimensionDetected: "检测到向量维度:{value}",
supportsVisionLabel: "支持视觉/多模态",
supportsVisionDesc: "模型是否支持图片等多模态输入",
dimensionHint: '模型已选择,点击"检测维度"按钮自动获取向量维度',
loadModelListFailed: "加载模型列表失败",
listRefreshed: "列表已刷新",
@@ -2194,6 +2200,7 @@ export default {
cannotRemoveAgentKb: "智能体配置的知识库无法移除",
agentConfiguredKb: "由智能体配置,不可删除",
modelLockedByAgent: "当前智能体已锁定模型配置",
imageUploadDisabledByAgent: "当前智能体未启用图片上传",
goToAgentSettings: "去设置智能体",
},
agentSettings: {
@@ -3104,6 +3111,7 @@ export default {
todoWrite: "计划管理",
knowledgeGraphExtract: "知识图谱抽取",
thinking: "思考",
imageAnalysis: "查看图片内容",
},
summary: {
searchKb: "检索知识库 <strong>{count}</strong> 次",
@@ -3151,6 +3159,9 @@ export default {
thinkingFailed: "思考失败",
updateTodos: "更新任务列表",
updateTodosFailed: "更新任务列表失败",
imageAnalyzing: "正在查看图片内容...",
imageAnalysisDone: "已查看图片内容",
imageAnalysisFailed: "图片内容查看失败",
called: "调用 {name}",
calledFailed: "调用 {name} 失败",
},
@@ -3238,6 +3249,20 @@ export default {
selectDesc: "选择要启用的 MCP 服务",
selectPlaceholder: "选择 MCP 服务",
},
imageUpload: {
label: "图片上传",
desc: "启用后用户可在对话中上传图片进行多模态问答",
vlmModel: "VLM 模型",
vlmModelDesc: "用于图片分析的视觉语言模型",
vlmModelPlaceholder: "请选择 VLM 模型",
vlmModelRequired: "启用图片上传时必须选择 VLM 模型",
storageProvider: "图片存储",
storageProviderDesc: "选择图片文件的存储引擎,留空则使用系统默认",
storageProviderPlaceholder: "选择存储引擎",
storageDefault: "系统默认",
notConfigured: "未配置",
goStorageSettings: "去存储设置中配置",
},
faq: {
title: "FAQ 优先策略",
tooltip: "当知识库中包含 FAQ(问答对)时,可以启用此策略让 FAQ 答案优先于普通文档",
+4 -1
View File
@@ -37,6 +37,7 @@ export const useMenuStore = defineStore('menuStore', () => {
const firstQuery = ref('')
const firstMentionedItems = ref<any[]>([])
const firstModelId = ref('')
const firstImageFiles = ref<any[]>([])
const prefillQuery = ref('')
const applyMenuTranslations = () => {
@@ -98,10 +99,11 @@ export const useMenuStore = defineStore('menuStore', () => {
isFirstSession.value = payload
}
const changeFirstQuery = (payload: string, mentionedItems: any[] = [], modelId: string = '') => {
const changeFirstQuery = (payload: string, mentionedItems: any[] = [], modelId: string = '', imageFiles: any[] = []) => {
firstQuery.value = payload
firstMentionedItems.value = mentionedItems
firstModelId.value = modelId
firstImageFiles.value = imageFiles
}
const setPrefillQuery = (q: string) => {
@@ -120,6 +122,7 @@ export const useMenuStore = defineStore('menuStore', () => {
firstQuery,
firstMentionedItems,
firstModelId,
firstImageFiles,
prefillQuery,
clearMenuArr,
updatemenuArr,
+125 -3
View File
@@ -318,6 +318,68 @@
<t-switch v-model="thinkingEnabled" />
</div>
</div>
<!-- 图片上传(多模态) -->
<div class="setting-row">
<div class="setting-info">
<label>{{ $t('agentEditor.imageUpload.label') }}</label>
<p class="desc">{{ $t('agentEditor.imageUpload.desc') }}</p>
</div>
<div class="setting-control">
<t-switch v-model="formData.config.image_upload_enabled" />
</div>
</div>
<!-- VLM模型(图片上传启用时) -->
<div v-if="formData.config.image_upload_enabled" class="setting-row">
<div class="setting-info">
<label>{{ $t('agentEditor.imageUpload.vlmModel') }} <span class="required">*</span></label>
<p class="desc">{{ $t('agentEditor.imageUpload.vlmModelDesc') }}</p>
</div>
<div class="setting-control">
<ModelSelector
model-type="VLLM"
:selected-model-id="formData.config.vlm_model_id"
:all-models="allModels"
@update:selected-model-id="(val: string) => formData.config.vlm_model_id = val"
@add-model="handleAddModel('vllm')"
:placeholder="$t('agentEditor.imageUpload.vlmModelPlaceholder')"
/>
</div>
</div>
<!-- 图片存储 Provider(图片上传启用时) -->
<div v-if="formData.config.image_upload_enabled" class="setting-row">
<div class="setting-info">
<label>{{ $t('agentEditor.imageUpload.storageProvider') }}</label>
<p class="desc">{{ $t('agentEditor.imageUpload.storageProviderDesc') }}</p>
</div>
<div class="setting-control" style="flex-direction: column; align-items: flex-end;">
<t-select
v-model="formData.config.image_storage_provider"
style="width: 280px;"
:placeholder="$t('agentEditor.imageUpload.storageProviderPlaceholder')"
clearable
>
<t-option value="" :label="$t('agentEditor.imageUpload.storageDefault')" />
<t-option
v-for="opt in imageStorageOptions"
:key="opt.value"
:value="opt.value"
:label="opt.label"
:disabled="opt.disabled"
>
<span class="select-option-with-tag">
<span>{{ opt.label }}</span>
<t-tag v-if="opt.disabled" theme="warning" variant="light" size="small">{{ $t('agentEditor.imageUpload.notConfigured') }}</t-tag>
</span>
</t-option>
</t-select>
<a href="javascript:void(0)" class="go-settings-link" @click.prevent="uiStore.openSettings('storage')">
{{ $t('agentEditor.imageUpload.goStorageSettings') }}
</a>
</div>
</div>
</div>
</div>
@@ -1066,7 +1128,7 @@ import { listModels, type ModelConfig } from '@/api/model';
import { listKnowledgeBases } from '@/api/knowledge-base';
import { listMCPServices, type MCPService } from '@/api/mcp-service';
import { listSkills, type SkillInfo } from '@/api/skill';
import { getAgentConfig, getConversationConfig } from '@/api/system';
import { getAgentConfig, getConversationConfig, getStorageEngineStatus, type StorageEngineStatusItem } from '@/api/system';
import { useUIStore } from '@/stores/ui';
import { useOrganizationStore } from '@/stores/organization';
import AgentAvatar from '@/components/AgentAvatar.vue';
@@ -1099,6 +1161,21 @@ const mcpOptions = ref<{ label: string; value: string }[]>([]);
const skillOptions = ref<{ name: string; description: string }[]>([]);
// 是否允许启用 Skills(取决于后端沙箱是否启用,disabled 时为 false;未请求前为 false 避免闪显)
const skillsAvailable = ref(false);
// 存储引擎可用状态(用于图片存储 provider 选择)
const storageEngineStatus = ref<StorageEngineStatusItem[]>([]);
const imageStorageOptions = computed(() => {
const statusMap: Record<string, boolean> = {};
for (const e of storageEngineStatus.value) {
statusMap[e.name] = e.available;
}
return [
{ value: 'local', label: t('settings.storage.engineLocal'), disabled: false },
{ value: 'minio', label: 'MinIO', disabled: statusMap.minio === false },
{ value: 'cos', label: t('settings.storage.engineCos'), disabled: statusMap.cos === false },
{ value: 'tos', label: t('settings.storage.engineTos'), disabled: statusMap.tos === false },
{ value: 's3', label: 'Amazon S3', disabled: statusMap.s3 === false },
];
});
// 系统默认配置(用于内置智能体显示默认提示词)
const defaultAgentSystemPrompt = ref(''); // Agent 模式的默认系统提示词(来自 agent-config)
@@ -1320,6 +1397,10 @@ const defaultFormData = {
// 知识库设置
kb_selection_mode: 'none' as 'all' | 'selected' | 'none',
knowledge_bases: [] as string[],
// 图片上传/多模态设置
image_upload_enabled: false,
vlm_model_id: '',
image_storage_provider: '',
// 文件类型限制
supported_file_types: [] as string[],
// FAQ 策略设置
@@ -1642,12 +1723,18 @@ watch(() => uiStore.showSettingsModal, async (visible, prevVisible) => {
// 从设置页面返回时(弹窗关闭),刷新模型列表
if (prevVisible && !visible && props.visible) {
try {
const models = await listModels();
const [models, statusRes] = await Promise.all([
listModels(),
getStorageEngineStatus(),
]);
if (models && models.length > 0) {
allModels.value = models;
}
if (statusRes?.data?.engines) {
storageEngineStatus.value = statusRes.data.engines;
}
} catch (e) {
console.warn('Failed to refresh models after settings closed', e);
console.warn('Failed to refresh data after settings closed', e);
}
}
});
@@ -1725,6 +1812,16 @@ const loadDependencies = async () => {
skillsAvailable.value = false;
}
// 加载存储引擎可用状态(用于图片存储 provider 选择)
try {
const statusRes = await getStorageEngineStatus();
if (statusRes?.data?.engines) {
storageEngineStatus.value = statusRes.data.engines;
}
} catch (e) {
console.warn('Failed to load storage engine status', e);
}
// 加载占位符定义(从统一 API)
try {
const placeholdersRes = await getPlaceholders();
@@ -2627,6 +2724,13 @@ const handleSave = async () => {
return;
}
// 校验 VLM 模型(当图片上传启用时必填)
if (formData.value.config.image_upload_enabled && !formData.value.config.vlm_model_id) {
MessagePlugin.error(t('agentEditor.imageUpload.vlmModelRequired'));
currentSection.value = 'model';
return;
}
// 校验 ReRank 模型(当需要时必填)
if (needsRerankModel.value && !formData.value.config.rerank_model_id) {
MessagePlugin.error(t('agent.editor.rerankModelRequired'));
@@ -2914,6 +3018,24 @@ const handleSave = async () => {
}
}
.select-option-with-tag {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
gap: 8px;
}
.go-settings-link {
font-size: 12px;
color: var(--td-brand-color);
margin-top: 4px;
text-decoration: none;
&:hover {
text-decoration: underline;
}
}
// 名称输入框带头像预览
.name-input-wrapper {
display: flex;
@@ -33,7 +33,7 @@
<div class="action-header" @click="toggleEvent(event.event_id)">
<div class="action-title">
<img class="action-title-icon" :src="thinkingIcon" alt="" />
<span class="action-name">{{ $t('agent.think') }}</span>
<span v-if="isEventExpanded(event.event_id)" class="action-name">{{ $t('agent.think') }}</span>
<span v-if="getThinkingSummary(event) && !isEventExpanded(event.event_id)" class="action-summary">{{ getThinkingSummary(event) }}</span>
</div>
<div v-if="event.content" class="action-show-icon">
@@ -134,12 +134,7 @@
<div class="detail-output">{{ event.output }}</div>
</div>
</div>
<div v-if="event.arguments && event.tool_name !== 'todo_write' && !event.display_type" class="tool-arguments-wrapper">
<div class="arguments-header">
<span class="arguments-label">{{ $t('agent.argumentsLabel') }}</span>
</div>
<pre class="detail-code">{{ formatJSON(event.arguments) }}</pre>
</div>
<!-- Raw arguments hidden for user-friendly display -->
</div>
</div>
</div>
@@ -296,12 +291,7 @@
</div>
</div>
<div v-if="event.arguments && event.tool_name !== 'todo_write' && !event.display_type" class="tool-arguments-wrapper">
<div class="arguments-header">
<span class="arguments-label">{{ $t('agent.argumentsLabel') }}</span>
</div>
<pre class="detail-code">{{ formatJSON(event.arguments) }}</pre>
</div>
<!-- Raw arguments hidden for user-friendly display -->
</div>
</div>
</div>
@@ -435,6 +425,7 @@ const TOOL_NAME_KEYS: Record<string, string> = {
todo_write: 'agentStream.tools.todoWrite',
knowledge_graph_extract: 'agentStream.tools.knowledgeGraphExtract',
thinking: 'agentStream.tools.thinking',
image_analysis: 'agentStream.tools.imageAnalysis',
};
const getLocalizedToolName = (toolName?: string | null): string => {
@@ -443,6 +434,42 @@ const getLocalizedToolName = (toolName?: string | null): string => {
return key ? t(key) : toolName;
};
const TOOL_NAME_DISPLAY: Record<string, string> = {
knowledge_search: '语义搜索',
search_knowledge: '语义搜索',
grep_chunks: '文本搜索',
list_knowledge_chunks: '阅读文档内容',
get_document_info: '获取文档信息',
query_knowledge_graph: '知识图谱查询',
web_search: '网络搜索',
web_fetch: '网页抓取',
todo_write: '制定计划',
final_answer: '生成回答',
thinking: '思考',
read_skill: '读取技能',
execute_skill_script: '执行技能脚本',
data_analysis: '数据分析',
data_schema: '数据结构',
database_query: '数据库查询',
image_analysis: '查看图片内容',
};
const UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/gi;
const ID_LABEL_RE = /\b(knowledge_base_id|knowledge_id|chunk_id|knowledge_base_ids)\s*[:=]\s*/gi;
const sanitizeForDisplay = (text: string): string => {
if (!text) return text;
let result = text;
for (const [name, display] of Object.entries(TOOL_NAME_DISPLAY)) {
result = result.replaceAll(name, display);
}
result = result.replace(ID_LABEL_RE, '');
result = result.replace(UUID_RE, '');
result = result.replace(/`\s*`/g, '');
result = result.replace(/\(\s*\)/g, '');
return result;
};
// 根元素引用
const rootElement = ref<HTMLElement | null>(null);
@@ -759,13 +786,12 @@ const getThinkingContent = (event: any): string => {
const getThinkingSummary = (event: any): string => {
const content = getThinkingContent(event);
if (!content) return '';
// Strip markdown formatting and take first meaningful line
const cleaned = content
.replace(/^#+\s+/gm, '') // remove heading markers
.replace(/\*\*/g, '') // remove bold
.replace(/\*/g, '') // remove italic
.replace(/`/g, '') // remove code ticks
.replace(/\n+/g, ' ') // collapse newlines
const cleaned = sanitizeForDisplay(content)
.replace(/^#+\s+/gm, '')
.replace(/\*\*/g, '')
.replace(/\*/g, '')
.replace(/`/g, '')
.replace(/\n+/g, ' ')
.trim();
if (cleaned.length <= 50) return cleaned;
return cleaned.slice(0, 50) + '...';
@@ -1321,12 +1347,12 @@ const preprocessMarkdown = (contentStr: string): string => {
);
};
// Get tokens from markdown content
// Get tokens from markdown content (with sanitization for user-friendly display)
const getTokens = (content: any) => {
const contentStr = typeof content === 'string' ? content : String(content || '');
if (!contentStr.trim()) return [];
const processed = preprocessMarkdown(contentStr);
const processed = preprocessMarkdown(sanitizeForDisplay(contentStr));
return marked.lexer(processed);
};
@@ -1524,6 +1550,8 @@ const getToolIcon = (toolName: string): string => {
return documentIcon;
} else if (toolName === 'todo_write') {
return fileAddIcon;
} else if (toolName === 'image_analysis') {
return thinkingIcon;
} else {
return documentIcon; // default icon
}
@@ -1621,6 +1649,9 @@ const getQueryText = (args: any): string => {
// Get tool title - prefer summary over description, add query for search tools
const getToolTitle = (event: any): string => {
if (event.pending) {
if (event.tool_name === 'image_analysis') {
return t('agentStream.toolStatus.imageAnalyzing');
}
const localizedName = getLocalizedToolName(event.tool_name);
return t('agentStream.toolStatus.calling', { name: localizedName });
}
@@ -1706,6 +1737,9 @@ const getToolTitle = (event: any): string => {
// Tool description
const getToolDescription = (event: any): string => {
if (event.pending) {
if (event.tool_name === 'image_analysis') {
return t('agentStream.toolStatus.imageAnalyzing');
}
const localizedName = getLocalizedToolName(event.tool_name);
return t('agentStream.toolStatus.calling', { name: localizedName });
}
@@ -1723,6 +1757,8 @@ const getToolDescription = (event: any): string => {
return success ? t('agentStream.toolStatus.thinkingDone') : t('agentStream.toolStatus.thinkingFailed');
} else if (toolName === 'todo_write') {
return success ? t('agentStream.toolStatus.updateTodos') : t('agentStream.toolStatus.updateTodosFailed');
} else if (toolName === 'image_analysis') {
return success ? t('agentStream.toolStatus.imageAnalysisDone') : t('agentStream.toolStatus.imageAnalysisFailed');
} else {
const localizedName = getLocalizedToolName(toolName);
return success ? t('agentStream.toolStatus.called', { name: localizedName }) : t('agentStream.toolStatus.calledFailed', { name: localizedName });
@@ -2121,7 +2157,6 @@ const handleAddToKnowledge = (answerEvent: any) => {
&.action-error {
border-left: 2px solid var(--td-error-color);
animation: shakeError 0.4s ease-out;
}
&.action-pending {
+69 -4
View File
@@ -1,5 +1,5 @@
<template>
<div class="user_msg_container">
<div class="user_msg_container" ref="containerRef">
<!-- 显示@的知识库和文件 -->
<div v-if="mentioned_items && mentioned_items.length > 0" class="mentioned_items">
<span
@@ -17,27 +17,70 @@
<span class="tag_name">{{ item.name }}</span>
</span>
</div>
<!-- 显示上传的图片 -->
<div v-if="hasImages" class="user_images">
<img
v-for="(img, idx) in props.images"
:key="idx"
:src="img.url"
class="user_image_thumb"
@click="previewImage($event)"
/>
</div>
<div class="user_msg">
{{ content }}
</div>
<picturePreview :reviewImg="reviewImg" :reviewUrl="reviewUrl" @closePreImg="closePreImg" />
</div>
</template>
<script setup>
import { defineProps } from "vue";
import { defineProps, computed, ref, watch, onMounted, nextTick } from "vue";
import { hydrateProtectedFileImages } from '@/utils/security';
import picturePreview from '@/components/picture-preview.vue';
const props = defineProps({
// 必填项
content: {
type: String,
required: false
},
// @提及的知识库和文件
mentioned_items: {
type: Array,
required: false,
default: () => []
},
images: {
type: Array,
required: false,
default: () => []
}
});
const containerRef = ref(null);
const hasImages = computed(() => props.images && props.images.length > 0);
const hydrateImages = async () => {
await nextTick();
await hydrateProtectedFileImages(containerRef.value);
};
watch(() => props.images, hydrateImages);
onMounted(hydrateImages);
const reviewImg = ref(false);
const reviewUrl = ref('');
const previewImage = (event) => {
const src = event.target?.src;
if (src) {
reviewUrl.value = src;
reviewImg.value = true;
}
};
const closePreImg = () => {
reviewImg.value = false;
reviewUrl.value = '';
};
</script>
<style scoped lang="less">
.user_msg_container {
@@ -125,6 +168,28 @@ const props = defineProps({
box-sizing: border-box;
}
.user_images {
display: flex;
flex-wrap: wrap;
gap: 6px;
justify-content: flex-end;
max-width: 100%;
}
.user_image_thumb {
width: 120px;
height: 120px;
object-fit: cover;
border-radius: 6px;
cursor: pointer;
border: 1px solid var(--td-border-level-2-color, #e7e7e7);
transition: opacity 0.2s;
&:hover {
opacity: 0.85;
}
}
html[theme-mode="dark"] {
.user_msg {
background: var(--td-brand-color-3);
+36 -7
View File
@@ -4,7 +4,7 @@
<div class="msg_list">
<div v-for="(session, id) in messagesList" :key='id'>
<div v-if="session.role == 'user'">
<usermsg :content="session.content" :mentioned_items="session.mentioned_items"></usermsg>
<usermsg :content="session.content" :mentioned_items="session.mentioned_items" :images="session.images"></usermsg>
</div>
<div v-if="session.role == 'assistant'">
<botmsg :content="session.content" :session="session" :user-query="getUserQuery(id)" @scroll-bottom="scrollToBottom"
@@ -23,7 +23,7 @@
</div>
<div style="min-height: 115px; margin: 16px auto 4px;width: 100%;max-width: 800px;">
<InputField
@send-msg="(query, modelId, mentionedItems) => sendMsg(query, modelId, mentionedItems)"
@send-msg="(query, modelId, mentionedItems, imageFiles) => sendMsg(query, modelId, mentionedItems, imageFiles)"
@stop-generation="handleStopGeneration"
:isReplying="isReplying"
:sessionId="session_id"
@@ -61,7 +61,7 @@ const useSettingsStoreInstance = useSettingsStore();
const uiStore = useUIStore();
const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
const { t } = useI18n();
const { menuArr, isFirstSession, firstQuery, firstMentionedItems, firstModelId } = storeToRefs(usemenuStore);
const { menuArr, isFirstSession, firstQuery, firstMentionedItems, firstModelId, firstImageFiles } = storeToRefs(usemenuStore);
const { output, onChunk, isStreaming, isLoading, error, startStream, stopStream } = useStream();
const route = useRoute();
const router = useRouter();
@@ -83,6 +83,15 @@ const handleKBEditorSuccess = (kbId) => {
navigateToKnowledgeBaseList(kbId)
}
function fileToBase64(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = () => resolve(reader.result);
reader.onerror = reject;
reader.readAsDataURL(file);
});
}
const getUserQuery = (index) => {
if (index <= 0) {
return '';
@@ -323,12 +332,31 @@ const handleStopGeneration = () => {
// API 调用成功后,后端的 stop 事件会清空它
};
const sendMsg = async (value, modelId = '', mentionedItems = []) => {
const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []) => {
userquery.value = value;
isReplying.value = true;
loading.value = true;
// Convert images to base64 data URIs for backend processing and local display
let imageAttachments = [];
let userImages = [];
if (imageFiles && imageFiles.length > 0) {
try {
for (const file of imageFiles) {
const dataURI = await fileToBase64(file);
imageAttachments.push({ data: dataURI });
userImages.push({ url: dataURI });
}
} catch (e) {
console.error('[Image] Failed to read images:', e);
loading.value = false;
isReplying.value = false;
return;
}
}
// 将@提及的知识库和文件信息存入用户消息
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems });
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems, images: userImages });
scrollToBottom();
// Get agent mode status from settings store
@@ -377,6 +405,7 @@ const sendMsg = async (value, modelId = '', mentionedItems = []) => {
summary_model_id: modelId,
mcp_service_ids: mcpServiceIds,
mentioned_items: mentionedItems,
images: imageAttachments.length > 0 ? imageAttachments : undefined,
query: value,
method: 'POST',
url: endpoint
@@ -953,8 +982,8 @@ onMounted(async () => {
checkmenuTitle(session_id.value)
if (firstQuery.value) {
scrollLock.value = true;
sendMsg(firstQuery.value, firstModelId.value || '', firstMentionedItems.value || []);
usemenuStore.changeFirstQuery('', [], '');
sendMsg(firstQuery.value, firstModelId.value || '', firstMentionedItems.value || [], firstImageFiles.value || []);
usemenuStore.changeFirstQuery('', [], '', []);
} else {
scrollLock.value = false;
let data = {
+6 -6
View File
@@ -39,11 +39,11 @@ const uiStore = useUIStore();
const { t } = useI18n();
const { navigateToKnowledgeBaseList } = useKnowledgeBaseCreationNavigation();
const sendMsg = (value: string, modelId: string, mentionedItems: any[]) => {
createNewSession(value, modelId, mentionedItems);
const sendMsg = (value: string, modelId: string, mentionedItems: any[], imageFiles: any[] = []) => {
createNewSession(value, modelId, mentionedItems, imageFiles);
}
async function createNewSession(value: string, modelId: string, mentionedItems: any[] = []) {
async function createNewSession(value: string, modelId: string, mentionedItems: any[] = [], imageFiles: any[] = []) {
const selectedKbs = settingsStore.settings.selectedKnowledgeBases || [];
const selectedFiles = settingsStore.settings.selectedFiles || [];
@@ -63,7 +63,7 @@ async function createNewSession(value: string, modelId: string, mentionedItems:
try {
const res = await createSessions(sessionData);
if (res.data && res.data.id) {
await navigateToSession(res.data.id, value, modelId, mentionedItems);
await navigateToSession(res.data.id, value, modelId, mentionedItems, imageFiles);
} else {
console.error('[createChat] Failed to create session');
MessagePlugin.error(t('createChat.messages.createFailed'));
@@ -74,7 +74,7 @@ async function createNewSession(value: string, modelId: string, mentionedItems:
}
}
const navigateToSession = async (sessionId: string, value: string, modelId: string, mentionedItems: any[]) => {
const navigateToSession = async (sessionId: string, value: string, modelId: string, mentionedItems: any[], imageFiles: any[] = []) => {
const now = new Date().toISOString();
let obj = {
title: t('createChat.newSessionTitle'),
@@ -87,7 +87,7 @@ const navigateToSession = async (sessionId: string, value: string, modelId: stri
};
usemenuStore.updataMenuChildren(obj);
usemenuStore.changeIsFirstSession(true);
usemenuStore.changeFirstQuery(value, mentionedItems, modelId);
usemenuStore.changeFirstQuery(value, mentionedItems, modelId, imageFiles);
router.push(`/platform/chat/${sessionId}`);
}
@@ -293,7 +293,8 @@ function convertToLegacyFormat(model: ModelConfig) {
apiKey: model.parameters.api_key || '',
provider: model.parameters.provider || '', // 添加 provider 字段
dimension: model.parameters.embedding_parameters?.dimension,
isBuiltin: model.is_builtin || false
isBuiltin: model.is_builtin || false,
supportsVision: model.parameters.supports_vision || false
}
}
@@ -408,6 +409,9 @@ const handleModelSave = async (modelData: any) => {
dimension: modelData.dimension,
truncate_prompt_tokens: 0
}
} : {}),
...((currentModelType.value === 'chat' || currentModelType.value === 'vllm') ? {
supports_vision: modelData.supportsVision ?? false
} : {})
}
}