feat:执行状态单例状态bug修复
This commit is contained in:
@@ -78,17 +78,17 @@ class WebSocketClient {
|
||||
reject(error)
|
||||
})
|
||||
|
||||
this.socket.on('disconnect', (reason) => {
|
||||
this.socket.on('disconnect', () => {
|
||||
this.isConnected = false
|
||||
})
|
||||
|
||||
this.socket.on('connected', (data) => {
|
||||
this.socket.on('connected', () => {
|
||||
// Server connected message
|
||||
})
|
||||
|
||||
// 监听响应消息
|
||||
this.socket.on('response', (response: ResponseMessage) => {
|
||||
const { id, status, data, error } = response
|
||||
const { id, status, data, error, generation_id, execution_id } = response
|
||||
const handler = this.requestHandlers.get(id)
|
||||
|
||||
if (handler) {
|
||||
@@ -98,7 +98,19 @@ class WebSocketClient {
|
||||
}
|
||||
|
||||
if (status === 'success') {
|
||||
handler.resolve(data)
|
||||
// 返回完整响应,包含 data、generation_id、execution_id 等
|
||||
// 注意:需要检查 data 是否为 null,因为 typeof null === 'object'
|
||||
// generation_id/execution_id 可能放在 data 中,需要兼容处理
|
||||
// 注意:如果 data 是数组,不能展开,否则会破坏数组结构
|
||||
const resolvedGenerationId = generation_id || (data && typeof data === 'object' && !Array.isArray(data) && data.generation_id)
|
||||
const resolvedExecutionId = execution_id || (data && typeof data === 'object' && !Array.isArray(data) && data.execution_id)
|
||||
|
||||
// 直接返回 data,保持原始数据结构(数组或对象)
|
||||
handler.resolve({
|
||||
data,
|
||||
generation_id: resolvedGenerationId,
|
||||
execution_id: resolvedExecutionId
|
||||
})
|
||||
} else {
|
||||
handler.reject(new Error(error || 'Unknown error'))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user