Strict plugin-only: no model / account / harness table left in core.
- plugins/providers: an unbound or never-seeded store reads the seed dir's
provider-*/harness-* manifests (PLUGINS_SEED_DIR, else the plugins
checkout, else backend/fixtures/typed_plugins) — once seeded, only what is
installed. Harness↔vendor helpers (vendors_of_harness, login_harness,
hosted_harnesses, accounts_for_harness, provider_config/secret).
- models/catalog + presets: list_models / is_local / context_window /
opencode_model / agy_model / pi_provider / key_of / vendor_of / guest pool
delegate to the registry; DEFAULT_MODEL, FAMILIES… computed (PEP 562).
openrouter.py reads the provider-openrouter plugin's catalogueUrl and its
api_key hub secret (OPENROUTER_API_KEY fallback).
- accounts: provider-owned; vendor-native helpers (accounts_for_vendor,
vendor_of_account, resolve_alias, wire_id) + compat for_harness /
valid_for / harness_of joined through harness.supports[]. Clean provider
accounts: keyless evox2 (alias opencode-lab, still sent to the sidecar as
opencode-lab), openrouter's own account — pi no longer bills `personal`.
- profiles: profile-level ★ per vendor (profile.accounts), per-machine
overrides on workers[i].accounts; idempotent migration of the harness-keyed
runner ★ on load (file version 3); default_login takes a vendor or a
harness; PUT|PATCH /api/profiles/{id} edits accounts. The API keeps
harness keys beside vendor keys in each runner's accounts/logins.
- runs/cron/scheduled: harness tuples → the registry (caps lean/fork,
runsOn lab, hosted harnesses); a new run routes model → vendor → the
profile's ★ for it.
- cli: --harness accepts any active harness (checked against
/api/providers); MCP drops its static enum.
- tests: golden-tables.json pins the old tables' answers; new
test_provider_accounts.py (migration, clean accounts, routing by vendor).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
181 lines
7.0 KiB
Python
181 lines
7.0 KiB
Python
"""
|
|
The models a session can run on — read from the provider & harness plugins.
|
|
|
|
Since the typed-plugins cutover (Wave 3A, 2026-11-26) there is **no model
|
|
table in core**: every model, its context window, its efforts and which
|
|
harness runs it come from the owner's enabled ``kind: "provider"`` /
|
|
``kind: "harness"`` plugins through ``plugins.providers`` (the
|
|
``ProviderRegistry``). A provider owns its canonical models (Anthropic's are
|
|
discovered live from ``/v1/models`` in the background, with the plugin's
|
|
static list as the cold-start copy); a harness's ``supports[]`` says which
|
|
vendors it runs and how a model id is spelled for it (an opencode EVOX2 twin is
|
|
``<server>/<id>``, a GPT priority tier ``<id>-fast``). ``list_models`` is
|
|
their product — the exact ``/api/models`` shape the composer reads.
|
|
|
|
Each entry carries:
|
|
``id`` the exact ``--model`` argument;
|
|
``family`` how the picker groups / colours it (opus, qwen, gpt…);
|
|
``version`` the human version within the family ("4.8");
|
|
``alias`` the CLI shorthand (``opus``) when the CLI has one;
|
|
``harness`` the harness it runs on (one entry per harness that lists it);
|
|
``provider`` the vendor (anthropic, openai, google, openrouter, evox2);
|
|
``contextWindow``, and per harness ``efforts`` / ``fast`` / ``server`` /
|
|
``twinEfforts``.
|
|
|
|
The helpers below (``is_local``, ``context_window``, ``opencode_model``…)
|
|
keep their old names and answers for the callers that predate the registry.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
|
|
from plugins import providers as _providers
|
|
|
|
|
|
def _reg():
|
|
return _providers.current()
|
|
|
|
|
|
def list_models(force: bool = False) -> list[dict]:
|
|
"""The pickable models: every active harness's entries, in harness order
|
|
(claude, pi, opencode, agy), each harness's default model first. Never
|
|
blocks on the network — live discovery refreshes in the background
|
|
(``plugins/providers.py``)."""
|
|
return _reg().catalog_entries()
|
|
|
|
|
|
def harness_ids() -> tuple[str, ...]:
|
|
return _reg().harness_ids()
|
|
|
|
|
|
def _entries_of(harness: str) -> list[dict]:
|
|
return [m for m in list_models() if m.get("harness") == harness]
|
|
|
|
|
|
def _default_model() -> str:
|
|
"""What a fresh claude spawn runs on when nothing is picked:
|
|
``SPAWN_DEFAULT_MODEL``, else the claude harness's ``defaultModel``, else
|
|
its first model (its CLI alias when it has one)."""
|
|
env = os.environ.get("SPAWN_DEFAULT_MODEL")
|
|
if env:
|
|
return env
|
|
reg = _reg()
|
|
h = reg.harnesses.get("claude")
|
|
if h and h.spec.get("defaultModel"):
|
|
return h.spec["defaultModel"]
|
|
first = next(iter(_entries_of("claude")), None)
|
|
return (first or {}).get("alias") or (first or {}).get("id") or ""
|
|
|
|
|
|
def _harness_default(harness: str) -> str | None:
|
|
h = _reg().harnesses.get(harness)
|
|
return h.spec.get("defaultModel") if h else None
|
|
|
|
|
|
def families() -> tuple[str, ...]:
|
|
"""The Claude families the picker offers (the anthropic provider's)."""
|
|
reg = _reg()
|
|
out: list[str] = []
|
|
for vid in reg.vendors_of_harness("claude"):
|
|
disc = (reg.providers[vid].spec.get("discovery") or {}).get("families")
|
|
for f in disc or list(reg.providers[vid].spec.get("families") or {}):
|
|
if f not in out:
|
|
out.append(f)
|
|
return tuple(out)
|
|
|
|
|
|
# ── per-harness lookups ─────────────────────────────────────────────────────
|
|
def opencode_model(model_id: str | None) -> dict | None:
|
|
if not model_id:
|
|
return None
|
|
return next((m for m in _entries_of("opencode") if m.get("id") == model_id), None)
|
|
|
|
|
|
def _strip_level(model_id: str | None) -> str:
|
|
"""A harness's per-level slug → its base id, by the pricing table's
|
|
``normalize.stripLevelRegex`` of whichever vendor declares one."""
|
|
mid = (model_id or "").strip()
|
|
reg = _reg()
|
|
for vid in reg.vendors_of_harness("agy"):
|
|
rx = ((reg.providers[vid].spec.get("pricing") or {}).get("normalize") or {}).get("stripLevelRegex")
|
|
if rx:
|
|
mid = re.sub(rx, "", mid)
|
|
return mid
|
|
|
|
|
|
def agy_base(model_id: str | None) -> str:
|
|
"""agy's own per-level slug (``gemini-4-neon-high``, what its transcript
|
|
records) → the base id the catalogue lists (``gemini-4-neon``)."""
|
|
return _strip_level(model_id)
|
|
|
|
|
|
def agy_model(model_id: str | None) -> dict | None:
|
|
if not model_id:
|
|
return None
|
|
base = agy_base(model_id)
|
|
return next((m for m in _entries_of("agy") if m.get("id") == base), None)
|
|
|
|
|
|
def pi_provider(model_id: str) -> str | None:
|
|
"""The vendor of a pickable pi model id, or None if unlisted (an
|
|
OpenRouter-browser pick). The id's shape is not a reliable test — the
|
|
EVOX2 serves ``ggml-org/qwen3.8-27b``, OpenRouter a ``qwen/qwen3.8-27b``."""
|
|
return next((m.get("provider") for m in _entries_of("pi") if m.get("id") == model_id), None)
|
|
|
|
|
|
def local_twin_base(model_id: str | None) -> str | None:
|
|
"""The model an opencode EVOX2 twin runs (``evox2-inkling/inkling-2-mini`` →
|
|
``inkling-2-mini``), else None — the harnesses' ``stripPrefixRegex``."""
|
|
mid = model_id or ""
|
|
reg = _reg()
|
|
for h in reg.harnesses.values():
|
|
for sup in h.spec.get("supports") or []:
|
|
rx = sup.get("stripPrefixRegex")
|
|
prov = reg.providers.get(sup.get("vendor") or "")
|
|
if not rx or not prov or not prov.spec.get("local"):
|
|
continue
|
|
hit = re.match(rx, mid)
|
|
if hit and mid[hit.end():]:
|
|
return mid[hit.end():]
|
|
return None
|
|
|
|
|
|
def is_local(model_id: str | None) -> bool:
|
|
"""Whether a model runs on a local provider (the EVOX2: free) — a pi chip
|
|
or its opencode twin, listed or not."""
|
|
return _reg().is_local(model_id)
|
|
|
|
|
|
def context_window(model_id: str) -> int:
|
|
"""Context-window size for any model id: its catalogue entry's, else its
|
|
family's (the provider's ``families``), else 200k."""
|
|
return _reg().context_window(model_id)
|
|
|
|
|
|
def vendor_of_model(model_id: str | None) -> str | None:
|
|
return _reg().vendor_of_model(model_id)
|
|
|
|
|
|
# Old module constants, now read off the registry (PEP 562).
|
|
def __getattr__(name: str):
|
|
if name == "DEFAULT_MODEL":
|
|
return _default_model()
|
|
if name == "FAMILIES":
|
|
return families()
|
|
if name == "OPENCODE_DEFAULT_MODEL":
|
|
return os.environ.get("OPENCODE_DEFAULT_MODEL") or _harness_default("opencode") or ""
|
|
if name == "AGY_DEFAULT_MODEL":
|
|
return os.environ.get("AGY_DEFAULT_MODEL") or _harness_default("agy") or ""
|
|
if name == "AGY_DEFAULT_EFFORT":
|
|
h = _reg().harnesses.get("agy")
|
|
return os.environ.get("AGY_DEFAULT_EFFORT") or (h.spec.get("defaultEffort") if h else None) or ""
|
|
if name == "HARNESSES":
|
|
return harness_ids()
|
|
raise AttributeError(name)
|
|
|
|
|
|
__all__ = ["list_models", "harness_ids", "families", "opencode_model", "agy_base", "agy_model",
|
|
"pi_provider", "local_twin_base", "is_local", "context_window", "vendor_of_model"]
|