feat: add legacy endpoint migration and testing endpoint notice
This commit is contained in:
@@ -11,7 +11,7 @@ import type { LLMConfig } from '@page-agent/llms'
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
|
||||
import { MultiPageAgent } from './MultiPageAgent'
|
||||
import { DEMO_CONFIG } from './constants'
|
||||
import { DEMO_CONFIG, migrateLegacyEndpoint } from './constants'
|
||||
|
||||
/** Language preference: undefined means follow system */
|
||||
export type LanguagePreference = SupportedLanguage | undefined
|
||||
@@ -41,13 +41,19 @@ export function useAgent(): UseAgentResult {
|
||||
|
||||
useEffect(() => {
|
||||
chrome.storage.local.get(['llmConfig', 'language']).then((result) => {
|
||||
const llmConfig = (result.llmConfig as LLMConfig) ?? DEMO_CONFIG
|
||||
let llmConfig = (result.llmConfig as LLMConfig) ?? DEMO_CONFIG
|
||||
const language = (result.language as SupportedLanguage) || undefined
|
||||
const full = { ...llmConfig, language }
|
||||
if (!result.llmConfig) {
|
||||
|
||||
// Auto-migrate legacy testing endpoints
|
||||
const migrated = migrateLegacyEndpoint(llmConfig)
|
||||
if (migrated !== llmConfig) {
|
||||
llmConfig = migrated
|
||||
chrome.storage.local.set({ llmConfig: migrated })
|
||||
} else if (!result.llmConfig) {
|
||||
chrome.storage.local.set({ llmConfig: DEMO_CONFIG })
|
||||
}
|
||||
setConfig(full)
|
||||
|
||||
setConfig({ ...llmConfig, language })
|
||||
})
|
||||
}, [])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user