Repository navigation
feat: add modelNameTemplate for discovered model display names - #55
Conversation
|
Caution Review failedThe pull request is closed. No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Adds a per-provider template that wraps every discovered model's display
name with that provider's context, so several providers backed by the
same LiteLLM proxy stay distinguishable in the picker.
Placeholders are {name}, {id}, {provider_id} and {provider_name}. The
default is "{name}", normalized to "unset" so existing cache keys stay
warm. An explicit models.<id>.name still wins and is never templated.
The template is applied once in toConfigModel, so the chat provider and
the Responses sibling inherit it, and it is threaded through cold
discovery, background refresh and the OpenCode 2 provider source. The
template and the resolved provider name are part of the cache identity,
so changing either starts a fresh discovery instead of serving stale
names.
Closes #52
- Re-render Responses-sibling names on OpenCode 1 so `{provider_id}` and
`{provider_name}` resolve to the provider the model is selected through,
without mutating the cached discovery entries OpenCode 2 shares.
- Derive the sibling's generated label from the base provider's name, or
its id when unnamed, so its label and `{provider_name}` agree.
- Use the provider id as the `{provider_name}` fallback when no name is
configured, instead of the shared `LiteLLM (proxy)` label.
- Keep the host's own `modelNameTemplate` setting intact (later
reconciles re-derive naming from it); plugin-level options still never
reach provider settings.
- Widen `formatModelName` to `Pick<LiteLLMModel, 'id'>` and share one
base-name helper between discovery and the sibling rename.
- Tests for the sibling placeholders (named and unnamed base), the v2
provider-settings path, and the plugin-option stripping path.
Rebase of the SSO credential keying (main) onto the sibling placeholder resolution (#55) crossed exactly here: a sign-in's Responses sibling must both re-render its models with the sibling's own provider identity and keep the sign-in runtime fetch with the placeholder key its runtime package insists on. Extends the existing auth-v1 sibling test to hold both behaviors at once, so neither side of the merge can regress alone.
1ca824d to
b4e8f0f
Compare
Closes #52.
Adds an optional
modelNameTemplatesetting per provider. Every discovered model's display name is built from it, so two providers backed by the same proxy and different keys stop showing identical entries in the picker.Behaviour
{name}(today's formatted name, or the raw id withformatModelNames: false),{id},{provider_id},{provider_name}."{name}", so behaviour is unchanged. It also normalizes to "unset", so existing cache keys stay warm instead of rediscovering on upgrade.models.<id>.namestill wins and is never templated.{id}is inserted literally rather than expanded again.{provider_name}is the provider's configured name, or its id when none is set.<provider>-responsessibling, so{provider_id}/{provider_name}resolve to that sibling for those models (the sibling's generated label is<base name or id> Responses). The cached entries stay as discovered, because OpenCode 2 reads the same cache with a single provider.formatModelNames: the template and the resolved provider name go into the fingerprint, so a template change or a provider rename triggers a fresh discovery instead of serving stale names. Without a template the key is byte-identical to today's.Implementation
applyModelNameTemplate/ModelNaminginsrc/utils/format-model-name.ts;readModelNameTemplatenext toreadFormatModelNames.toConfigModel; the Responses sibling re-renders its own names at injection time without mutating the cache.discoverModels,refreshContextsand the v2ProviderSource.buildCacheKeytakesModelNamingand appends the template + resolved provider name to the fingerprint only when a template is set.runtimeSettingsstrips the plugin-levelmodelNameTemplateoption, so a plugin option never lands in the host's provider settings. A template already present inprovider.settingsis preserved — it is the host's own config and later reconciles re-derive the naming and cache key from it.Tests
test/to-config-model.test.ts: every placeholder, raw-id composition, unknown placeholders, single-pass substitution, provider-name fallback, empty template, reader normalization.test/model-cache.test.ts: key changes on template or provider rename, and stays plain when no template is set.test/plugin-v1.test.ts: templated injection, curated names preserved, cache keyed by the template, sibling placeholders for named and unnamed bases.test/plugin-v2.test.ts: templated model registration fromprovider.settings, curated name preserved, setting preserved, plugin-level option kept out ofinfo.settings,{provider_name}id fallback, cache keyed by the template.npm run typecheckclean;npm test186/186.Summary by CodeRabbit
{name},{id},{provider_id}, and{provider_name}. Templates are applied after existing name formatting; explicitly configured model names remain unchanged.