From d9a120442ce48600f2eb45df16e399d55a4faaaf Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Fri, 17 Jul 2026 10:39:35 +0800 Subject: [PATCH] feat: Refactor the front-end dialog box --- ui/src/components/chat-plus/api/chat.ts | 41 ++ ui/src/components/chat-plus/api/debug.ts | 44 ++ ui/src/components/chat-plus/api/index.ts | 8 + ui/src/components/chat-plus/bus.ts | 37 ++ .../component/answer-content/index.vue | 143 +++++++ .../answer-content/items/failure.vue | 10 + .../component/answer-content/items/form.vue | 62 +++ .../component/answer-content/items/index.vue | 22 + .../answer-content/items/reasoning.vue | 180 ++++++++ .../component/answer-content/items/text.vue | 20 + .../component/answer-content/items/tool.vue | 26 ++ .../chat-plus/component/chat-panel/index.vue | 167 ++++++++ .../component/conversation-list/index.vue | 64 +++ ui/src/components/chat-plus/composable.ts | 205 ++++++++++ ui/src/components/chat-plus/index.scss | 387 ++++++++++++++++++ ui/src/components/chat-plus/index.ts | 183 +++++++++ ui/src/components/chat-plus/index.vue | 228 +++++++++++ ui/src/components/conversation/api/index.ts | 54 +++ .../conversation/chat-panel/index.vue | 371 +++++++++++++++++ ui/src/components/conversation/composable.ts | 317 ++++++++++++++ .../conversation/content-list/index.vue | 28 ++ .../components/conversation/content/index.vue | 22 + .../conversation/content/items/failure.vue | 34 ++ .../conversation/content/items/form.vue | 89 ++++ .../conversation/content/items/reasoning.vue | 63 +++ .../conversation/content/items/text.vue | 20 + .../conversation/content/items/tool.vue | 74 ++++ .../components/conversation/editor/index.vue | 154 +++++++ ui/src/components/conversation/index.ts | 112 +++++ ui/src/components/conversation/index.vue | 234 +++++++++++ .../components/conversation/loading/index.vue | 56 +++ .../components/conversation/sidebar/index.vue | 265 ++++++++++++ ui/src/components/conversation/stream.ts | 134 ++++++ ui/src/components/markdown/MdRenderer.vue | 18 +- ui/src/views/application-workflow/index.vue | 57 +-- 35 files changed, 3878 insertions(+), 51 deletions(-) create mode 100644 ui/src/components/chat-plus/api/chat.ts create mode 100644 ui/src/components/chat-plus/api/debug.ts create mode 100644 ui/src/components/chat-plus/api/index.ts create mode 100644 ui/src/components/chat-plus/bus.ts create mode 100644 ui/src/components/chat-plus/component/answer-content/index.vue create mode 100644 ui/src/components/chat-plus/component/answer-content/items/failure.vue create mode 100644 ui/src/components/chat-plus/component/answer-content/items/form.vue create mode 100644 ui/src/components/chat-plus/component/answer-content/items/index.vue create mode 100644 ui/src/components/chat-plus/component/answer-content/items/reasoning.vue create mode 100644 ui/src/components/chat-plus/component/answer-content/items/text.vue create mode 100644 ui/src/components/chat-plus/component/answer-content/items/tool.vue create mode 100644 ui/src/components/chat-plus/component/chat-panel/index.vue create mode 100644 ui/src/components/chat-plus/component/conversation-list/index.vue create mode 100644 ui/src/components/chat-plus/composable.ts create mode 100644 ui/src/components/chat-plus/index.scss create mode 100644 ui/src/components/chat-plus/index.ts create mode 100644 ui/src/components/chat-plus/index.vue create mode 100644 ui/src/components/conversation/api/index.ts create mode 100644 ui/src/components/conversation/chat-panel/index.vue create mode 100644 ui/src/components/conversation/composable.ts create mode 100644 ui/src/components/conversation/content-list/index.vue create mode 100644 ui/src/components/conversation/content/index.vue create mode 100644 ui/src/components/conversation/content/items/failure.vue create mode 100644 ui/src/components/conversation/content/items/form.vue create mode 100644 ui/src/components/conversation/content/items/reasoning.vue create mode 100644 ui/src/components/conversation/content/items/text.vue create mode 100644 ui/src/components/conversation/content/items/tool.vue create mode 100644 ui/src/components/conversation/editor/index.vue create mode 100644 ui/src/components/conversation/index.ts create mode 100644 ui/src/components/conversation/index.vue create mode 100644 ui/src/components/conversation/loading/index.vue create mode 100644 ui/src/components/conversation/sidebar/index.vue create mode 100644 ui/src/components/conversation/stream.ts diff --git a/ui/src/components/chat-plus/api/chat.ts b/ui/src/components/chat-plus/api/chat.ts new file mode 100644 index 00000000000..97e461681cf --- /dev/null +++ b/ui/src/components/chat-plus/api/chat.ts @@ -0,0 +1,41 @@ +import { get, postStream, del, put, post } from '@/request/chat/index' + +const prefix = (window.MaxKB?.prefix || '/chat') + '/api' + +export const open = () => + get('/open', {}) + +export const chat = (chatId: string, data: any) => + postStream(`${prefix}/chat_message/${chatId}`, data) + +export const history = (page: number, size: number) => + get(`/historical_conversation/${page}/${size}`) + +export const records = (chatId: string, page: number, size: number) => + get(`/historical_conversation_record/${chatId}/${page}/${size}`) + +export const recordDetail = (chatId: string, recordId: string) => + get(`/historical_conversation/${chatId}/record/${recordId}`) + +export const vote = (chatId: string, recordId: string, voteStatus: string, reason?: string) => + put(`/vote/chat/${chatId}/chat_record/${recordId}`, { + vote_status: voteStatus, + ...(reason !== undefined && { vote_reason: reason }), + }) + +export const deleteChat = (chatId: string) => + del(`/historical_conversation/${chatId}`) + +export const clearChat = () => + del('/historical_conversation/clear') + +export const modifyChat = (chatId: string, data: any) => + put(`/historical_conversation/${chatId}`, data) + +export const uploadFile = (file: File, sourceId: string, sourceType: string) => { + const fd = new FormData() + fd.append('file', file) + fd.append('source_id', sourceId) + fd.append('source_type', sourceType) + return post('/oss/file', fd) +} diff --git a/ui/src/components/chat-plus/api/debug.ts b/ui/src/components/chat-plus/api/debug.ts new file mode 100644 index 00000000000..4cdf5ec570b --- /dev/null +++ b/ui/src/components/chat-plus/api/debug.ts @@ -0,0 +1,44 @@ +import { get, postStream, del, put, post } from '@/request/index' +import useStore from '@/stores' + +const prefix = (window.MaxKB?.prefix || '/admin') + '/api' + +export const open = (applicationId: string) => { + const { user } = useStore() + return get(`/workspace/${user.getWorkspaceId()}/application/${applicationId}/open`, {}) +} + +export const chat = (chatId: string, data: any) => + postStream(`${prefix}/chat_message/${chatId}`, data) + +export const history = (page: number, size: number) => + get(`/historical_conversation/${page}/${size}`) + +export const records = (chatId: string, page: number, size: number) => + get(`/historical_conversation_record/${chatId}/${page}/${size}`) + +export const recordDetail = (chatId: string, recordId: string) => + get(`/historical_conversation/${chatId}/record/${recordId}`) + +export const vote = (chatId: string, recordId: string, voteStatus: string, reason?: string) => + put(`/vote/chat/${chatId}/chat_record/${recordId}`, { + vote_status: voteStatus, + ...(reason !== undefined && { vote_reason: reason }), + }) + +export const deleteChat = (chatId: string) => + del(`/historical_conversation/${chatId}`) + +export const clearChat = () => + del('/historical_conversation/clear') + +export const modifyChat = (chatId: string, data: any) => + put(`/historical_conversation/${chatId}`, data) + +export const uploadFile = (file: File, sourceId: string, sourceType: string) => { + const fd = new FormData() + fd.append('file', file) + fd.append('source_id', sourceId) + fd.append('source_type', sourceType) + return post('/oss/file', fd) +} diff --git a/ui/src/components/chat-plus/api/index.ts b/ui/src/components/chat-plus/api/index.ts new file mode 100644 index 00000000000..a86043a06fd --- /dev/null +++ b/ui/src/components/chat-plus/api/index.ts @@ -0,0 +1,8 @@ +import * as chat from './chat' +import * as debug from './debug' + +export type ChatType = 'CHAT' | 'DEBUG' + +const apis = { CHAT: chat, DEBUG: debug } as const + +export const useApi = (type: ChatType) => apis[type] diff --git a/ui/src/components/chat-plus/bus.ts b/ui/src/components/chat-plus/bus.ts new file mode 100644 index 00000000000..6d726947149 --- /dev/null +++ b/ui/src/components/chat-plus/bus.ts @@ -0,0 +1,37 @@ +type Handler = (...args: any[]) => void + +class ChatBus { + private events = new Map>() + + on(event: string, handler: Handler) { + if (!this.events.has(event)) { + this.events.set(event, new Set()) + } + this.events.get(event)!.add(handler) + return () => this.off(event, handler) + } + + off(event: string, handler: Handler) { + this.events.get(event)?.delete(handler) + } + + emit(event: string, ...args: any[]) { + this.events.get(event)?.forEach((handler) => handler(...args)) + } + + clear() { + this.events.clear() + } +} + +export const chatBus = new ChatBus() + +export const ChatEvents = { + OPEN_CONVERSATION: 'open:conversation', + NEW_CONVERSATION: 'new:conversation', + DELETE_CONVERSATION: 'delete:conversation', + RENAME_CONVERSATION: 'rename:conversation', + SEND_MESSAGE: 'send:message', + STOP_GENERATING: 'stop:generating', + REFRESH_LIST: 'refresh:list', +} as const diff --git a/ui/src/components/chat-plus/component/answer-content/index.vue b/ui/src/components/chat-plus/component/answer-content/index.vue new file mode 100644 index 00000000000..53870d4f08d --- /dev/null +++ b/ui/src/components/chat-plus/component/answer-content/index.vue @@ -0,0 +1,143 @@ + + + diff --git a/ui/src/components/chat-plus/component/answer-content/items/failure.vue b/ui/src/components/chat-plus/component/answer-content/items/failure.vue new file mode 100644 index 00000000000..d06fd85168b --- /dev/null +++ b/ui/src/components/chat-plus/component/answer-content/items/failure.vue @@ -0,0 +1,10 @@ + + + diff --git a/ui/src/components/chat-plus/component/answer-content/items/form.vue b/ui/src/components/chat-plus/component/answer-content/items/form.vue new file mode 100644 index 00000000000..008c54a558d --- /dev/null +++ b/ui/src/components/chat-plus/component/answer-content/items/form.vue @@ -0,0 +1,62 @@ + + + + diff --git a/ui/src/components/chat-plus/component/answer-content/items/index.vue b/ui/src/components/chat-plus/component/answer-content/items/index.vue new file mode 100644 index 00000000000..a61d04a6fcf --- /dev/null +++ b/ui/src/components/chat-plus/component/answer-content/items/index.vue @@ -0,0 +1,22 @@ + + + diff --git a/ui/src/components/chat-plus/component/answer-content/items/reasoning.vue b/ui/src/components/chat-plus/component/answer-content/items/reasoning.vue new file mode 100644 index 00000000000..288b21a30bf --- /dev/null +++ b/ui/src/components/chat-plus/component/answer-content/items/reasoning.vue @@ -0,0 +1,180 @@ + + + + + diff --git a/ui/src/components/chat-plus/component/answer-content/items/text.vue b/ui/src/components/chat-plus/component/answer-content/items/text.vue new file mode 100644 index 00000000000..862503e4169 --- /dev/null +++ b/ui/src/components/chat-plus/component/answer-content/items/text.vue @@ -0,0 +1,20 @@ + + + + + diff --git a/ui/src/components/chat-plus/component/answer-content/items/tool.vue b/ui/src/components/chat-plus/component/answer-content/items/tool.vue new file mode 100644 index 00000000000..cab8ebb5c30 --- /dev/null +++ b/ui/src/components/chat-plus/component/answer-content/items/tool.vue @@ -0,0 +1,26 @@ + + + diff --git a/ui/src/components/chat-plus/component/chat-panel/index.vue b/ui/src/components/chat-plus/component/chat-panel/index.vue new file mode 100644 index 00000000000..dafb89c5e86 --- /dev/null +++ b/ui/src/components/chat-plus/component/chat-panel/index.vue @@ -0,0 +1,167 @@ +