feat: unify InvokeError; add rawResponse to historical ErrorEvent

This commit is contained in:
Simon
2026-01-20 20:16:34 +08:00
parent 1f8953c450
commit 22516dec74
5 changed files with 34 additions and 13 deletions

View File

@@ -2,7 +2,7 @@
* Copyright (C) 2025 Alibaba Group Holding Limited
* All rights reserved.
*/
import { LLM, type Tool } from '@page-agent/llms'
import { InvokeError, LLM, type Tool } from '@page-agent/llms'
import type { PageController } from '@page-agent/page-controller'
import chalk from 'chalk'
import zod from 'zod'
@@ -107,7 +107,7 @@ export class PageAgentCore extends EventTarget {
this.#emitHistoryChange()
})
this.#llm.addEventListener('error', (e) => {
const { error } = (e as CustomEvent).detail
const error = (e as CustomEvent).detail.error as Error | InvokeError
const message = String(error)
this.emitActivity({ type: 'error', message })
// Also push to history for panel rendering
@@ -115,6 +115,7 @@ export class PageAgentCore extends EventTarget {
type: 'error',
errorType: 'error',
message,
rawResponse: (error as InvokeError).rawResponse,
})
this.#emitHistoryChange()
})

View File

@@ -76,6 +76,7 @@ export interface ErrorEvent {
message: string
attempt?: number
maxAttempts?: number
rawResponse?: unknown
}
/**