feat!: Refine lifecycle hooks; fix abortSignal

- add `stop` method. agent can be reused after stopped
- agent can not be reused after disposed
- extension DO NOT exposes `dispose` anymore. only `stop`.
- update panel for new `stop` method
- fix MultiPageAgent dispose event
- better handling abortSignal
This commit is contained in:
Simon
2026-02-13 17:57:12 +08:00
parent 4dc332a32c
commit dffcb53db9
13 changed files with 80 additions and 68 deletions

View File

@@ -16,7 +16,6 @@ export interface ExecuteConfig {
onStatusChange?: (status: AgentStatus) => void
onActivity?: (activity: AgentActivity) => void
onHistoryUpdate?: (history: HistoricalEvent[]) => void
onDispose?: () => void
}
export default defineUnlistedScript(() => {
@@ -60,12 +59,6 @@ export default defineUnlistedScript(() => {
return
}
if (data.action === 'dispose_event' && config.onDispose) {
config.onDispose()
window.removeEventListener('message', handleMessage)
return
}
if (data.action !== 'execute_result') return
// execute_result
@@ -104,14 +97,14 @@ export default defineUnlistedScript(() => {
return promise
}
const dispose = () => {
const stop = () => {
const id = getId()
window.postMessage(
{
channel: 'PAGE_AGENT_EXT_REQUEST',
id,
action: 'dispose',
action: 'stop',
},
'*'
)
@@ -121,6 +114,6 @@ export default defineUnlistedScript(() => {
;(window as any).PAGE_AGENT_EXT = {
version: __EXT_VERSION__,
execute,
dispose,
stop,
}
})