Skip to content

improvement(models): sort model dropdown by latest release date within each provider#5099

Merged
waleedlatif1 merged 2 commits into
stagingfrom
perf/model-dropdown-sort
Jun 16, 2026
Merged

improvement(models): sort model dropdown by latest release date within each provider#5099
waleedlatif1 merged 2 commits into
stagingfrom
perf/model-dropdown-sort

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Model dropdowns (agent, evaluator, router, guardrails, translate) now sort models within each provider group by latest release date (newest first), while keeping the existing provider grouping order
  • Added orderModelIdsByReleaseDate to the provider catalog (models.ts) — a pure display-ordering helper; undated models keep declaration order after dated ones, and unknown/dynamic-provider IDs are preserved at the end
  • Applied it in getModelOptions, so every model dropdown picks it up through the shared source

Type of Change

  • Improvement

Testing

  • Added unit tests for orderModelIdsByReleaseDate (provider grouping preserved, newest-first within provider, unknown IDs last, case-insensitive, no IDs added/dropped)
  • Existing blocks/utils.test.ts passing; typecheck clean

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jun 16, 2026 6:14pm

Request Review

@cursor

cursor Bot commented Jun 16, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Display-only reordering of dropdown options with no inference, auth, or persistence changes; behavior is covered by new unit tests.

Overview
Model comboboxes that use getModelOptions (agent, evaluator, router, guardrails, translate, etc.) now list catalog base models with newest releaseDate first inside each provider, without changing which provider group appears first.

Adds orderModelIdsByReleaseDate in models.ts: a one-time MODEL_CATALOG_INDEX from static PROVIDER_DEFINITIONS, then groups IDs by provider in first-seen input order, sorts each group by release date (undated models keep declaration order after dated ones), and leaves unknown / dynamic IDs at the end unchanged. getModelOptions runs this on providers.base.models only; Ollama, OpenRouter, and other runtime lists are untouched.

Unit tests cover grouping, newest-first ordering, cross-provider order, unknown IDs, case insensitivity, and stable ID sets.

Reviewed by Cursor Bugbot for commit 7ee4d97. Configure here.

Comment thread apps/sim/providers/models.ts Outdated
@greptile-apps

greptile-apps Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds a orderModelIdsByReleaseDate helper to models.ts and applies it in getModelOptions so that all model dropdowns (agent, evaluator, router, guardrails, translate) show models newest-first within each provider group. The MODEL_CATALOG_INDEX map is built once at module load from the static PROVIDER_DEFINITIONS constant, avoiding any per-call iteration overhead.

  • models.ts: Introduces MODEL_CATALOG_INDEX (module-scoped) and orderModelIdsByReleaseDate, which groups input IDs by provider (preserving first-seen provider order), sorts each group descending by releaseTime with a declIndex tiebreaker for undated/same-date models, and appends unknown/dynamic IDs at the end.
  • blocks/utils.ts: Single-line change wrapping base.models with orderModelIdsByReleaseDate in getModelOptions.
  • models.test.ts: New test file covering provider grouping, newest-first ordering, unknown IDs, case-insensitivity, empty input, and no-add/no-drop invariants.

Confidence Score: 5/5

Safe to merge — the change is a pure display-ordering helper with no effect on stored state, execution, or dynamic providers.

The sorting logic is correct: Number.NEGATIVE_INFINITY as the sentinel for undated models means the NEGATIVE_INFINITY !== NEGATIVE_INFINITY branch is never taken (falls through to the declIndex tiebreaker, avoiding any NaN in the comparator). MODEL_CATALOG_INDEX is built once at module load. The only affected path is the model dropdown render in getModelOptions, which is a read-only, side-effect-free operation. Tests cover all documented invariants.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/providers/models.ts Adds MODEL_CATALOG_INDEX (module-scoped, built once) and orderModelIdsByReleaseDate; logic is correct, sentinel value (NEGATIVE_INFINITY) for undated models correctly prevents NaN in the comparator
apps/sim/blocks/utils.ts One-line change applying orderModelIdsByReleaseDate to base.models (a string[]) in getModelOptions; dynamic provider models are unaffected and appended after
apps/sim/providers/models.test.ts Comprehensive new unit-test suite for orderModelIdsByReleaseDate covering all documented invariants; test-local index mirrors production logic consistently

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["getModelOptions()"] --> B["providersState.providers.base.models\n(string[])"]
    B --> C["orderModelIdsByReleaseDate(modelIds)"]
    C --> D{"For each ID:\nlookup MODEL_CATALOG_INDEX"}
    D -- "Found" --> E["Group by providerId\n(Map, insertion-order preserved)"]
    D -- "Not found" --> F["unknown[] — dynamic provider IDs"]
    E --> G["Sort each bucket:\nnewer releaseTime first\ndeclIndex tiebreaker"]
    G --> H["ordered: string[]"]
    F --> I["Append unknown IDs at end"]
    H --> I
    I --> J["allModels = Set([...baseModels, ...ollamaModels, ...])"]
    J --> K["Return model options for dropdown"]

    M["MODULE LOAD\nMODEL_CATALOG_INDEX\nbuilt once from\nPROVIDER_DEFINITIONS"] -.-> D
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A["getModelOptions()"] --> B["providersState.providers.base.models\n(string[])"]
    B --> C["orderModelIdsByReleaseDate(modelIds)"]
    C --> D{"For each ID:\nlookup MODEL_CATALOG_INDEX"}
    D -- "Found" --> E["Group by providerId\n(Map, insertion-order preserved)"]
    D -- "Not found" --> F["unknown[] — dynamic provider IDs"]
    E --> G["Sort each bucket:\nnewer releaseTime first\ndeclIndex tiebreaker"]
    G --> H["ordered: string[]"]
    F --> I["Append unknown IDs at end"]
    H --> I
    I --> J["allModels = Set([...baseModels, ...ollamaModels, ...])"]
    J --> K["Return model options for dropdown"]

    M["MODULE LOAD\nMODEL_CATALOG_INDEX\nbuilt once from\nPROVIDER_DEFINITIONS"] -.-> D
Loading

Reviews (2): Last reviewed commit: "fix(models): preserve input provider ord..." | Re-trigger Greptile

Comment thread apps/sim/providers/models.ts Outdated
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@cursor review

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 7ee4d97. Configure here.

@waleedlatif1 waleedlatif1 merged commit c864a92 into staging Jun 16, 2026
16 checks passed
@waleedlatif1 waleedlatif1 deleted the perf/model-dropdown-sort branch June 16, 2026 18:21
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.

1 participant