diff --git a/scripts/sync-atlascloud-models.ts b/scripts/sync-atlascloud-models.ts index 0455116e6..1de03d9ac 100644 --- a/scripts/sync-atlascloud-models.ts +++ b/scripts/sync-atlascloud-models.ts @@ -1,4 +1,4 @@ -import { and, eq } from "drizzle-orm"; +import { and, eq, inArray } from "drizzle-orm"; import { fetchAtlasCloudImagePresets } from "../lib/ai/atlascloud-models"; import { db } from "../lib/db"; import { aiModel, aiProvider } from "../lib/db/schema"; @@ -22,6 +22,9 @@ async function main() { } const summaries = []; + const catalogModelIds = new Set( + catalog.presets.map((preset) => preset.modelId) + ); for (const provider of providers) { let added = 0; let updated = 0; @@ -65,11 +68,34 @@ async function main() { added += 1; } } + const providerModels = await db + .select({ modelId: aiModel.modelId }) + .from(aiModel) + .where(eq(aiModel.providerId, provider.id)); + const staleModelIds = providerModels + .map((model) => model.modelId) + .filter((modelId) => !catalogModelIds.has(modelId)); + if (staleModelIds.length > 0) { + await db + .update(aiModel) + .set({ + isEnabled: false, + isHidden: true, + updatedAt: new Date(), + }) + .where( + and( + eq(aiModel.providerId, provider.id), + inArray(aiModel.modelId, staleModelIds) + ) + ); + } summaries.push({ providerId: provider.id, providerName: provider.name, added, updated, + disabledStale: staleModelIds.length, }); }