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 @@ +