fix: 从 loacl 中切换到 openrouter 后自动更新 模型名称
Browse files
src/components/LogoV2/LogoV2.tsx
CHANGED
|
@@ -39,7 +39,7 @@ import { SandboxManager } from 'src/utils/sandbox/sandbox-adapter.js';
|
|
| 39 |
import { useShowGuestPassesUpsell, incrementGuestPassesSeenCount } from './GuestPassesUpsell.js';
|
| 40 |
import { useShowOverageCreditUpsell, incrementOverageCreditUpsellSeenCount, createOverageCreditFeed } from './OverageCreditUpsell.js';
|
| 41 |
import { plural } from '../../utils/stringUtils.js';
|
| 42 |
-
import { useAppState } from '../../state/AppState.js';
|
| 43 |
import { getEffortSuffix } from '../../utils/effort.js';
|
| 44 |
import { useMainLoopModel } from '../../hooks/useMainLoopModel.js';
|
| 45 |
import { renderModelSetting } from '../../utils/model/model.js';
|
|
@@ -158,6 +158,61 @@ export function LogoV2() {
|
|
| 158 |
useEffect(t7, t8);
|
| 159 |
const model = useMainLoopModel();
|
| 160 |
const fullModelDisplayName = renderModelSetting(model);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
const {
|
| 162 |
version,
|
| 163 |
cwd,
|
|
|
|
| 39 |
import { useShowGuestPassesUpsell, incrementGuestPassesSeenCount } from './GuestPassesUpsell.js';
|
| 40 |
import { useShowOverageCreditUpsell, incrementOverageCreditUpsellSeenCount, createOverageCreditFeed } from './OverageCreditUpsell.js';
|
| 41 |
import { plural } from '../../utils/stringUtils.js';
|
| 42 |
+
import { useAppState, useSetAppState } from '../../state/AppState.js';
|
| 43 |
import { getEffortSuffix } from '../../utils/effort.js';
|
| 44 |
import { useMainLoopModel } from '../../hooks/useMainLoopModel.js';
|
| 45 |
import { renderModelSetting } from '../../utils/model/model.js';
|
|
|
|
| 158 |
useEffect(t7, t8);
|
| 159 |
const model = useMainLoopModel();
|
| 160 |
const fullModelDisplayName = renderModelSetting(model);
|
| 161 |
+
const setAppState = useSetAppState();
|
| 162 |
+
|
| 163 |
+
// Poll for OpenRouter models when using 'default' model
|
| 164 |
+
useEffect(() => {
|
| 165 |
+
let mounted = true
|
| 166 |
+
let pollTimer: NodeJS.Timeout | null = null
|
| 167 |
+
|
| 168 |
+
async function checkOpenRouterCache() {
|
| 169 |
+
try {
|
| 170 |
+
const { getAPIProvider } = await import('../../utils/model/providers.js')
|
| 171 |
+
const provider = getAPIProvider()
|
| 172 |
+
|
| 173 |
+
if (provider === 'openrouter' && model === 'default') {
|
| 174 |
+
// Check cache every 500ms
|
| 175 |
+
pollTimer = setInterval(async () => {
|
| 176 |
+
if (!mounted) {
|
| 177 |
+
if (pollTimer) clearInterval(pollTimer)
|
| 178 |
+
return
|
| 179 |
+
}
|
| 180 |
+
|
| 181 |
+
try {
|
| 182 |
+
const { hasOpenRouterModelsCache } = await import('../../utils/model/openRouterModels.js')
|
| 183 |
+
if (hasOpenRouterModelsCache()) {
|
| 184 |
+
// Cache is now populated, trigger re-render
|
| 185 |
+
if (mounted) {
|
| 186 |
+
setAppState(prev => ({ ...prev, authVersion: prev.authVersion + 1 }))
|
| 187 |
+
}
|
| 188 |
+
if (pollTimer) clearInterval(pollTimer)
|
| 189 |
+
}
|
| 190 |
+
} catch (error) {
|
| 191 |
+
console.error('Error checking OpenRouter cache:', error)
|
| 192 |
+
if (pollTimer) clearInterval(pollTimer)
|
| 193 |
+
}
|
| 194 |
+
}, 500)
|
| 195 |
+
|
| 196 |
+
// Stop polling after 10 seconds
|
| 197 |
+
setTimeout(() => {
|
| 198 |
+
if (pollTimer && mounted) {
|
| 199 |
+
clearInterval(pollTimer)
|
| 200 |
+
pollTimer = null
|
| 201 |
+
}
|
| 202 |
+
}, 10000)
|
| 203 |
+
}
|
| 204 |
+
} catch (error) {
|
| 205 |
+
console.error('Error checking API provider:', error)
|
| 206 |
+
}
|
| 207 |
+
}
|
| 208 |
+
|
| 209 |
+
checkOpenRouterCache()
|
| 210 |
+
|
| 211 |
+
return () => {
|
| 212 |
+
mounted = false
|
| 213 |
+
if (pollTimer) clearInterval(pollTimer)
|
| 214 |
+
}
|
| 215 |
+
}, [model, setAppState])
|
| 216 |
const {
|
| 217 |
version,
|
| 218 |
cwd,
|
src/hooks/useMainLoopModel.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
| 13 |
export function useMainLoopModel(): ModelName {
|
| 14 |
const mainLoopModel = useAppState(s => s.mainLoopModel)
|
| 15 |
const mainLoopModelForSession = useAppState(s => s.mainLoopModelForSession)
|
|
|
|
| 16 |
|
| 17 |
// parseUserSpecifiedModel reads tengu_ant_model_override via
|
| 18 |
// _CACHED_MAY_BE_STALE (in resolveAntModel). Until GB init completes,
|
|
|
|
| 13 |
export function useMainLoopModel(): ModelName {
|
| 14 |
const mainLoopModel = useAppState(s => s.mainLoopModel)
|
| 15 |
const mainLoopModelForSession = useAppState(s => s.mainLoopModelForSession)
|
| 16 |
+
const authVersion = useAppState(s => s.authVersion)
|
| 17 |
|
| 18 |
// parseUserSpecifiedModel reads tengu_ant_model_override via
|
| 19 |
// _CACHED_MAY_BE_STALE (in resolveAntModel). Until GB init completes,
|