Skip to content

feat(models): ModelClient registry, mock, and OpenAI client (issue #17)#51

Merged
leo-aa88 merged 1 commit into
mainfrom
issue/17-models-registry
Apr 11, 2026
Merged

feat(models): ModelClient registry, mock, and OpenAI client (issue #17)#51
leo-aa88 merged 1 commit into
mainfrom
issue/17-models-registry

Conversation

@leo-aa88
Copy link
Copy Markdown
Member

Summary

Adds the ModelClient boundary from design doc §12.2 F with a registry backed by Project.spec.providers.models (§7.1), a mock for deterministic tests, and a minimal OpenAI-compatible HTTP client.

API

Types (types.go)

  • ModelClientGenerate(ctx, GenerateRequest) (GenerateResponse, error)
  • GenerateRequestModel, Messages []ChatMessage
  • GenerateResponseContent (assistant text, often JSON for structured agents), Meta (DurationMs, CostUSD placeholders per issue scope)

Registry (registry.go)

  • NewRegistry(*spec.ProjectGraph) reads graph.Spec.Providers.Models
  • ClientFor("namespace/model_id") returns a client and the model id segment (e.g. openai/gpt-4.1 → id gpt-4.1)
  • Supported ModelProviderConfig.Type values: openai*OpenAIClient, mock → fixed JSON mock

OpenAI (openai.go)

  • NewOpenAIClientFromConfig(cfg) resolves apiKeyFrom via ResolveAPIKeyFrom
  • Default base URL https://api.openai.com/v1; POST .../chat/completions with Bearer auth
  • BaseURL / HTTPClient overridable (used in tests with httptest)

Key resolution (key.go)

  • ResolveAPIKeyFrom("env:VAR") — returns error if variable unset (MVP)

Mock (mock.go)

  • MockClient — returns configured Content and optional Meta without network I/O

Tests

  • Mock / agent step: JSON output unmarshals into a structured schema; meta honored
  • Registry: unknown provider namespace (anthropic/... with only openai configured); invalid modelRef format
  • Registry + OpenAI: resolves *OpenAIClient with env:OPENAI_API_KEY
  • OpenAI client: httptest server asserts /v1/chat/completions and Authorization
  • ResolveAPIKeyFrom: success and missing env

Verification

  • make fmt (go fmt ./...)
  • make test (go test ./... -race)
  • make vet

Closes #17

Made with Cursor

Add GenerateRequest/Response, ModelClient, Registry from Project providers,
ResolveAPIKeyFrom (env:VAR), MockClient for deterministic tests, and
OpenAIClient posting to /v1/chat/completions.

Tests cover mock JSON agent output, unknown provider namespace, httptest
OpenAI path, and API key resolution (issue #17).

Made-with: Cursor
@leo-aa88 leo-aa88 merged commit 3f8788d into main Apr 11, 2026
4 checks passed
@leo-aa88 leo-aa88 deleted the issue/17-models-registry branch April 11, 2026 21:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MVP] ModelClient registry, mock, minimal OpenAI-compatible path (internal/models)

1 participant