Repository navigation
feat(website): retire /p/supported-models into /hub/models #20192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| import { describe, expect, it } from 'vitest' | ||
|
|
||
| import { compileSupportedModelUrls } from './generate-supported-model-urls' | ||
|
|
||
| const hubPages = [ | ||
| { newSlug: 'wan-2-7-image-to-video', name: 'Wan 2.7 Image-to-Video' }, | ||
| { newSlug: 'wan-2-7-video-edit', name: 'Wan 2.7 Video Edit' }, | ||
| { newSlug: 'wan-2-7-text-to-video', name: 'Wan 2.7 Text-to-Video' }, | ||
| { newSlug: 'seedance-2-0-text-to-video', name: 'Seedance 2.0 Text-to-Video' }, | ||
| { | ||
| newSlug: 'seedance-2-0-fast-text-to-video', | ||
| name: 'Seedance 2.0 Fast Text-to-Video' | ||
| }, | ||
| { | ||
| newSlug: 'kling-2-6-pro-text-to-video-with-audio', | ||
| name: 'Kling 2.6 Pro Text-to-Video with Audio' | ||
| }, | ||
| { | ||
| newSlug: 'elevenlabs-text-to-dialogue', | ||
| name: 'ElevenLabs Text-to-Dialogue' | ||
| }, | ||
| { newSlug: 'nano-banana-image-edit', name: 'Nano Banana Image Edit' }, | ||
| { newSlug: 'nano-banana-text-to-image', name: 'Nano Banana Text-to-Image' } | ||
| ] | ||
| const providers = ['ElevenLabs', 'Kling'] | ||
|
|
||
| const hubSlugFor = (displayName: string) => | ||
| compileSupportedModelUrls( | ||
| [{ slug: 'page', displayName }], | ||
| hubPages, | ||
| providers | ||
| )[0][1] | ||
|
|
||
| describe('compileSupportedModelUrls', () => { | ||
| it.for([ | ||
| ['Wan 2.7', 'wan-2-7-text-to-video'], | ||
| ['Nano Banana', 'nano-banana-text-to-image'], | ||
| ['Seedance 2.0', 'seedance-2-0-text-to-video'], | ||
| ['Seedance 2', 'seedance-2-0-text-to-video'], | ||
| ['Kling 2.6', undefined], | ||
| ['ElevenLabs', undefined], | ||
| ['Wan', undefined], | ||
| ['Wan 2.7 Turbo', undefined], | ||
| ['wan2.7-vae-bf16', undefined] | ||
| ] as const)('sends "%s" to %s', ([displayName, hubSlug]) => { | ||
| expect(hubSlugFor(displayName)).toBe(hubSlug) | ||
| }) | ||
|
|
||
| it('resolves an alias through its canonical page', () => { | ||
| expect( | ||
| compileSupportedModelUrls( | ||
| [ | ||
| { slug: 'wan-27', canonicalSlug: 'wan2-7', displayName: 'Wan 27' }, | ||
| { slug: 'wan2-7', displayName: 'Wan 2.7' } | ||
| ], | ||
| hubPages, | ||
| providers | ||
| ) | ||
| ).toEqual([ | ||
| ['wan-27', 'wan-2-7-text-to-video'], | ||
| ['wan2-7', 'wan-2-7-text-to-video'] | ||
| ]) | ||
| }) | ||
|
|
||
| it('keeps frozen rows and slugs no longer in the data', () => { | ||
| expect( | ||
| compileSupportedModelUrls( | ||
| [{ slug: 'wan2-7', displayName: 'Wan 2.7' }], | ||
| hubPages, | ||
| providers, | ||
| [['wan2-7'], ['retired-page']] | ||
| ) | ||
| ).toEqual([['retired-page'], ['wan2-7']]) | ||
| }) | ||
| }) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,134 @@ | ||
| import { writeFile } from 'node:fs/promises' | ||
| import { join } from 'node:path' | ||
|
|
||
| import { websiteRoot } from '@website/paths' | ||
| import { modelPageUrls } from '@/config/model-urls' | ||
| import { models } from '@/config/models' | ||
| import type { SupportedModelUrl } from '@/config/supported-model-urls' | ||
| import { supportedModelUrls } from '@/config/supported-model-urls' | ||
| import { workshopModels } from '@/config/workshop-browse-content' | ||
| import { modelUrlSlug } from './generate-model-url-map' | ||
| import { isDirectExecution } from './script-entry-point' | ||
|
|
||
| interface SupportedModel { | ||
| readonly slug: string | ||
| readonly canonicalSlug?: string | ||
| readonly displayName: string | ||
| } | ||
|
|
||
| interface HubPage { | ||
| readonly newSlug: string | ||
| readonly name: string | ||
| } | ||
|
|
||
| /** Earlier wins when one model has several task pages. */ | ||
| const TASKS_BY_PRIORITY = [ | ||
| 'text-to-image', | ||
| 'text-to-vector', | ||
| 'text-to-video', | ||
| 'reference-to-video', | ||
| 'text-to-speech', | ||
| 'text-to-dialogue', | ||
| 'image-to-video', | ||
| 'first-last-frame', | ||
| 'video-continuation', | ||
| 'image-edit', | ||
| 'video-edit', | ||
| 'video-to-video', | ||
| 'audio-to-video' | ||
| ] as const | ||
|
|
||
| const taskOf = (slug: string) => | ||
| TASKS_BY_PRIORITY.find((task) => slug.endsWith(`-${task}`)) | ||
|
|
||
| const sameVersion = (slug: string) => slug.replace(/(\d)-0(?=-|$)/g, '$1') | ||
|
|
||
| const modelKey = (name: string) => sameVersion(modelUrlSlug(name)) | ||
|
|
||
| function hubModelKey({ name }: HubPage): string { | ||
| const slug = modelUrlSlug(name) | ||
| const task = taskOf(slug) | ||
| return sameVersion(task ? slug.slice(0, -task.length - 1) : slug) | ||
| } | ||
|
|
||
| const taskRank = (page: HubPage) => { | ||
| const task = taskOf(modelUrlSlug(page.name)) | ||
| return task ? TASKS_BY_PRIORITY.indexOf(task) : -1 | ||
| } | ||
|
|
||
| /** | ||
| * The Hub page for the same model, or undefined when there is none. A Hub | ||
| * page matches only when its name minus the task is the model's name, so a | ||
| * provider page (ElevenLabs) or another version (Kling 2.6 vs Kling 2.6 Pro) | ||
| * never matches. | ||
| */ | ||
| function supportedModelHubSlug( | ||
| name: string, | ||
| hubPages: readonly HubPage[], | ||
| providers: ReadonlySet<string> | ||
| ): string | undefined { | ||
| const key = modelKey(name) | ||
| if (providers.has(key)) return undefined | ||
| return hubPages | ||
| .filter((page) => hubModelKey(page) === key) | ||
| .sort( | ||
| (a, b) => | ||
| taskRank(a) - taskRank(b) || a.newSlug.localeCompare(b.newSlug, 'en') | ||
| ) | ||
| .at(0)?.newSlug | ||
| } | ||
|
|
||
| /** `frozen` rows keep their target; only slugs new to the table are matched. */ | ||
| export function compileSupportedModelUrls( | ||
| supportedModels: readonly SupportedModel[], | ||
| hubPages: readonly HubPage[], | ||
| providerNames: readonly string[], | ||
| frozen: readonly SupportedModelUrl[] = [] | ||
| ): SupportedModelUrl[] { | ||
| const providers = new Set(providerNames.map(modelKey)) | ||
| const bySlug = new Map(supportedModels.map((model) => [model.slug, model])) | ||
| const rows = new Map(frozen.map((row) => [row[0], row])) | ||
| for (const model of supportedModels) { | ||
| if (rows.has(model.slug)) continue | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟢 Low — Roughly 370 of the 380 generated rows are bare |
||
| const canonical = bySlug.get(model.canonicalSlug ?? model.slug) ?? model | ||
| const hubSlug = supportedModelHubSlug( | ||
| canonical.displayName, | ||
| hubPages, | ||
| providers | ||
| ) | ||
| rows.set(model.slug, hubSlug ? [model.slug, hubSlug] : [model.slug]) | ||
| } | ||
| return [...rows.values()].sort((a, b) => a[0].localeCompare(b[0], 'en')) | ||
| } | ||
|
|
||
| function renderSupportedModelUrlsModule( | ||
| rows: readonly SupportedModelUrl[] | ||
| ): string { | ||
| const line = (row: SupportedModelUrl) => | ||
| ` [${row.map((value) => `'${value}'`).join(', ')}]` | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Medium — Each value is interpolated into a single-quoted TypeScript literal with no escaping, so a slug containing |
||
| return `// Generated by scripts/generate-supported-model-urls.ts. Rows are frozen. | ||
| // Every published /p/supported-models/<slug> page, with the /hub/models/<slug> | ||
| // page for the same model. A row without one redirects to /hub/models/. | ||
| export type SupportedModelUrl = readonly [slug: string, hubSlug?: string] | ||
|
|
||
| export const supportedModelUrls: readonly SupportedModelUrl[] = [ | ||
| ${rows.map(line).join(',\n')} | ||
| ] | ||
| ` | ||
| } | ||
|
|
||
| if (isDirectExecution(process.argv[1], import.meta.filename)) { | ||
| const rows = compileSupportedModelUrls( | ||
| models, | ||
| modelPageUrls, | ||
| workshopModels.flatMap(({ provider }) => (provider ? [provider] : [])), | ||
| supportedModelUrls | ||
| ) | ||
| await writeFile( | ||
| join(websiteRoot, 'src/config/supported-model-urls.ts'), | ||
| renderSupportedModelUrlsModule(rows) | ||
| ) | ||
| console.warn( | ||
| `${rows.length} pages, ${rows.filter((row) => row[1]).length} with a Hub page` | ||
| ) | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Medium —
/(\d)-0(?=-|$)/gstrips-0after any digit anywhere in the key, not just a trailing.0, so a three-part version collapses onto a different model: a supported model namedModel 2.0.1keys asmodel-2-1and matches the Hub page forModel 2.1. Anchor the replacement to the end of the key, and/or throw when two supported models resolve to the same key, so a bad match surfaces instead of shipping as a permanent 308 that browsers cache and cannot be retracted. Raised by 3 of 8 reviewers (gpt-5.6-sol-max edge-case, claude-opus-5-thinking-max adversarial, kimi-k3-max edge-case).