singularity-forge/packages/pi-ai/src
Jeremy McSpadden f8814f5a15 refactor(pi-ai): replace model-ID pattern matching with capability metadata (#2548)
* refactor(pi-ai): replace model-ID pattern matching with capability metadata

Add ModelCapabilities to Model<TApi> and a CAPABILITY_PATCHES mechanism
so call sites read model.capabilities fields instead of parsing model IDs
or hardcoding provider names.

- types.ts: add ModelCapabilities interface (supportsXhigh, requiresToolCallId,
  supportsServiceTier, charsPerToken) and capabilities?: ModelCapabilities to
  Model<TApi>
- models.ts: add CAPABILITY_PATCHES table applied at registry init; patches
  declare GPT-5.x and Opus 4.6 capabilities once instead of repeating ID
  checks at every call site; supportsXhigh() now reads capabilities only
- service-tier.ts: extract SERVICE_TIER_MODEL_PREFIXES constant so the gating
  list has a single named home; add path comment pointing to issue #2546 for
  the full capability-driven follow-up

No behaviour change. New models and providers can declare capabilities in
their model definitions without touching function logic.

Closes #2546

* fix(pi-ai): apply capability patches to custom/discovered/extension models

Models constructed outside the static pi-ai registry (custom models
from models.json, extension-registered models, discovered models)
bypassed CAPABILITY_PATCHES — causing supportsXhigh() to silently
return false for GPT-5.x or Opus 4.6 variants registered through
those paths.

Export applyCapabilityPatches() from pi-ai and call it in ModelRegistry
after model assembly in all three construction paths: loadModels(),
applyProviderConfig(), and discoverModels().

Add regression tests covering patching, precedence, idempotency,
and synthetic models that mimic the custom/extension path.

Closes #2546
2026-03-26 16:38:29 -06:00
..
providers Merge pull request #2168 from frizynn/fix/ai-providers-memory-leaks 2026-03-25 22:15:32 -06:00
utils fix(pi-ai): correct Copilot context window and output token limits (#2118) 2026-03-22 17:04:16 -06:00
api-registry.ts refactor: remove dead code (unused exports) (#1486) 2026-03-19 15:33:32 -06:00
bedrock-provider.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
cli.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
env-api-keys.ts feat: add anthropic-vertex provider for Claude on Vertex AI (#1533) 2026-03-19 23:14:13 -06:00
index.ts Remove deprecated legacy dead code from OAuth module 2026-03-14 05:11:55 +00:00
models.custom.ts fix(pi-ai): restore alibaba-coding-plan provider via models.custom.ts (#2350) 2026-03-24 07:19:27 -06:00
models.generated.ts fix(pi-ai): correct Copilot context window and output token limits (#2118) 2026-03-22 17:04:16 -06:00
models.test.ts refactor(pi-ai): replace model-ID pattern matching with capability metadata (#2548) 2026-03-26 16:38:29 -06:00
models.ts refactor(pi-ai): replace model-ID pattern matching with capability metadata (#2548) 2026-03-26 16:38:29 -06:00
oauth.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
stream.ts feat: vendor Pi source into workspace monorepo 2026-03-12 21:55:17 -06:00
types.ts refactor(pi-ai): replace model-ID pattern matching with capability metadata (#2548) 2026-03-26 16:38:29 -06:00
web-runtime-env-api-keys.ts feat(web): browser-based web interface (#1717) 2026-03-21 12:16:54 -06:00
web-runtime-oauth.ts feat(web): browser-based web interface (#1717) 2026-03-21 12:16:54 -06:00