feat(ext): require llmConfig when calling from main world
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { initPageController } from '@/agent/RemotePageController.content'
|
import { initPageController } from '@/agent/RemotePageController.content'
|
||||||
import { DEMO_CONFIG } from '@/agent/constants'
|
|
||||||
|
// import { DEMO_CONFIG } from '@/agent/constants'
|
||||||
|
|
||||||
const DEBUG_PREFIX = '[Content]'
|
const DEBUG_PREFIX = '[Content]'
|
||||||
|
|
||||||
@@ -67,9 +68,11 @@ async function exposeAgentToPage() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
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(
|
window.postMessage(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import type { LLMConfig } from '@page-agent/llms'
|
||||||
|
|
||||||
export default defineUnlistedScript(() => {
|
export default defineUnlistedScript(() => {
|
||||||
const w = window as any
|
const w = window as any
|
||||||
|
|
||||||
@@ -7,7 +9,14 @@ export default defineUnlistedScript(() => {
|
|||||||
return _lastId
|
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 id = getId()
|
||||||
|
|
||||||
const promise = new Promise((resolve, reject) => {
|
const promise = new Promise((resolve, reject) => {
|
||||||
@@ -35,7 +44,7 @@ export default defineUnlistedScript(() => {
|
|||||||
channel: 'PAGE_AGENT_EXT_REQUEST',
|
channel: 'PAGE_AGENT_EXT_REQUEST',
|
||||||
id,
|
id,
|
||||||
action: 'execute',
|
action: 'execute',
|
||||||
payload: task,
|
payload: { task, llmConfig },
|
||||||
},
|
},
|
||||||
'*'
|
'*'
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user