feat(channel): add channel support across various components and locales

- Introduced a new `channel` field in multiple request and message structures to track the source channel (e.g., "web", "api", "im").
- Updated frontend API calls and chat components to include the `channel` parameter, ensuring consistent channel tracking in user messages.
- Enhanced localization files to support channel labels in English, Korean, Russian, and Chinese.
- Added database migration scripts to incorporate the `channel` column in the messages table, facilitating the storage of channel information.
- Refactored related functions and components to accommodate the new channel feature, improving overall message context and tracking.
This commit is contained in:
wizardchen
2026-03-24 19:01:40 +08:00
committed by lyingbug
parent de0169d7c0
commit 5b2ebd1f44
19 changed files with 99 additions and 5 deletions
+3 -2
View File
@@ -15,7 +15,7 @@ export async function generateSessionsTitle(session_id: string, data: any) {
}
export async function knowledgeChat(data: { session_id: string; query: string; }) {
return postChat(`/api/v1/knowledge-chat/${data.session_id}`, { query: data.query });
return postChat(`/api/v1/knowledge-chat/${data.session_id}`, { query: data.query, channel: "web" });
}
// Agent chat with streaming support
@@ -28,7 +28,8 @@ export async function agentChat(data: {
return postChat(`/api/v1/agent-chat/${data.session_id}`, {
query: data.query,
knowledge_base_ids: data.knowledge_base_ids,
agent_enabled: data.agent_enabled
agent_enabled: data.agent_enabled,
channel: "web"
});
}
+1
View File
@@ -118,6 +118,7 @@ export function useStream() {
if (params.images !== undefined && params.images.length > 0) {
postBody.images = params.images;
}
postBody.channel = "web";
await fetchEventSource(url, {
method: params.method,
+3
View File
@@ -1718,6 +1718,9 @@ export default {
referencesDocAndWebCount: 'Referenced {docCount} document(s) and {webCount} web page(s)',
referenceChunkCount: '{count} chunk(s)',
fallbackHint: 'No relevant content found in knowledge base. Above is a direct response from the model.',
channelWeb: 'Web',
channelApi: 'API',
channelIm: 'IM',
chunkLabel: 'Chunk {index}:',
navigateToDocument: 'View document details',
referenceIconAlt: 'Reference materials icon',
+3
View File
@@ -322,6 +322,9 @@ export default {
referencesDocAndWebCount: "{docCount}개 문서와 {webCount}개 웹페이지 참조",
referenceChunkCount: "{count}개 청크",
fallbackHint: "지식 베이스에서 관련 내용을 찾지 못했습니다. 위는 모델의 직접 응답입니다.",
channelWeb: "웹",
channelApi: "API",
channelIm: "IM",
chunkLabel: "청크 {index}:",
navigateToDocument: "문서 상세 보기",
referenceIconAlt: "참조 내용 아이콘",
+3
View File
@@ -1887,6 +1887,9 @@ export default {
referencesDocAndWebCount: 'Использовано {docCount} документ(ов) и {webCount} веб-страниц(ы)',
referenceChunkCount: '{count} фрагмент(ов)',
fallbackHint: 'В базе знаний не найдено релевантного содержимого. Выше представлен прямой ответ модели.',
channelWeb: 'Веб',
channelApi: 'API',
channelIm: 'IM',
chunkLabel: 'Фрагмент {index}:',
navigateToDocument: 'Просмотр документа',
referenceIconAlt: 'Иконка ссылок на материалы',
+3
View File
@@ -319,6 +319,9 @@ export default {
referencesDocAndWebCount: "引用了{docCount}篇文档和{webCount}条网页",
referenceChunkCount: "{count}个片段",
fallbackHint: "未从知识库中检索到相关内容,以上为模型直接回答",
channelWeb: "网页",
channelApi: "API",
channelIm: "IM",
chunkLabel: "片段{index}:",
navigateToDocument: "查看文档详情",
referenceIconAlt: "参考内容图标",
@@ -37,6 +37,9 @@
import { defineProps, computed, ref, watch, onMounted, nextTick } from "vue";
import { hydrateProtectedFileImages } from '@/utils/security';
import picturePreview from '@/components/picture-preview.vue';
import { useI18n } from 'vue-i18n';
const { t } = useI18n();
const props = defineProps({
content: {
@@ -52,9 +55,28 @@ const props = defineProps({
type: Array,
required: false,
default: () => []
},
channel: {
type: String,
required: false,
default: ''
}
});
const channelLabelMap = {
web: () => t('chat.channelWeb'),
api: () => t('chat.channelApi'),
im: () => t('chat.channelIm'),
};
const channelLabel = computed(() => {
if (!props.channel) return '';
const label = channelLabelMap[props.channel];
return typeof label === 'function' ? label() : (label || props.channel);
});
const channelClass = computed(() => props.channel ? `channel-${props.channel}` : '');
const containerRef = ref(null);
const hasImages = computed(() => props.images && props.images.length > 0);
@@ -190,6 +212,37 @@ const closePreImg = () => {
}
}
.channel_tag {
display: inline-flex;
align-items: center;
padding: 1px 6px;
border-radius: 3px;
font-size: 11px;
font-weight: 500;
line-height: 18px;
background: var(--td-bg-color-secondarycontainer);
color: var(--td-text-color-placeholder);
border: 1px solid var(--td-border-level-2-color, #e7e7e7);
&.channel-web {
color: var(--td-brand-color);
background: var(--td-brand-color-light);
border-color: var(--td-brand-color-2, rgba(0, 82, 217, 0.1));
}
&.channel-api {
color: var(--td-success-color);
background: var(--td-success-color-1, rgba(0, 168, 112, 0.06));
border-color: var(--td-success-color-2, rgba(0, 168, 112, 0.15));
}
&.channel-im {
color: var(--td-warning-color);
background: var(--td-warning-color-1, rgba(237, 123, 0, 0.06));
border-color: var(--td-warning-color-2, rgba(237, 123, 0, 0.15));
}
}
html[theme-mode="dark"] {
.user_msg {
background: var(--td-brand-color-3);
+1 -1
View File
@@ -355,7 +355,7 @@ const sendMsg = async (value, modelId = '', mentionedItems = [], imageFiles = []
}
// 将@提及的知识库和文件信息存入用户消息
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems, images: userImages });
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems, images: userImages, channel: 'web' });
scrollToBottom();
// Get agent mode status from settings store