-
-
Notifications
You must be signed in to change notification settings - Fork 312
chore: fetch Lovable AI Gateway model catalog in the daily sync #1251
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
Merged
AlemTuzlak
merged 1 commit into
TanStack:main
from
daniel-trevino:daniel-trevino/fetch-lovable-gateway-models
Aug 26, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| /** | ||
| * Fetches models from the Lovable AI Gateway API and writes them to | ||
| * lovable-gateway.models.json. | ||
| * | ||
| * Usage: | ||
| * pnpm tsx scripts/fetch-lovable-gateway-models.ts | ||
| * | ||
| * The endpoint is public β no API key required. | ||
| * | ||
| * The output is plain JSON so a malicious or compromised upstream response | ||
| * cannot smuggle executable code into the build (JSON.stringify cannot produce | ||
| * a JS expression). The committed wrapper at `lovable-gateway.models.ts` | ||
| * re-exports this JSON typed as `Array<LovableGatewayCatalogModel>`. | ||
| */ | ||
|
|
||
| import { writeFile } from 'node:fs/promises' | ||
| import { dirname, resolve } from 'node:path' | ||
| import { fileURLToPath } from 'node:url' | ||
|
|
||
| const __dirname = dirname(fileURLToPath(import.meta.url)) | ||
| const OUTPUT_PATH = resolve(__dirname, 'lovable-gateway.models.json') | ||
| const API_URL = 'https://ai.gateway.lovable.dev/v1/models' | ||
|
|
||
| interface ApiModel { | ||
| id: string | ||
| [key: string]: unknown | ||
| } | ||
|
|
||
| function isValidModel(model: unknown): model is ApiModel { | ||
| return ( | ||
| typeof model === 'object' && | ||
| model !== null && | ||
| typeof (model as { id?: unknown }).id === 'string' && | ||
| (model as { id: string }).id.length > 0 | ||
| ) | ||
| } | ||
|
|
||
| async function main() { | ||
| console.log(`Fetching models from ${API_URL}...`) | ||
|
|
||
| const response = await fetch(API_URL, { | ||
| headers: { Accept: 'application/json' }, | ||
| signal: AbortSignal.timeout(30_000), | ||
| }) | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error( | ||
| `Failed to fetch Lovable AI Gateway models: ${response.status} ${response.statusText}`, | ||
| ) | ||
| } | ||
|
|
||
| const json = (await response.json()) as { data?: unknown } | ||
| if (!Array.isArray(json.data)) { | ||
| throw new Error( | ||
| 'Lovable AI Gateway /v1/models response is missing a data array', | ||
| ) | ||
| } | ||
|
|
||
| const allModels = json.data | ||
| const validModels = allModels.filter(isValidModel) | ||
| const skipped = allModels.length - validModels.length | ||
| if (skipped > 0) { | ||
| console.log(`Skipped ${skipped} models missing a string id`) | ||
| } | ||
|
|
||
| validModels.sort((a, b) => a.id.localeCompare(b.id)) | ||
|
|
||
| await writeFile( | ||
| OUTPUT_PATH, | ||
| JSON.stringify(validModels, null, 2) + '\n', | ||
| 'utf-8', | ||
| ) | ||
| console.log(`Fetched ${validModels.length} models`) | ||
| console.log(`Written to ${OUTPUT_PATH}`) | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error) | ||
| process.exit(1) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
ποΈ Data Integrity & Integration | π‘ Minor | β‘ Quick win
The commit gate never triggers on a Lovable-only catalog change.
The
changesstep at lines 36-40 setschanged=trueonly whenpackages/differs. Nothing regenerates package code from the Lovable catalog today, so a run where onlyscripts/lovable-gateway.models.jsonchanges stays atchanged=false. The commit and push steps are skipped, and the fetched catalog is dropped. The committed file then stays stale until an unrelated OpenRouter or Vercel change movespackages/.Include the staged script data in the gate.
π§ Proposed fix for the change gate
π€ Prompt for AI Agents