refactor: centralize oauth identity and route refresh workflow

This commit is contained in:
Cita
2026-03-23 11:53:59 +08:00
parent 328b492ab3
commit 3877f3a3f1
22 changed files with 361 additions and 78 deletions
@@ -11,7 +11,7 @@ import { buildOauthProviderHeaders } from '../../services/oauth/service.js';
import { getOauthInfoFromAccount } from '../../services/oauth/oauthAccount.js';
import { refreshOauthAccessTokenSingleflight } from '../../services/oauth/refreshSingleflight.js';
import { resolveChannelProxyUrl, withSiteRecordProxyRequestInit } from '../../services/siteProxy.js';
import { refreshModelsAndRebuildRoutes } from '../../services/modelService.js';
import * as routeRefreshWorkflow from '../../services/routeRefreshWorkflow.js';
import { getDownstreamRoutingPolicy } from '../../routes/proxy/downstreamPolicy.js';
import { executeEndpointFlow, type BuiltEndpointRequest } from '../../routes/proxy/endpointFlow.js';
import { composeProxyLogMessage } from '../../routes/proxy/logPathMeta.js';
@@ -278,7 +278,7 @@ export async function geminiProxyRoute(app: FastifyInstance) {
if (!isDirectGeminiFamilyPlatform(selected.site.platform)) {
let models = await readRouteAwareGeminiModels(request);
if (models.length <= 0) {
await refreshModelsAndRebuildRoutes();
await routeRefreshWorkflow.refreshModelsAndRebuildRoutes();
models = await readRouteAwareGeminiModels(request);
}
return reply.code(200).send({ models });
@@ -1,4 +1,4 @@
import { refreshModelsAndRebuildRoutes } from '../../services/modelService.js';
import * as routeRefreshWorkflow from '../../services/routeRefreshWorkflow.js';
import { formatUtcSqlDateTime } from '../../services/localTimeService.js';
import { resolveChannelProxyUrl, withSiteRecordProxyRequestInit } from '../../services/siteProxy.js';
import type { SiteProxyConfigLike } from '../../services/siteProxy.js';
@@ -86,7 +86,7 @@ export async function selectSurfaceChannelForAttempt(input: {
);
if (!selected && input.retryCount === 0) {
await refreshModelsAndRebuildRoutes();
await routeRefreshWorkflow.refreshModelsAndRebuildRoutes();
selected = await tokenRouter.selectChannel(input.requestedModel, input.downstreamPolicy);
}