perf: Assistant token

This commit is contained in:
fit2cloud-chenyw
2025-07-10 12:43:14 +08:00
parent 4bd69b845f
commit e69caadd09
10 changed files with 149 additions and 58 deletions
+31
View File
@@ -0,0 +1,31 @@
import { defineStore } from 'pinia'
import { store } from './index'
interface AssistantState {
token: string
}
export const AssistantStore = defineStore('assistant', {
state: (): AssistantState => {
return {
token: '',
}
},
getters: {
getToken(): string {
return this.token
},
},
actions: {
setToken(token: string) {
this.token = token
},
clear() {
this.$reset()
},
},
})
export const useAssistantStore = () => {
return AssistantStore(store)
}
+6
View File
@@ -10,6 +10,8 @@ import axios, {
import { useCache } from '@/utils/useCache'
import { getLocale } from './utils'
import { useAssistantStore } from '@/stores/assistant'
const assistantStore = useAssistantStore()
const { wsCache } = useCache()
// Response data structure
export interface ApiResponse<T = unknown> {
@@ -70,6 +72,10 @@ class HttpService {
if (token && config.headers) {
config.headers['X-SQLBOT-TOKEN'] = `Bearer ${token}`
}
if (assistantStore.getToken) {
config.headers['X-SQLBOT-ASSISTANT-TOKEN'] = `Assistant ${assistantStore.getToken}`
if (config.headers['X-SQLBOT-TOKEN']) config.headers.delete('X-SQLBOT-TOKEN')
}
const locale = getLocale()
if (locale) {
/* const mapping = {
+4 -3
View File
@@ -62,8 +62,9 @@ import IconOpeEdit from '@/assets/svg/operate/ope-edit.svg'
import IconOpeDelete from '@/assets/svg/operate/ope-delete.svg'
import { useRoute } from 'vue-router'
import { assistantApi } from '@/api/assistant'
import { useUserStore } from '@/stores/user'
const userStore = useUserStore()
import { useAssistantStore } from '@/stores/assistant'
const assistantStore = useAssistantStore()
const route = useRoute()
const chatRef = ref()
@@ -96,7 +97,7 @@ const loading = ref(true)
onBeforeMount(async () => {
const assistantId = route.params.id
validator.value = await assistantApi.validate(assistantId)
userStore.setToken(validator.value.token)
assistantStore.setToken(validator.value.token)
loading.value = false
})
</script>