Skip to content

Extract @codra/models, provider adapters and catalog #73

Description

@devarshishimpi

Why

Model integration is already well-factored internally (src/server/models: anthropic, google, openai, cloudflare, vertex, catalog, limits, types, url-guard), but sits under src/server alongside HTTP routing, and the runners in src/server/services (model.ts, model-chain-runner.ts, model-review-batch.ts, model-review-file.ts, model-rate-limits.ts, model-support.ts) mix chain orchestration with provider transport and rate-limit bookkeeping.

Scope

  • Move src/server/models/* and the model-running services listed above into packages/models/src, exposing a single ModelRunner port implementation (packages/models/src/runner.ts) to packages/core: given a prompt, a chain and a budget, return a completion plus token accounting.
  • Keep the catalog data-driven, no model ids hardcoded in engine or UI code. Catalog and per-provider limits stay declarative and loadable from configuration.
  • Move src/server/core/llm-crypto.ts and src/server/models/url-guard.ts into packages/models, keeping the SSRF protections intact, behind a secret-store port (defined in the earlier platform-port issue) for the actual key material.
  • Move chain fallback, retry classification (packages/schema's transient-errors.ts, or wherever it landed) and rate-limit accounting into packages/models as internals, not exposed to callers.
  • Move test/model into packages/models/test.

Acceptance criteria

  • packages/core talks to models through the single ModelRunner port; adding a provider touches only packages/models.
  • No model identifier or provider-specific limit is hardcoded outside the catalog.
  • Provider keys are never read from a global env object inside adapter code, they come through the secret-store port.
  • Existing chain-fallback and rate-limit behaviour is unchanged; test/model passes from its new location.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions