Files
buzz/scripts
npub1g8493u0xfsjrvflg4n08ezd7vec99mnwzlv0qgwpr9d7gvjwhuzqx59rhwandWill Pfleger 4855d95252 feat(models): Phase 3 — pricing axis to D2' (authority, model) exact-lookup contract
Replaces lookup_pricing(raw_model_id) + normalize_for_pricing + 17 prefix rules
with an exact (billing-authority domain, billable-model-string) lookup. Billing
authority is a distinct namespace from the runtime transport Provider enum.
Match is exact: no case normalization, no prefix matching, no inference.

Manifest (scripts/model-capabilities.json):
- Removed pricing_rules (17 prefix-match rules), pricing_exact_records (3 records)
- Added flat pricing_records list of 20 exact records, each with authority + model +
  usd_per_mtok (input/output/cache_read/cache_write) + _source provenance
- Authorities: api.anthropic.com, api.openai.com — registered bare-host tokens per
  D2'/NIP-AM; not transport Provider enum values
- Semantics: current list prices (ccusage-aligned); cache_write scoped to ephemeral;
  other classes unknown

Generator (scripts/generate-model-capabilities.mjs):
- Removed all old pricing machinery (pricingNormalize, normalizeVersionSeparators,
  pricingRules, pricingExactRecords, resolvePricing, all TS rule-resolver emission)
- Strict pricing-record validation: registered authority (closed set: api.anthropic.com,
  api.openai.com, openrouter.ai); nonempty verbatim model; no control/NUL/quote/backslash
  in key fields; finite nonnegative input/output; both cache_read and cache_write required
  (absent member is hard error; use null for unpublished); _source provenance required;
  duplicate detection on exact emitted identities
- byAuthority grouping uses exact record values — no toLowerCase() anywhere in
  pricing generation path
- REGISTERED_AUTHORITIES set; hasUnsafeKeyChars() guard
- TS PRICING_TABLE: key is ${authority}\0${model} (exact strings, no transforms)
- lookupModelPricing(authority, model) performs exact Map lookup (no normalization)
- modelPricing.ts is standalone (no import from modelCapabilities)

Generated artifacts:
- generated_model_capabilities.rs: lookup_pricing(authority: &str, model: &str)
  performs exact match — no to_ascii_lowercase() calls, no fallback
- modelPricing.ts: exact PRICING_TABLE + lookupModelPricing(authority, model)

CI (.github/workflows/ci.yml):
- Replaced two-step "regenerate + git diff" check with a single
  node scripts/generate-model-capabilities.mjs --check step, which validates
  all three generated artifacts (Rust capabilities, TS capabilities, TS pricing)
  and exits 1 if any are stale. Self-maintains if a fourth artifact is added.

Tests (generated_model_capabilities_tests.rs, 23 pricing tests):
- Anthropic models with correct rates (claude-fable-5, claude-opus-5, claude-sonnet-5,
  claude-opus-4-8, claude-sonnet-4-6, claude-haiku-4-5)
- OpenAI models incl. gpt-5.6-luna different tier, gpt-5.5 null cache_write, gpt-5-pro
  null cache fields
- Null guards: unknown authority, custom base URL, unknown model, empty authority,
  empty model, both empty, wrong authority for known model
- Exact-match guards: uppercase authority -> None, mixed-case authority -> None,
  mixed-case model -> None (no case folding)
- Databricks guards: workspace URL authority -> None, 'databricks' authority -> None

Manifest validator tests (scripts/test-manifest-validator.mjs, 45 tests total):
- 21 new pricing-record mutation tests covering: missing authority, unregistered/path-
  bearing/scheme authority, empty model, unsafe chars (double-quote, backslash, NUL,
  control), missing output, negative rates, invalid cache rate, deleted cache_read,
  deleted cache_write, missing/empty provenance, duplicate records, uppercase authority

Co-authored-by: Will Pfleger <pfleger.will@gmail.com>
Signed-off-by: Will Pfleger <pfleger.will@gmail.com>
2026-08-04 10:58:29 -04:00
..
2026-07-27 14:18:24 -04:00