-
+
{{ is_submit ? '已提交' : '提交' }}
@@ -16,7 +11,8 @@
import { computed, ref, inject } from 'vue'
import { MkDynamicsForm } from '@/components/mk-dynamics-form'
-const chat = inject
('chat')
+// 由 chat-panel 注入的通用「发起对话」函数
+const sendMessage = inject<(opts: any) => void>('sendMessage')
const props = defineProps<{
content: any
@@ -30,41 +26,25 @@ const form_data = computed({
get: () => (props.content.is_submit ? props.content.form_data : _form_data.value),
set: (v) => {
_form_data.value = v
- }
+ },
})
const dynamicsFormRef = ref()
+// 表单重提交是对同一条 chat_record 的续跑(newQuestion=false):
+// 不新增 question,续跑分片由 chat-panel 聚合回持有本表单的那条 assistant 消息。
const submit = async () => {
try {
await dynamicsFormRef.value?.validate()
_submit.value = true
-
- if (chat?.sendMessage) {
- // 确保有对话 ID
- if (!chat.currentChatId?.value && chat?.openChat) {
- await chat.openChat()
- }
-
- // 传递 position、chat_record_id、chunk_id
- const position = props.content.position || null
- const chatRecordId = props.content.chat_record_id || null
- const chunkId = props.content.id || null
-
- // form_data 只包含表单收集到的数据
- const formData = { ...form_data.value }
-
- // 使用 form_content_format 作为消息
- const message = props.content.form_content_format || '表单已提交'
-
- await chat.sendMessage(message, {
- re_chat: true,
- form_data: formData,
- position: position,
- chat_record_id: chatRecordId,
- chunk_id: chunkId,
- onScroll: () => chat.scrollToBottom?.()
- })
- }
+ sendMessage?.({
+ message: { content: '', type: 'QUESTION' },
+ newQuestion: false,
+ reChat: true,
+ formData: { ...form_data.value },
+ position: props.content.position || null,
+ chatRecordId: props.content.chat_record_id || null,
+ chunkId: props.content.id || null,
+ })
} catch (e) {
console.error('Form submit failed:', e)
_submit.value = false
diff --git a/ui/src/components/conversation/sidebar/index.vue b/ui/src/components/conversation/sidebar/index.vue
index 50278023348..97b66227917 100644
--- a/ui/src/components/conversation/sidebar/index.vue
+++ b/ui/src/components/conversation/sidebar/index.vue
@@ -112,6 +112,8 @@ const renamingId = ref(null)
const renameValue = ref('')
const handleSwitch = async (id: string) => {
+ // 切换会话丢弃当前未发送的暂存文件/输入,避免其 source_id 绑在旧会话上
+ store.resetComposer()
store.currentChatId.value = id
await store.switchConversation(id)
if (props.mode === 'drawer') emit('update:open', false)
@@ -128,8 +130,13 @@ const handleDelete = async (id: string) => {
}
const handleNew = () => {
- // 本地草稿:仅生成 chat_id 并清空消息,不请求后端 open(避免产生空会话)。
- store.newChat()
+ // 已在空白新对话(无消息)则不动:保留当前 chat_id 与暂存文件(幂等,避免连点/上传后再点导致 id 变化)。
+ // 只有从已有会话切回空白时才重置消息并清空暂存文件(旧文件的 source_id 绑在旧会话上)。
+ if (store.messages.value.length > 0) {
+ store.resetComposer()
+ store.currentChatId.value = ''
+ store.resetMsgState()
+ }
if (props.mode === 'drawer') emit('update:open', false)
}