Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/apps/system/api/assistant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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("__"):
Expand Down
44 changes: 43 additions & 1 deletion frontend/public/assistant.js
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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')
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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) => {
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/stores/assistant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface AssistantState {
certificate: string
online: boolean
pageEmbedded?: boolean
history: boolean
requestPromiseMap: Map<string, PendingRequest>
}

Expand All @@ -34,6 +35,7 @@ export const AssistantStore = defineStore('assistant', {
certificate: '',
online: false,
pageEmbedded: false,
history: true,
requestPromiseMap: new Map<string, PendingRequest>(),
}
},
Expand All @@ -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
},
Expand Down Expand Up @@ -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
Expand Down
37 changes: 26 additions & 11 deletions frontend/src/views/chat/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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"
Expand All @@ -30,14 +36,15 @@
<el-aside
v-if="(isCompletePage || pageEmbedded) && chatListSideBarShow"
class="chat-container-left"
:class="{ 'embedded-history-hidden': embeddedHistoryHidden }"
>
<ChatListContainer
v-model:chat-list="chatList"
v-model:current-chat-id="currentChatId"
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"
Expand All @@ -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"
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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">
Expand All @@ -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"
Expand Down Expand Up @@ -292,7 +302,7 @@
:first-chat="message.first_chat"
:disabled="isTyping"
@click-question="quickAsk"
@loadingOver="loadingOver"
@loading-over="loadingOver"
@stop="onChatStop"
/>
</template>
Expand Down Expand Up @@ -328,7 +338,7 @@
:current-chat-id="currentChatId"
:loading="isTyping"
:message="message"
@scrollBottom="scrollToBottom"
@scroll-bottom="scrollToBottom"
@finish="onPredictAnswerFinish"
@error="onPredictAnswerError"
@stop="onChatStop"
Expand Down Expand Up @@ -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 ''
Expand Down Expand Up @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/views/embedded/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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() || '')
Expand Down
12 changes: 12 additions & 0 deletions frontend/src/views/embedded/page.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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())
Expand Down