Skip to content

feat: filter discovered models via includeModels/excludeModels - #27

Merged
yuseferi merged 1 commit into
mainfrom
feat/model-filtering
Sep 11, 2026
Merged

yuseferi merged 1 commit into
mainfrom
feat/model-filtering

Conversation

@yuseferi

Copy link
Copy Markdown
Owner

Summary

Implements #21's feature on top of the post-v1.0 codebase. Per-provider includeModels / excludeModels glob options let one LiteLLM proxy be split across several OpenCode providers (e.g. one provider per naming prefix or environment) without hand-maintaining a model list.

Credit and a big thank-you to @zyc (Cleverson Sacramento) — the design, the minimal *-only glob implementation, and the option semantics are all theirs. This PR carries their work forward with two adaptations and lands it as a clean rebase was no longer practical after #24/#26 rewrote the surrounding code.

Behavior

  • includeModels evaluated first — only ids matching at least one pattern are kept; omit it to keep everything.
  • excludeModels evaluated after and always wins.
  • Patterns support only *; everything else matches literally (dots in gpt-4.1 need no escaping).
  • Empty or omitted arrays mean "no filter"; non-string entries are dropped, so a typo'd option degrades toward no filtering rather than an empty provider.
  • A warning is logged when the filters remove every discovered model (a typo'd glob is the likeliest misuse).

Why applied in discoverModels() instead of at merge time (the #21 review follow-up)

In #21 the filter ran in the cold discovery path only. On the current architecture that silently lapses: backgroundRefresh() writes an unfiltered result into the SWR cache, and the next startup's cache-hit path merges it without filtering. Here the filter runs inside discoverModels(), so cold discovery and background refresh persist the same filtered view, and each provider's cache (already keyed providerId@baseURL) holds exactly its own slice.

Type of change

  • ✨ New feature (non-breaking) — fully backward-compatible; without the options nothing changes

Checklist

  • npm run typecheck passes
  • npm test — 35 tests pass, including 7 new passesModelFilter cases (include/exclude/precedence, empty arrays, literal metacharacters, mid-pattern stars, case sensitivity)
  • No new runtime dependencies
  • README updated (features table + "Splitting one proxy into multiple providers" section)
  • Conventional Commits (with Co-authored-by trailer)

Closes #21

Per-provider glob filters (only `*`, everything else literal) let one
LiteLLM proxy be split across several OpenCode providers without
hand-maintained model lists. includeModels is evaluated first,
excludeModels always wins, and empty/omitted arrays mean no filtering.

Based on #21 by Cleverson Sacramento, with two changes for the
post-v1.0 architecture: the filter is applied inside discoverModels()
rather than at merge time, so the SWR cache and background refresh
write the same filtered view instead of the filter silently lapsing
after the first refresh; and the dead V2-schema path it also touched
no longer exists.

Co-authored-by: Cleverson Sacramento <cleverson.sacramento@gmail.com>
@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown

Warning

Review limit reached

Next included review available in 37 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: e7e941c6-761c-4732-aafa-5d40969cc400

📥 Commits

Reviewing files that changed from the base of the PR and between 9c40068 and d0a4bc1.

📒 Files selected for processing (5)
  • README.md
  • src/plugin/index.ts
  • src/utils/index.ts
  • src/utils/model-filter.ts
  • test/model-filter.test.ts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@yuseferi
yuseferi merged commit 42c7ea7 into main Sep 11, 2026
4 checks passed
github-actions Bot pushed a commit that referenced this pull request Sep 11, 2026
# [1.1.0](v1.0.1...v1.1.0) (2026-09-11)

### Features

* filter discovered models via includeModels/excludeModels ([#27](#27)) ([42c7ea7](42c7ea7)), closes [#21](#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