mirror of
https://gh-proxy.org/https://github.com/klinsmaya/SQLBot.git
synced 2026-11-08 01:06:59 +08:00
feat: New API to control the visibility of the assistant's chat history
This commit is contained in:
committed by
fit2cloud-chenyw
parent
c5466459e9
commit
ccb7d97d83
@@ -67,9 +67,16 @@
|
||||
</div>`
|
||||
|
||||
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 `
|
||||
<div id="sqlbot-assistant-chat-container">
|
||||
<iframe id="sqlbot-assistant-chat-iframe-${data.id}" allow="microphone;clipboard-read 'src'; clipboard-write 'src'" src="${data.domain_url}/#/assistant?id=${data.id}&online=${!!data.online}&name=${encodeURIComponent(data.name)}&userFlag=${data.userFlag || ''}"></iframe>
|
||||
<iframe id="sqlbot-assistant-chat-iframe-${data.id}" allow="microphone;clipboard-read 'src'; clipboard-write 'src'" src="${srcUrl}"></iframe>
|
||||
<div class="sqlbot-assistant-operate">
|
||||
<div class="sqlbot-assistant-closeviewport sqlbot-assistant-viewportnone">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 20 20" fill="none">
|
||||
@@ -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) => {
|
||||
|
||||
@@ -20,6 +20,7 @@ interface AssistantState {
|
||||
certificate: string
|
||||
online: boolean
|
||||
pageEmbedded?: boolean
|
||||
history: boolean
|
||||
requestPromiseMap: Map<string, PendingRequest>
|
||||
}
|
||||
|
||||
@@ -34,6 +35,7 @@ export const AssistantStore = defineStore('assistant', {
|
||||
certificate: '',
|
||||
online: false,
|
||||
pageEmbedded: false,
|
||||
history: true,
|
||||
requestPromiseMap: new Map<string, PendingRequest>(),
|
||||
}
|
||||
},
|
||||
@@ -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
|
||||
|
||||
@@ -6,7 +6,13 @@
|
||||
popper-class="popover-chat_history popover-chat_history_small"
|
||||
>
|
||||
<template #reference>
|
||||
<el-icon class="show-history_icon" style="" size="20" @click="showFloatPopover">
|
||||
<el-icon
|
||||
class="show-history_icon"
|
||||
:class="{ 'embedded-history-hidden': embeddedHistoryHidden }"
|
||||
style=""
|
||||
size="20"
|
||||
@click="showFloatPopover"
|
||||
>
|
||||
<icon_sidebar_outlined></icon_sidebar_outlined>
|
||||
</el-icon>
|
||||
</template>
|
||||
@@ -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 @@
|
||||
<el-aside
|
||||
v-if="(isCompletePage || pageEmbedded) && chatListSideBarShow"
|
||||
class="chat-container-left"
|
||||
:class="{ 'embedded-history-hidden': embeddedHistoryHidden }"
|
||||
>
|
||||
<ChatListContainer
|
||||
v-model:chat-list="chatList"
|
||||
@@ -37,7 +44,7 @@
|
||||
v-model:current-chat="currentChat"
|
||||
v-model:loading="loading"
|
||||
:in-popover="!chatListSideBarShow"
|
||||
:appName="customName"
|
||||
:app-name="customName"
|
||||
@go-empty="goEmpty"
|
||||
@on-chat-created="onChatCreated"
|
||||
@on-click-history="onClickHistory"
|
||||
@@ -50,7 +57,10 @@
|
||||
<div
|
||||
v-if="(!isCompletePage && !pageEmbedded) || !chatListSideBarShow"
|
||||
class="hidden-sidebar-btn"
|
||||
:class="{ 'assistant-popover-sidebar': !isCompletePage && !pageEmbedded }"
|
||||
:class="{
|
||||
'assistant-popover-sidebar': !isCompletePage && !pageEmbedded,
|
||||
'embedded-history-hidden': embeddedHistoryHidden,
|
||||
}"
|
||||
>
|
||||
<el-popover
|
||||
:width="280"
|
||||
@@ -72,7 +82,7 @@
|
||||
v-model:current-chat="currentChat"
|
||||
v-model:loading="loading"
|
||||
:in-popover="!chatListSideBarShow"
|
||||
:appName="customName"
|
||||
:app-name="customName"
|
||||
@go-empty="goEmpty"
|
||||
@on-chat-created="onChatCreated"
|
||||
@on-click-history="onClickHistory"
|
||||
@@ -97,7 +107,7 @@
|
||||
v-model:current-chat-id="currentChatId"
|
||||
v-model:current-chat="currentChat"
|
||||
v-model:loading="loading"
|
||||
:appName="customName"
|
||||
:app-name="customName"
|
||||
:in-popover="false"
|
||||
@go-empty="goEmpty"
|
||||
@on-chat-created="onChatCreated"
|
||||
@@ -199,7 +209,7 @@
|
||||
:first-chat="message.first_chat"
|
||||
@click-question="quickAsk"
|
||||
@stop="onChatStop"
|
||||
@loadingOver="loadingOver"
|
||||
@loading-over="loadingOver"
|
||||
/>
|
||||
<UserChat v-if="message.role === 'user'" :message="message" />
|
||||
<template v-if="message.role === 'assistant' && !message.first_chat">
|
||||
@@ -216,8 +226,8 @@
|
||||
:current-chat-id="currentChatId"
|
||||
:loading="isTyping"
|
||||
:message="message"
|
||||
@scrollBottom="scrollToBottom"
|
||||
:reasoning-name="['sql_answer', 'chart_answer']"
|
||||
@scroll-bottom="scrollToBottom"
|
||||
@finish="onChartAnswerFinish"
|
||||
@error="onChartAnswerError"
|
||||
@stop="onChatStop"
|
||||
@@ -292,7 +302,7 @@
|
||||
:first-chat="message.first_chat"
|
||||
:disabled="isTyping"
|
||||
@click-question="quickAsk"
|
||||
@loadingOver="loadingOver"
|
||||
@loading-over="loadingOver"
|
||||
@stop="onChatStop"
|
||||
/>
|
||||
</template>
|
||||
@@ -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 ''
|
||||
@@ -1328,7 +1341,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;
|
||||
|
||||
@@ -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() || '')
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user