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>
151 lines
6.6 KiB
Python
Executable File
151 lines
6.6 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Dump the model catalogue as stable JSON: what ``GET /api/models`` returns.
|
|
|
|
Calls the real route handler (``models/routes.py list_models``) for the owner
|
|
and for guests, over a small matrix — OpenRouter key fine / refused, agy hosted
|
|
or not, the default presets or a tuned preset file, a guest with no extra
|
|
model / a few / every key — with every network call stubbed: no Anthropic key
|
|
(``FALLBACK`` list), no sidecar (the OpenRouter-key probe answers from the
|
|
scenario), ``urlopen`` raising. Also the raw ``models.list_models()``.
|
|
|
|
scripts/ab/catalog-dump.py # print the working tree's dump
|
|
scripts/ab/catalog-dump.py --base HEAD # diff base ref vs working tree
|
|
|
|
The backend's web deps are not on the host, so each tree runs under
|
|
``uv run --with-requirements <tree>/backend/requirements.txt``.
|
|
|
|
Exit codes: 0 = identical (or plain dump), 1 = a difference, 2 = setup error.
|
|
"""
|
|
|
|
import argparse
|
|
import atexit
|
|
import json
|
|
import os
|
|
import pathlib
|
|
import shutil
|
|
import sys
|
|
import tempfile
|
|
import types
|
|
|
|
HERE = pathlib.Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(HERE))
|
|
import _common as ab # noqa: E402
|
|
|
|
# A tuned preset file: guests get a local model, a GPT on its fast tier and a
|
|
# Gemini; one local model is switched to its opencode twin; a favourite.
|
|
TUNED_PRESETS = {"models": {
|
|
"inkling-2-mini": {"guests": True, "favorite": True},
|
|
"ggml-org/qwen3.8-27b": {"harness": "opencode", "guests": True, "effort": "high"},
|
|
"gpt-6-sol": {"guests": True, "fast": "fast", "effort": "low"},
|
|
"gpt-6.1-sol": {"fast": "ultrafast", "favorite": True},
|
|
"gemini-4-neon": {"guests": True, "effort": "xhigh"},
|
|
"opus": {"guests": False, "thinking": False},
|
|
"no-such-model": {"guests": True},
|
|
}}
|
|
|
|
|
|
def runner(tree: pathlib.Path) -> list[str]:
|
|
return ["uv", "run", "--quiet", "--no-project", "--with-requirements",
|
|
str(tree / "backend" / "requirements.txt"), "python"]
|
|
|
|
|
|
def dump(tree: pathlib.Path) -> None:
|
|
scratch = pathlib.Path(tempfile.mkdtemp(prefix="ab-catalog-"))
|
|
atexit.register(shutil.rmtree, scratch, ignore_errors=True)
|
|
# Nothing may read the lab's state or the network: point every path the
|
|
# imports might open at an empty scratch dir (same for both trees).
|
|
os.environ.update({"DB_PATH": str(scratch / "ai-agent.db"),
|
|
"MODEL_PRESETS_PATH": str(scratch / "none.json"),
|
|
"DATA_DIR": str(scratch)})
|
|
os.environ.pop("ANTHROPIC_API_KEY", None)
|
|
# Since the typed-plugins cutover the catalogue is the provider / harness
|
|
# plugins': read the tree's own reference fixtures (an older tree ignores
|
|
# it), never the live discovery.
|
|
fixtures = tree / "backend" / "fixtures" / "typed_plugins"
|
|
if fixtures.is_dir():
|
|
os.environ["PLUGINS_SEED_DIR"] = str(fixtures)
|
|
os.environ["PROVIDERS_DISCOVERY"] = "0"
|
|
import urllib.error
|
|
import urllib.request
|
|
|
|
def no_network(*a, **k):
|
|
raise urllib.error.URLError("catalog-dump: the network is off")
|
|
urllib.request.urlopen = no_network
|
|
|
|
sys.path.insert(0, str(tree / "backend"))
|
|
scenario = {"openrouter": None}
|
|
|
|
import runs.sidecar_client as sidecar_client # noqa: E402
|
|
|
|
def fake_sidecar_get(path, *a, **k):
|
|
if path == "/pi/openrouter":
|
|
return scenario["openrouter"]
|
|
return None
|
|
sidecar_client._sidecar_get = fake_sidecar_get # before models.routes binds it
|
|
|
|
import accounts as accounts_mod # noqa: E402
|
|
import models as models_mod # noqa: E402
|
|
from models import presets as presets_mod # noqa: E402
|
|
from models import routes # noqa: E402
|
|
from users.caller import Caller # noqa: E402
|
|
assert routes._sidecar_get is fake_sidecar_get
|
|
|
|
tuned = scratch / "tuned.json"
|
|
tuned.write_text(json.dumps(TUNED_PRESETS))
|
|
raw = models_mod.list_models()
|
|
every_key = tuple(sorted({presets_mod.key_of(m) for m in raw}))
|
|
agy_accounts = set(accounts_mod.for_harness("agy"))
|
|
|
|
def payload(owner: bool, allowed: tuple, agy_hosted: bool):
|
|
routes._or_down = None # the probe's TTL cache: every scenario asks afresh
|
|
health = types.SimpleNamespace(
|
|
host_accounts=lambda: set(agy_accounts) if agy_hosted else set())
|
|
deps = types.SimpleNamespace(account_health=health, worker_store=None)
|
|
caller = Caller(id="owner" if owner else "guest-1",
|
|
role="owner" if owner else "guest",
|
|
name="Owner" if owner else "Guest", models=allowed)
|
|
out = routes.list_models(deps, caller)
|
|
body = getattr(out, "body", None)
|
|
return json.loads(body) if body is not None else out
|
|
|
|
out: dict = {"listModels": raw, "everyKey": list(every_key), "scenarios": {}}
|
|
callers = [("owner", True, ()), ("guest-no-extra", False, ()),
|
|
("guest-some", False, ("inkling-2-mini", "gpt-6-sol", "gemini-4-neon",
|
|
"ggml-org/qwen3.8-27b", "gpt-5.5")),
|
|
("guest-every-key", False, every_key)]
|
|
for preset_name, preset_path in (("default-presets", scratch / "none.json"),
|
|
("tuned-presets", tuned)):
|
|
presets_mod.set_store(presets_mod.PresetStore(str(preset_path)))
|
|
for or_name, or_state in (("openrouter-ok", {"ok": True}),
|
|
("openrouter-refused", {"ok": False, "reason": "key refused"}),
|
|
("sidecar-silent", None)):
|
|
scenario["openrouter"] = or_state
|
|
for agy_hosted in (True, False):
|
|
for who, owner, allowed in callers:
|
|
name = (f"{preset_name}/{or_name}/"
|
|
f"{'agy-hosted' if agy_hosted else 'agy-unhosted'}/{who}")
|
|
out["scenarios"][name] = payload(owner, allowed, agy_hosted)
|
|
print(json.dumps(out, indent=1, sort_keys=True, ensure_ascii=False))
|
|
|
|
|
|
def main() -> int:
|
|
ap = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
|
ap.add_argument("--base", metavar="REF", help="diff this git ref against the working tree")
|
|
ap.add_argument("--keep", action="store_true", help="keep the scratch dir")
|
|
ap.add_argument("--tree", type=pathlib.Path, help=argparse.SUPPRESS)
|
|
args = ap.parse_args()
|
|
if args.tree: # internal: one tree's dump (already under uv)
|
|
dump(args.tree)
|
|
return 0
|
|
me = pathlib.Path(__file__).resolve()
|
|
if args.base:
|
|
return ab.dump_ab(me, args.base, [], runner=runner, keep=args.keep)
|
|
with ab.workdir() as work:
|
|
ab.run_pool([([*runner(ab.REPO), str(me), "--tree", str(ab.REPO)],
|
|
ab.frozen_env(work), None)], 1)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|