fix: improve maintenance and synchronize live conversations

This commit is contained in:
WangShen007 committed 2026-10-29 09:46:21 +08:00
1 parent bb541bd212
commit ef86a5d3af
297 files changed
+2983 -1274

No files matched your search

+8 -7
View File
@@ -15,8 +15,9 @@ limitations under the License.
*/
import { ref } from 'vue'
import { io, Socket } from 'socket.io-client'
import type { HumanAgent, SocketError } from '../types/widget'
import { io } from 'socket.io-client'
import type { Socket } from 'socket.io-client'
import type { HumanAgent, SocketError, WidgetFormData, WidgetMessage } from '../types/widget'
import { getErrorMessage } from '../types/widget'
import { widgetEnv } from '../webclient/widget-env'
import { readTokenClaims } from './useConversationToken'
@@ -38,7 +39,7 @@ export interface SessionState {
const END_CHAT_TIMEOUT_MS = 5000
export function useWidgetSocket() {
const messages = ref<Message[]>([])
const messages = ref<WidgetMessage[]>([])
const loading = ref(false)
const errorMessage = ref('')
const showError = ref(false)
@@ -48,7 +49,7 @@ export function useWidgetSocket() {
const retryCount = ref(0)
const MAX_RETRIES = 5
const humanAgent = ref<HumanAgent>({})
const currentForm = ref<any>(null)
const currentForm = ref<WidgetFormData | null>(null)
const currentSessionId = ref<string>('')
// The typing indicator is driven solely by the server's `bot_typing`
@@ -168,7 +169,7 @@ export function useWidgetSocket() {
return auth
}
const initializeSocket = (sessionId: string) => {
const initializeSocket = () => {
socket = io(`${widgetEnv.WS_URL}/widget`, {
transports: ['websocket'],
reconnection: true,
@@ -400,7 +401,7 @@ export function useWidgetSocket() {
socket = null
}
socket = initializeSocket('')
socket = initializeSocket()
return new Promise((resolve) => {
socket?.on('connect', () => {
@@ -808,4 +809,4 @@ export function useWidgetSocket() {
setToken,
setWidgetId
}
}
}