Skip to content

refactor(gateway): extract isFreeModel from models.ts - #3398

Merged
markijbema merged 1 commit into
mainfrom
mark/extract-is-free-model
May 21, 2026
Merged

markijbema merged 1 commit into
mainfrom
mark/extract-is-free-model

Conversation

@markijbema

Copy link
Copy Markdown
Contributor

Summary

  • Extracts isFreeModel from apps/web/src/lib/ai-gateway/models.ts into a new apps/web/src/lib/ai-gateway/is-free-model.ts. No behavior change.
  • Why: models.ts is reachable from client bundles via constants like PRIMARY_DEFAULT_MODEL and preferredModels (imported by ModelCombobox.tsx, AutoFixConfigForm.tsx, OrganizationProvidersAndModelsPage.tsx, etc.). Follow-up work needs isFreeModel to consult a Redis-backed membership set; doing that inside models.ts would drag the Redis client into client bundles and break next build with Module not found: 'net'/'tls'/'dns/promises'. Splitting now sets up a clean home for the function before that follow-up lands.
  • isOpenRouterStealthModel is exported (was file-private) so the new module can use it.

Verification

  • pnpm --filter web typecheck clean.
  • pnpm --filter web test -- src/lib/ai-gateway/models.test.ts — 18/18 pass (test file's import of isFreeModel was updated to point at the new module).

Visual Changes

N/A.

Reviewer Notes

  • Six server-side importers updated mechanically (route.ts, embeddings/route.ts, fim/completions/route.ts, processUsage.ts, agent-runner.ts, openrouter/index.ts).
  • The follow-up that motivated this lives on the experiment-models PR (feat(gateway): route and persist model experiments #3325) — once this lands, that branch trivially folds the experiment-membership check into is-free-model.ts without touching any client-reachable file.

models.ts is reachable from client bundles via constants like PRIMARY_DEFAULT_MODEL and preferredModels (imported by ModelCombobox.tsx, AutoFixConfigForm.tsx, OrganizationProvidersAndModelsPage.tsx, etc.). Future implementations of isFreeModel will need to consult server-only resources (e.g. a Redis-backed membership set), and folding those imports into models.ts would drag the relevant clients into client bundles.

Move the function to its own apps/web/src/lib/ai-gateway/is-free-model.ts. No behavior change; body is identical. isOpenRouterStealthModel becomes exported so the new file can use it.
@kilo-code-bot

kilo-code-bot Bot commented May 21, 2026 •

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Executive Summary

Clean extraction of isFreeModel from models.ts into is-free-model.ts with no behavior change; all six server-side callsites and the test file updated mechanically.

Files Reviewed (8 files)
  • apps/web/src/lib/ai-gateway/is-free-model.ts — new file, logic identical to removed function
  • apps/web/src/lib/ai-gateway/models.ts — isFreeModel removed, isOpenRouterStealthModel exported
  • apps/web/src/lib/ai-gateway/models.test.ts — import updated
  • apps/web/src/lib/ai-gateway/processUsage.ts — import updated
  • apps/web/src/lib/ai-gateway/providers/openrouter/index.ts — import updated
  • apps/web/src/lib/bot/agent-runner.ts — import updated
  • apps/web/src/app/api/fim/completions/route.ts — import updated
  • apps/web/src/app/api/openrouter/[...path]/route.ts — import updated
  • apps/web/src/app/api/openrouter/embeddings/route.ts — import updated

Fix these issues in Kilo Cloud


Reviewed by claude-sonnet-4.6 · 207,477 tokens

Review guidance: REVIEW.md from base branch main

@markijbema
markijbema merged commit 8debbaf into main May 21, 2026
13 checks passed
@markijbema
markijbema deleted the mark/extract-is-free-model branch May 21, 2026 15:19
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