feat(usage): add automatic models.dev pricing sync (#5734)

* feat(usage): persist model pricing in local config

* feat(usage): sync selected models.dev pricing on startup

* fix(usage): address models.dev sync review feedback

* fix(usage): harden local pricing synchronization
This commit is contained in:
Thefool
2026-07-28 23:37:55 +08:00
committed by GitHub
parent ff3bc242cc
commit 12b972a66e
20 changed files with 2672 additions and 195 deletions
+23
View File
@@ -19,6 +19,10 @@ import {
installGlobalErrorHandlers,
reportFrontendError,
} from "./lib/frontendLogger";
import {
MODELS_DEV_SYNC_CONFIG_QUERY_KEY,
syncModelsDevPricingOnStartup,
} from "./lib/modelsDevAutoSync";
installGlobalErrorHandlers();
@@ -124,6 +128,25 @@ async function bootstrap() {
</FrontendErrorBoundary>
</React.StrictMode>,
);
void syncModelsDevPricingOnStartup()
.then((result) => {
if (!result.skipped) {
return Promise.all([
queryClient.invalidateQueries({ queryKey: ["usage"] }),
queryClient.invalidateQueries({
queryKey: MODELS_DEV_SYNC_CONFIG_QUERY_KEY,
}),
]);
}
})
.catch((error) => {
// 离线或 models.dev 暂时不可用不应阻塞应用启动。
reportFrontendError("models_dev_startup_sync", error);
void queryClient.invalidateQueries({
queryKey: MODELS_DEV_SYNC_CONFIG_QUERY_KEY,
});
});
}
void bootstrap();