feat(ext): require llmConfig when calling from main world

This commit is contained in:
Simon
2026-01-28 20:28:21 +08:00
parent 0f3ae38cb3
commit f67ec5a2c2
2 changed files with 17 additions and 5 deletions

View File

@@ -1,5 +1,6 @@
import { initPageController } from '@/agent/RemotePageController.content'
import { DEMO_CONFIG } from '@/agent/constants'
// import { DEMO_CONFIG } from '@/agent/constants'
const DEBUG_PREFIX = '[Content]'
@@ -67,9 +68,11 @@ async function exposeAgentToPage() {
}
try {
multiPageAgent = new MultiPageAgent(DEMO_CONFIG)
const { task, llmConfig } = payload
const result = await multiPageAgent.execute(payload)
multiPageAgent = new MultiPageAgent(llmConfig)
const result = await multiPageAgent.execute(task)
window.postMessage(
{

View File

@@ -1,3 +1,5 @@
import type { LLMConfig } from '@page-agent/llms'
export default defineUnlistedScript(() => {
const w = window as any
@@ -7,7 +9,14 @@ export default defineUnlistedScript(() => {
return _lastId
}
w.execute = async (task: string) => {
w.execute = async (task: string, llmConfig: LLMConfig) => {
if (typeof task !== 'string') throw new Error('Task must be a string')
if (task.trim().length === 0) throw new Error('Task cannot be empty')
if (!llmConfig) throw new Error('LLM config is required')
if (!llmConfig.baseURL) throw new Error('LLM config must have a baseURL')
if (!llmConfig.apiKey) throw new Error('LLM config must have an apiKey')
if (!llmConfig.model) throw new Error('LLM config must have a model')
const id = getId()
const promise = new Promise((resolve, reject) => {
@@ -35,7 +44,7 @@ export default defineUnlistedScript(() => {
channel: 'PAGE_AGENT_EXT_REQUEST',
id,
action: 'execute',
payload: task,
payload: { task, llmConfig },
},
'*'
)