mirror of
https://github.com/hellodigua/ChatLab.git
synced 2026-05-26 08:30:23 +08:00
feat: AI 对话错误详情展示优化
This commit is contained in:
@@ -79,7 +79,9 @@ export interface ChatStreamChunk {
|
||||
|
||||
// Agent API 类型 — 从 shared/types 统一导入
|
||||
export type { TokenUsage, AgentRuntimeStatus } from '../../shared/types'
|
||||
import type { TokenUsage, AgentRuntimeStatus } from '../../shared/types'
|
||||
import type { TokenUsage, AgentRuntimeStatus, SerializedErrorInfo } from '../../shared/types'
|
||||
|
||||
export type { SerializedErrorInfo } from '../../shared/types'
|
||||
|
||||
export interface AgentStreamChunk {
|
||||
type: 'content' | 'think' | 'tool_start' | 'tool_result' | 'status' | 'done' | 'error'
|
||||
@@ -90,7 +92,7 @@ export interface AgentStreamChunk {
|
||||
toolParams?: Record<string, unknown>
|
||||
toolResult?: unknown
|
||||
status?: AgentRuntimeStatus
|
||||
error?: string
|
||||
error?: SerializedErrorInfo
|
||||
isFinished?: boolean
|
||||
/** Token 使用量(type=done 时返回累计值) */
|
||||
usage?: TokenUsage
|
||||
@@ -100,6 +102,7 @@ export interface AgentResult {
|
||||
content: string
|
||||
toolsUsed: string[]
|
||||
toolRounds: number
|
||||
error?: SerializedErrorInfo
|
||||
}
|
||||
|
||||
/** 单条脱敏规则 */
|
||||
@@ -907,7 +910,10 @@ export const agentApi = {
|
||||
assistantId?: string,
|
||||
skillId?: string | null,
|
||||
enableAutoSkill?: boolean
|
||||
): { requestId: string; promise: Promise<{ success: boolean; result?: AgentResult; error?: string }> } => {
|
||||
): {
|
||||
requestId: string
|
||||
promise: Promise<{ success: boolean; result?: AgentResult; error?: SerializedErrorInfo }>
|
||||
} => {
|
||||
// 防御性处理:确保传给 IPC 的 context 是“可结构化克隆”的纯对象
|
||||
// 避免调用方误传入响应式 Proxy(例如 Pinia/Vue state)导致 invoke 失败
|
||||
const sanitizedContext: ToolContext = {
|
||||
@@ -949,7 +955,7 @@ export const agentApi = {
|
||||
chatType ?? 'group'
|
||||
)
|
||||
|
||||
const promise = new Promise<{ success: boolean; result?: AgentResult; error?: string }>((resolve) => {
|
||||
const promise = new Promise<{ success: boolean; result?: AgentResult; error?: SerializedErrorInfo }>((resolve) => {
|
||||
// 监听流式 chunks
|
||||
const chunkHandler = (
|
||||
_event: Electron.IpcRendererEvent,
|
||||
@@ -965,7 +971,7 @@ export const agentApi = {
|
||||
// 监听完成事件
|
||||
const completeHandler = (
|
||||
_event: Electron.IpcRendererEvent,
|
||||
data: { requestId: string; result: AgentResult & { error?: string } }
|
||||
data: { requestId: string; result: AgentResult & { error?: SerializedErrorInfo } }
|
||||
) => {
|
||||
if (data.requestId === requestId) {
|
||||
console.log('[preload] Agent 完成,requestId:', requestId, 'hasError:', !!data.result?.error)
|
||||
@@ -1009,7 +1015,14 @@ export const agentApi = {
|
||||
console.error('[preload] Agent invoke 错误:', error)
|
||||
ipcRenderer.removeListener('agent:streamChunk', chunkHandler)
|
||||
ipcRenderer.removeListener('agent:complete', completeHandler)
|
||||
resolve({ success: false, error: String(error) })
|
||||
resolve({
|
||||
success: false,
|
||||
error: {
|
||||
name: error instanceof Error ? error.name : null,
|
||||
message: error instanceof Error ? error.message : String(error),
|
||||
stack: error instanceof Error ? (error.stack ?? null) : null,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
Vendored
+5
-3
@@ -1,6 +1,6 @@
|
||||
import { ElectronAPI } from '@electron-toolkit/preload'
|
||||
import type { AnalysisSession, MessageType, ImportProgress, ExportProgress } from '../../src/types/base'
|
||||
import type { TokenUsage, AgentRuntimeStatus } from '../shared/types'
|
||||
import type { TokenUsage, AgentRuntimeStatus, SerializedErrorInfo } from '../shared/types'
|
||||
import type {
|
||||
MemberActivity,
|
||||
MemberNameHistory,
|
||||
@@ -672,7 +672,7 @@ interface AgentStreamChunk {
|
||||
toolParams?: Record<string, unknown>
|
||||
toolResult?: unknown
|
||||
status?: AgentRuntimeStatus
|
||||
error?: string
|
||||
error?: SerializedErrorInfo
|
||||
isFinished?: boolean
|
||||
/** Token 使用量(type=done 时返回累计值) */
|
||||
usage?: TokenUsage
|
||||
@@ -684,6 +684,7 @@ interface AgentResult {
|
||||
toolRounds: number
|
||||
/** 总 Token 使用量(累计所有 LLM 调用) */
|
||||
totalUsage?: TokenUsage
|
||||
error?: SerializedErrorInfo
|
||||
}
|
||||
|
||||
/** Owner 信息(当前用户在对话中的身份) */
|
||||
@@ -768,7 +769,7 @@ interface AgentApi {
|
||||
assistantId?: string,
|
||||
skillId?: string | null,
|
||||
enableAutoSkill?: boolean
|
||||
) => { requestId: string; promise: Promise<{ success: boolean; result?: AgentResult; error?: string }> }
|
||||
) => { requestId: string; promise: Promise<{ success: boolean; result?: AgentResult; error?: SerializedErrorInfo }> }
|
||||
abort: (requestId: string) => Promise<{ success: boolean; error?: string }>
|
||||
}
|
||||
|
||||
@@ -1213,6 +1214,7 @@ export {
|
||||
AgentStreamChunk,
|
||||
AgentRuntimeStatus,
|
||||
AgentResult,
|
||||
SerializedErrorInfo,
|
||||
ToolContext,
|
||||
DesensitizeRule,
|
||||
PreprocessConfig,
|
||||
|
||||
Reference in New Issue
Block a user