Files
WeFlow/electron/services/agentProcessLifecycle.ts
2026-09-28 21:16:43 +08:00

30 lines
968 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
export type AgentProcessExitResolution =
| {
success: true
completionSource: 'finish-chunk' | 'run-store'
}
| {
success: false
error: string
}
/**
* 根据流式结束标记和持久化运行状态判断后台进程是否正常完成。
* 即使结束分片丢失,只要运行存储已确认完成,也不能把进程退出误报为失败。
*/
export function resolveAgentProcessExit(options: {
code: number | null
signal: string | null
sawFinishChunk: boolean
persistedStatus?: string | null
}): AgentProcessExitResolution {
if (options.sawFinishChunk) {
return { success: true, completionSource: 'finish-chunk' }
}
if (options.persistedStatus === 'completed') {
return { success: true, completionSource: 'run-store' }
}
const reason = options.signal || (options.code == null ? '未知' : String(options.code))
return { success: false, error: `Agent 后台进程意外退出(${reason})` }
}