Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(model-sync): store real provider in log summary
R.D.a07e64302099
diff --git a/src/app/api/providers/[id]/sync-models/route.ts b/src/app/api/providers/[id]/sync-models/route.tsindex 581cc6a73e..3792aa204b 100644--- a/src/app/api/providers/[id]/sync-models/route.ts+++ b/src/app/api/providers/[id]/sync-models/route.ts@@ -123,6 +123,8 @@ function getModelSyncChannelLabel(connection: unknown) {export async function POST(request: Request, { params }: { params: Promise<{ id: string }> }) {const start = Date.now();const { id } = await params;+ let logProvider = "unknown";+ let channelLabel: string | null = null;try {if (!(await isAuthenticated(request)) && !isModelSyncInternalRequest(request)) {@@ -137,7 +139,8 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:return NextResponse.json({ error: "Connection not found" }, { status: 404 });}- const providerLabel = getModelSyncChannelLabel(connection);+ logProvider = toNonEmptyString(connection.provider) || "unknown";+ channelLabel = getModelSyncChannelLabel(connection);// Fetch models from the existing /api/providers/[id]/models endpointconst origin = new URL(request.url).origin;@@ -160,7 +163,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:path: `/api/providers/${id}/models`,status: modelsRes.status,model: "model-sync",- provider: providerLabel,+ provider: logProvider,sourceFormat: "-",connectionId: id,duration,@@ -177,7 +180,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:const fetchedModels = modelsData.models || [];// Filter out models already in the built-in registry- const registryIds = new Set(getModelsByProviderId(connection.provider).map((m: any) => m.id));+ const registryIds = new Set(getModelsByProviderId(logProvider).map((m: any) => m.id));// Replace the full model listconst models = fetchedModels@@ -188,14 +191,14 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:})).filter((m: any) => m.id && !registryIds.has(m.id));- const previousModels = await getCustomModels(connection.provider);- const replaced = await replaceCustomModels(connection.provider, models);+ const previousModels = await getCustomModels(logProvider);+ const replaced = await replaceCustomModels(logProvider, models);const modelChanges = summarizeModelChanges(previousModels, replaced);let syncedAliases = 0;- if (usesManagedAvailableModels(connection.provider)) {+ if (usesManagedAvailableModels(logProvider)) {const aliasSync = await syncManagedAvailableModelAliases(- connection.provider,+ logProvider,models.map((model: any) => model.id));syncedAliases = aliasSync.assignedAliases.length;@@ -207,7 +210,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:path: `/api/providers/${id}/models`,status: 200,model: "model-sync",- provider: providerLabel,+ provider: logProvider,sourceFormat: "-",connectionId: id,duration: Date.now() - start,@@ -215,8 +218,8 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:responseBody: {syncedModels: models.length,syncedAliases,- provider: connection.provider,- channel: providerLabel,+ provider: logProvider,+ channel: channelLabel,modelChanges,},});@@ -224,7 +227,7 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:return NextResponse.json({ok: true,- provider: connection.provider,+ provider: logProvider,syncedModels: replaced.length,syncedAliases,modelChanges,@@ -238,12 +241,19 @@ export async function POST(request: Request, { params }: { params: Promise<{ id:path: `/api/providers/${id}/sync-models`,status: 500,model: "model-sync",- provider: "unknown",+ provider: logProvider,sourceFormat: "-",connectionId: id,duration: Date.now() - start,error: error.message || "Sync failed",requestType: "model-sync",+ ...(channelLabel+ ? {+ responseBody: {+ channel: channelLabel,+ },+ }+ : {}),}).catch(() => {});return NextResponse.json({ error: error.message || "Failed to sync models" }, { status: 500 });diff --git a/tests/unit/model-sync-route.test.mjs b/tests/unit/model-sync-route.test.mjsindex 5d1d9e7e18..511bc2a16a 100644--- a/tests/unit/model-sync-route.test.mjs+++ b/tests/unit/model-sync-route.test.mjs@@ -29,14 +29,14 @@ test("model sync route skips success log when fetched models do not change storeawait resetStorage();const connection = await providersDb.createProviderConnection({- provider: "openai",+ provider: "openrouter",authType: "apikey",name: "MAIN",- displayName: "channel-east",+ displayName: "OpenRouter Main",apiKey: "test-key",});- await modelsDb.replaceCustomModels("openai", [+ await modelsDb.replaceCustomModels("openrouter", [{id: "custom-model-1",name: "Custom Model 1",@@ -73,14 +73,14 @@ test("model sync route skips success log when fetched models do not change store}});-test("model sync route logs changed model syncs against the current channel label", async () => {+test("model sync route stores the real provider while keeping the account label", async () => {await resetStorage();const connection = await providersDb.createProviderConnection({- provider: "openai",+ provider: "openrouter",authType: "apikey",name: "MAIN",- displayName: "channel-west",+ displayName: "OpenRouter Main",apiKey: "test-key",});@@ -105,10 +105,12 @@ test("model sync route logs changed model syncs against the current channel labeconst body = await response.json();assert.equal(body.logged, true);assert.deepEqual(body.modelChanges, { added: 1, removed: 0, updated: 0, total: 1 });+ assert.equal(body.provider, "openrouter");const logs = await callLogs.getCallLogs({ model: "model-sync", limit: 10 });assert.equal(logs.length, 1);- assert.equal(logs[0].provider, "channel-west");+ assert.equal(logs[0].provider, "openrouter");+ assert.equal(logs[0].account, "MAIN");assert.equal(logs[0].model, "model-sync");} finally {globalThis.fetch = originalFetch;