fix(UMD): delay init
This commit is contained in:
@@ -20,21 +20,25 @@ const DEMO_MODEL = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
|||||||
const DEMO_BASE_URL = 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
const DEMO_BASE_URL = 'https://hwcxiuzfylggtcktqgij.supabase.co/functions/v1/llm-testing-proxy'
|
||||||
const DEMO_API_KEY = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
const DEMO_API_KEY = 'PAGE-AGENT-FREE-TESTING-RANDOM'
|
||||||
|
|
||||||
const currentScript = document.currentScript as HTMLScriptElement | null
|
// in case document.x is not ready yet
|
||||||
if (currentScript) {
|
// @todo give a switch to disable auto-init
|
||||||
console.log('🚀 page-agent.js detected current script:', currentScript.src)
|
setTimeout(() => {
|
||||||
const url = new URL(currentScript.src)
|
const currentScript = document.currentScript as HTMLScriptElement | null
|
||||||
const model = url.searchParams.get('model') || DEMO_MODEL
|
if (currentScript) {
|
||||||
const baseURL = url.searchParams.get('baseURL') || DEMO_BASE_URL
|
console.log('🚀 page-agent.js detected current script:', currentScript.src)
|
||||||
const apiKey = url.searchParams.get('apiKey') || DEMO_API_KEY
|
const url = new URL(currentScript.src)
|
||||||
const language = (url.searchParams.get('lang') as 'zh-CN' | 'en-US') || 'zh-CN'
|
const model = url.searchParams.get('model') || DEMO_MODEL
|
||||||
const config: PageAgentConfig = { model, baseURL, apiKey, language }
|
const baseURL = url.searchParams.get('baseURL') || DEMO_BASE_URL
|
||||||
window.pageAgent = new PageAgent(config)
|
const apiKey = url.searchParams.get('apiKey') || DEMO_API_KEY
|
||||||
} else {
|
const language = (url.searchParams.get('lang') as 'zh-CN' | 'en-US') || 'zh-CN'
|
||||||
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
const config: PageAgentConfig = { model, baseURL, apiKey, language }
|
||||||
window.pageAgent = new PageAgent()
|
window.pageAgent = new PageAgent(config)
|
||||||
}
|
} else {
|
||||||
|
console.log('🚀 page-agent.js no current script detected, using default demo config')
|
||||||
|
window.pageAgent = new PageAgent()
|
||||||
|
}
|
||||||
|
|
||||||
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
console.log('🚀 page-agent.js initialized with config:', window.pageAgent.config)
|
||||||
|
|
||||||
window.pageAgent.panel.show() // Show panel
|
window.pageAgent.panel.show() // Show panel
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user