2026-01-28 13:15:34 +08:00
|
|
|
import { type PageAgentConfig, PageAgentCore } from '@page-agent/core'
|
2026-01-27 17:21:32 +08:00
|
|
|
|
|
|
|
|
import { RemotePageController } from './RemotePageController'
|
|
|
|
|
import { TabsController } from './TabsController'
|
2026-01-28 13:15:34 +08:00
|
|
|
import SYSTEM_PROMPT from './system_prompt.md?raw'
|
2026-01-27 17:21:32 +08:00
|
|
|
import { createTabTools } from './tabTools'
|
|
|
|
|
|
|
|
|
|
export class MultiPageAgent extends PageAgentCore {
|
|
|
|
|
constructor(config: Omit<PageAgentConfig, 'pageController'>) {
|
|
|
|
|
const tabsController = new TabsController()
|
|
|
|
|
const pageController = new RemotePageController()
|
|
|
|
|
pageController.tabsController = tabsController
|
|
|
|
|
const customTools = createTabTools(tabsController)
|
|
|
|
|
|
|
|
|
|
super({
|
|
|
|
|
...config,
|
|
|
|
|
pageController: pageController as any,
|
|
|
|
|
customTools: customTools,
|
2026-01-27 21:45:51 +08:00
|
|
|
customSystemPrompt: SYSTEM_PROMPT,
|
2026-01-27 17:21:32 +08:00
|
|
|
|
|
|
|
|
onBeforeTask: async (agent) => {
|
|
|
|
|
await tabsController.init(agent.taskId)
|
|
|
|
|
|
|
|
|
|
await chrome.storage.local.set({
|
|
|
|
|
isAgentRunning: true,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onAfterTask: async () => {
|
|
|
|
|
await chrome.storage.local.set({
|
|
|
|
|
isAgentRunning: false,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
onDispose: () => {
|
|
|
|
|
chrome.storage.local.set({
|
|
|
|
|
isAgentRunning: false,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
}
|