Skip to content

refactor(openrouter): remove unused properties from cron job Zod schemas#2575

Open
kilo-code-bot[bot] wants to merge 6 commits intomainfrom
fix/openrouter-schema-trim
Open

refactor(openrouter): remove unused properties from cron job Zod schemas#2575
kilo-code-bot[bot] wants to merge 6 commits intomainfrom
fix/openrouter-schema-trim

Conversation

@kilo-code-bot
Copy link
Copy Markdown
Contributor

@kilo-code-bot kilo-code-bot bot commented Apr 18, 2026

Summary

The `/api/cron/sync-providers` job fetches data from two OpenRouter API endpoints and stores a normalized subset in the DB. Large portions of the parsed response data were never read — either in the sync logic itself or downstream in the UI.

This PR removes all those unused fields, reducing the schemas to only what is actually consumed:

  • `OpenRouterBaseModel`: keeps `slug`, `name`, `author`, `description`, `context_length`, `input_modalities`, `output_modalities`, `group`, `updated_at`
  • `OpenRouterEndpoint`: keeps `provider_display_name`, `is_free`, `pricing` (`prompt` + `completion` only)
  • `OpenRouterSearchResponse`: removes `analytics` and `categories` from the `data` wrapper
  • `OpenRouterProvider`: keeps only the fields mapped into `NormalizedProvider` (`name`, `displayName`, `slug`, `dataPolicy`, `headquarters`, `datacenters`, `icon`)
  • Removes entirely: `OpenRouterIcon`, `OpenRouterDataPolicy`, `OpenRouterReasoningConfig`, `OpenRouterToolChoiceSupport`, `OpenRouterSupportedParameters`, `OpenRouterFeatures`, `OpenRouterProviderInfo`, `OpenRouterAnalyticsEntry`, `OpenRouterAnalytics`, `OpenRouterCategoryEntry`, `OpenRouterCategories`
  • `mappedExtraModels` construction in `sync-providers.ts` and storybook mock data slimmed down to match

~300 lines deleted, no functional behaviour changed.

Verification

  • Traced every field of each parsed type through its consumers (DB write → DB read → UI components) to confirm nothing is accidentally removed
  • `group` is kept — read by `getModelSeries` in `util.ts` to classify models by family
  • `updated_at` is kept — useful for debugging
  • Fields on `NormalizedOpenRouterResponse` (`total_providers`, `total_models`, `generated_at`) are kept — consumed by `syncAndStoreProviders`
  • typecheck, lint, format-check, drizzle-check all pass

Visual Changes

N/A

Reviewer Notes

Zod's default strip mode means existing DB rows with the old (wider) JSON shapes will still parse fine — the extra fields are silently ignored on read. Both `group` and `updated_at` have always been present in stored rows (they were in the original schema before this PR), so making them required does not risk breaking any existing data.

@kilo-code-bot
Copy link
Copy Markdown
Contributor Author

kilo-code-bot bot commented Apr 18, 2026

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (4 files)
  • apps/storybook/src/mockData/providers.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/openrouter-types.ts
  • apps/web/src/lib/ai-gateway/providers/openrouter/sync-providers.ts
  • packages/db/src/schema-types.ts

Reviewed by gpt-5.4-20260305 · 920,797 tokens

input_modalities: z.array(z.string()),
output_modalities: z.array(z.string()),
has_text_output: z.boolean(),
group: z.string(),
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: This makes existing models_by_provider.data rows unreadable until the cron job rewrites them

The previous commit intentionally stripped group out of the normalized snapshot, so the latest persisted rows in models_by_provider do not have this property. useOpenRouterModelsAndProviders() reparses that stored JSON with NormalizedOpenRouterResponse, so making group required here will reject the current DB payload and break the models-by-provider page until sync-providers runs again.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The concern isn't valid here: this PR has not been deployed to production, so all existing models_by_provider rows were written by the pre-PR cron job which did include group in the stored JSON (it was part of the original OpenRouterBaseModel schema). There is no window where rows without group could have been persisted in production. Zod will find the field present in every real DB row and parse it correctly.

Comment thread apps/web/src/components/models/util.ts Outdated
@kilo-code-bot kilo-code-bot bot force-pushed the fix/openrouter-schema-trim branch from 74d050e to e00512c Compare April 18, 2026 10:12
return {
slug: base?.slug ?? `${randomChoice(rng, PROVIDERS)}/${modelName}`,
hf_slug: base?.hf_slug ?? null,
updated_at: base?.updated_at ?? new Date().toISOString(),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dont we want this for debugging?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants