diff --git a/backend/apps/system/api/assistant.py b/backend/apps/system/api/assistant.py index ea41e6d7..69b1cc0b 100644 --- a/backend/apps/system/api/assistant.py +++ b/backend/apps/system/api/assistant.py @@ -116,7 +116,7 @@ async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] = if flag_name == 'logo' or flag_name == 'float_icon': SQLBotFileUtils.check_file(file=file, file_types=[".jpg", ".jpeg", ".png", ".svg"], limit_file_size=(10 * 1024 * 1024)) if config_obj.get(flag_name): - SQLBotFileUtils.detete_file(config_obj.get(flag_name)) + SQLBotFileUtils.delete_file(config_obj.get(flag_name)) file_id = await SQLBotFileUtils.upload(file) ui_schema_dict[flag_name] = file_id else: @@ -126,7 +126,7 @@ async def ui(session: SessionDep, data: str = Form(), files: List[UploadFile] = file_val = config_obj.get(flag_name) if file_val and not ui_schema_dict.get(flag_name): config_obj[flag_name] = None - SQLBotFileUtils.detete_file(file_val) + SQLBotFileUtils.delete_file(file_val) for attr, value in ui_schema_dict.items(): if attr != 'id' and not attr.startswith("__"): diff --git a/frontend/public/assistant.js b/frontend/public/assistant.js index 38a963b2..b9c4a51d 100644 --- a/frontend/public/assistant.js +++ b/frontend/public/assistant.js @@ -67,9 +67,16 @@ ` const getChatContainerHtml = (data) => { + let srcUrl = `${data.domain_url}/#/assistant?id=${data.id}&online=${!!data.online}&name=${encodeURIComponent(data.name)}&userFlag=${data.userFlag || ''}` + if (data.userFlag) { + srcUrl += `&userFlag=${data.userFlag || ''}` + } + if (data.history) { + srcUrl += `&userFlag=${data.history}` + } return `
- +
@@ -499,6 +506,7 @@ const domain_url = getDomain(src) const online = getParam(src, 'online') const userFlag = getParam(src, 'userFlag') + const history = getParam(src, 'history') let url = `${domain_url}/api/v1/system/assistant/info/${id}` if (domain_url.includes('5173')) { url = url.replace('5173', '8000') @@ -536,6 +544,7 @@ tempData['online'] = online && online.toString().toLowerCase() == 'true' tempData['userFlag'] = userFlag + tempData['history'] = history initsqlbot_assistant(tempData) if (data.type == 1) { registerMessageEvent(id, tempData) @@ -750,6 +759,39 @@ } delete window.sqlbot_assistant_handler[id] } + window.sqlbot_assistant_handler[id]['setHistory'] = (show) => { + if (show != null && typeof show != 'boolean') { + throw new Error('The parameter can only be of type boolean') + } + const iframe = document.getElementById(`sqlbot-assistant-chat-iframe-${id}`) + if (iframe) { + const url = iframe.src + const eventName = 'sqlbot_assistant_event' + const params = { + busi: 'setHistory', + show, + eventName, + messageId: id, + } + const contentWindow = iframe.contentWindow + contentWindow.postMessage(params, url) + } + } + window.sqlbot_assistant_handler[id]['createConversation'] = (param) => { + const iframe = document.getElementById(`sqlbot-assistant-chat-iframe-${id}`) + if (iframe) { + const url = iframe.src + const eventName = 'sqlbot_assistant_event' + const params = { + busi: 'createConversation', + param, + eventName, + messageId: id, + } + const contentWindow = iframe.contentWindow + contentWindow.postMessage(params, url) + } + } } // window.addEventListener('load', init) const executeWhenReady = (fn) => { diff --git a/frontend/src/stores/assistant.ts b/frontend/src/stores/assistant.ts index d6eeb2f1..5b27fec4 100644 --- a/frontend/src/stores/assistant.ts +++ b/frontend/src/stores/assistant.ts @@ -20,6 +20,7 @@ interface AssistantState { certificate: string online: boolean pageEmbedded?: boolean + history: boolean requestPromiseMap: Map } @@ -34,6 +35,7 @@ export const AssistantStore = defineStore('assistant', { certificate: '', online: false, pageEmbedded: false, + history: true, requestPromiseMap: new Map(), } }, @@ -59,6 +61,9 @@ export const AssistantStore = defineStore('assistant', { getOnline(): boolean { return this.online }, + getHistory(): boolean { + return this.history + }, getPageEmbedded(): boolean { return this.pageEmbedded || false }, @@ -130,6 +135,9 @@ export const AssistantStore = defineStore('assistant', { setOnline(online: boolean) { this.online = !!online }, + setHistory(history: boolean) { + this.history = history ?? true + }, async setChat() { if (!this.assistant) { return null diff --git a/frontend/src/views/chat/index.vue b/frontend/src/views/chat/index.vue index 52c9f7aa..6960d2c2 100644 --- a/frontend/src/views/chat/index.vue +++ b/frontend/src/views/chat/index.vue @@ -6,7 +6,13 @@ popper-class="popover-chat_history popover-chat_history_small" > @@ -17,7 +23,7 @@ v-model:current-chat="currentChat" v-model:loading="loading" in-popover - :appName="customName" + :app-name="customName" @go-empty="goEmpty" @on-chat-created="onChatCreated" @on-click-history="onClickHistory" @@ -30,6 +36,7 @@ @@ -328,7 +338,7 @@ :current-chat-id="currentChatId" :loading="isTyping" :message="message" - @scrollBottom="scrollToBottom" + @scroll-bottom="scrollToBottom" @finish="onPredictAnswerFinish" @error="onPredictAnswerError" @stop="onChatStop" @@ -446,6 +456,9 @@ const defaultFloatPopoverStyle = ref({ }) const isCompletePage = computed(() => !assistantStore.getAssistant || assistantStore.getEmbedded) +const embeddedHistoryHidden = computed( + () => assistantStore.getAssistant && !assistantStore.getHistory +) const customName = computed(() => { if (!isCompletePage.value && props.pageEmbedded) return props.appName return '' @@ -1321,7 +1334,9 @@ onMounted(() => { border: 1px solid rgba(222, 224, 227, 1); border-radius: 6px; } - +.embedded-history-hidden { + display: none !important; +} .show-history_icon { cursor: pointer; position: absolute; diff --git a/frontend/src/views/embedded/index.vue b/frontend/src/views/embedded/index.vue index 928ea3f5..18b6e8d6 100644 --- a/frontend/src/views/embedded/index.vue +++ b/frontend/src/views/embedded/index.vue @@ -79,6 +79,12 @@ const communicationCb = async (event: any) => { if (event.data?.busi == 'setOnline') { setFormatOnline(event.data.online) } + if (event.data?.busi == 'setHistory') { + assistantStore.setHistory(event.data.show ?? true) + } + if (event.data?.busi == 'createConversation') { + createChat() + } } } const setFormatOnline = (text?: any) => { @@ -141,6 +147,10 @@ onBeforeMount(async () => { if (userFlag && userFlag === '1') { userFlag = '100001' } + + const history: boolean = route.query.history !== 'false' + assistantStore.setHistory(history) + const now = Date.now() assistantStore.setFlag(now) assistantStore.setId(assistantId?.toString() || '') diff --git a/frontend/src/views/embedded/page.vue b/frontend/src/views/embedded/page.vue index 58a38a96..aeb3bae2 100644 --- a/frontend/src/views/embedded/page.vue +++ b/frontend/src/views/embedded/page.vue @@ -69,8 +69,17 @@ const communicationCb = async (event: any) => { if (event.data?.busi == 'setOnline') { setFormatOnline(event.data.online) } + if (event.data?.busi == 'setHistory') { + assistantStore.setHistory(event.data.show ?? true) + } + if (event.data?.busi == 'createConversation') { + createChat() + } } } +const createChat = () => { + chatRef.value?.createNewChat() +} const setFormatOnline = (text?: any) => { if (text === null || typeof text === 'undefined') { assistantStore.setOnline(false) @@ -119,6 +128,9 @@ onBeforeMount(async () => { const online = route.query.online setFormatOnline(online) + const history: boolean = route.query.history !== 'false' + assistantStore.setHistory(history) + let name = route.query.name if (name) { assistantName.value = decodeURIComponent(name.toString())