feat: 支持在消息流中展示@的知识库和文件
This commit is contained in:
@@ -28,7 +28,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; web_search_enabled?: boolean; summary_model_id?: string; mcp_service_ids?: string[]; method: string; url: string }) => {
|
||||
const startStream = async (params: { session_id: any; query: any; knowledge_base_ids?: string[]; knowledge_ids?: string[]; agent_enabled?: boolean; web_search_enabled?: 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 }) => {
|
||||
// 重置状态
|
||||
output.value = '';
|
||||
error.value = null;
|
||||
@@ -101,6 +101,10 @@ export function useStream() {
|
||||
if (params.mcp_service_ids !== undefined && params.mcp_service_ids.length > 0) {
|
||||
postBody.mcp_service_ids = params.mcp_service_ids;
|
||||
}
|
||||
// Include mentioned_items if provided (for displaying @mentions in chat)
|
||||
if (params.mentioned_items !== undefined && params.mentioned_items.length > 0) {
|
||||
postBody.mentioned_items = params.mentioned_items;
|
||||
}
|
||||
|
||||
await fetchEventSource(url, {
|
||||
method: params.method,
|
||||
|
||||
@@ -816,7 +816,14 @@ const createSession = (val: string) => {
|
||||
if (props.isReplying) {
|
||||
return MessagePlugin.error(t('input.messages.replying'));
|
||||
}
|
||||
emit('send-msg', val, selectedModelId.value);
|
||||
// 获取@提及的知识库和文件信息
|
||||
const mentionedItems = allSelectedItems.value.map(item => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
type: item.type,
|
||||
kb_type: item.type === 'kb' ? (item.kbType || 'document') : undefined
|
||||
}));
|
||||
emit('send-msg', val, selectedModelId.value, mentionedItems);
|
||||
clearvalue();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,121 @@
|
||||
<template>
|
||||
<div class="user_msg">
|
||||
{{ content }}
|
||||
<div class="user_msg_container">
|
||||
<!-- 显示@的知识库和文件 -->
|
||||
<div v-if="mentioned_items && mentioned_items.length > 0" class="mentioned_items">
|
||||
<span
|
||||
v-for="item in mentioned_items"
|
||||
:key="item.id"
|
||||
class="mentioned_tag"
|
||||
:class="[
|
||||
item.type === 'kb' ? (item.kb_type === 'faq' ? 'faq-tag' : 'kb-tag') : 'file-tag'
|
||||
]"
|
||||
>
|
||||
<span class="tag_icon">
|
||||
<t-icon v-if="item.type === 'kb'" :name="item.kb_type === 'faq' ? 'chat-bubble-help' : 'folder'" />
|
||||
<t-icon v-else name="file" />
|
||||
</span>
|
||||
<span class="tag_name">{{ item.name }}</span>
|
||||
</span>
|
||||
</div>
|
||||
<div class="user_msg">
|
||||
{{ content }}
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, defineProps } from "vue";
|
||||
import { defineProps } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
// 必填项
|
||||
content: {
|
||||
type: String,
|
||||
required: false
|
||||
},
|
||||
// @提及的知识库和文件
|
||||
mentioned_items: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: () => []
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<style scoped lang="less">
|
||||
.user_msg_container {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
gap: 6px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.mentioned_items {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 6px;
|
||||
justify-content: flex-end;
|
||||
max-width: 100%;
|
||||
margin-bottom: 2px;
|
||||
}
|
||||
|
||||
.mentioned_tag {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
padding: 4px 8px;
|
||||
border-radius: 6px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
max-width: 200px;
|
||||
cursor: default;
|
||||
transition: all 0.15s;
|
||||
background: var(--td-bg-color-secondarycontainer, #f3f3f3);
|
||||
border: 1px solid transparent;
|
||||
color: var(--td-text-color-primary, #333);
|
||||
|
||||
/* KB - Document (Greenish tint) */
|
||||
&.kb-tag {
|
||||
background: rgba(16, 185, 129, 0.08);
|
||||
color: #059669;
|
||||
|
||||
.tag_icon {
|
||||
color: #10b981;
|
||||
}
|
||||
}
|
||||
|
||||
/* KB - FAQ (Blueish tint) */
|
||||
&.faq-tag {
|
||||
background: rgba(0, 82, 217, 0.08);
|
||||
color: #0052d9;
|
||||
|
||||
.tag_icon {
|
||||
color: #0052d9;
|
||||
}
|
||||
}
|
||||
|
||||
/* File (Orange tint) */
|
||||
&.file-tag {
|
||||
background: rgba(237, 123, 47, 0.08);
|
||||
color: #e65100;
|
||||
|
||||
.tag_icon {
|
||||
color: #ed7b2f;
|
||||
}
|
||||
}
|
||||
|
||||
.tag_icon {
|
||||
font-size: 14px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.tag_name {
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: currentColor;
|
||||
}
|
||||
}
|
||||
|
||||
.user_msg {
|
||||
width: max-content;
|
||||
max-width: 776px;
|
||||
@@ -35,4 +136,4 @@ const props = defineProps({
|
||||
max-width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
</style>
|
||||
|
||||
@@ -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"></usermsg>
|
||||
<usermsg :content="session.content" :mentioned_items="session.mentioned_items"></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) => sendMsg(query, modelId)"
|
||||
@send-msg="(query, modelId, mentionedItems) => sendMsg(query, modelId, mentionedItems)"
|
||||
@stop-generation="handleStopGeneration"
|
||||
:isReplying="isReplying"
|
||||
:sessionId="session_id"
|
||||
@@ -296,11 +296,12 @@ const handleStopGeneration = () => {
|
||||
// API 调用成功后,后端的 stop 事件会清空它
|
||||
};
|
||||
|
||||
const sendMsg = async (value, modelId = '') => {
|
||||
const sendMsg = async (value, modelId = '', mentionedItems = []) => {
|
||||
userquery.value = value;
|
||||
isReplying.value = true;
|
||||
loading.value = true;
|
||||
messagesList.push({ content: value, role: 'user' });
|
||||
// 将@提及的知识库和文件信息存入用户消息
|
||||
messagesList.push({ content: value, role: 'user', mentioned_items: mentionedItems });
|
||||
scrollToBottom();
|
||||
|
||||
// Get agent mode status from settings store
|
||||
@@ -329,6 +330,7 @@ const sendMsg = async (value, modelId = '') => {
|
||||
web_search_enabled: webSearchEnabled,
|
||||
summary_model_id: modelId,
|
||||
mcp_service_ids: mcpServiceIds,
|
||||
mentioned_items: mentionedItems,
|
||||
query: value,
|
||||
method: 'POST',
|
||||
url: endpoint
|
||||
|
||||
Reference in New Issue
Block a user