Skip to content

fix(types): derive agent llm.vendor union from @jambonz/schema#10

Merged
davehorton merged 1 commit into
mainfrom
fix/derive-llm-vendors-from-schema
Jun 5, 2026
Merged

fix(types): derive agent llm.vendor union from @jambonz/schema#10
davehorton merged 1 commit into
mainfrom
fix/derive-llm-vendors-from-schema

Conversation

@davehorton

Copy link
Copy Markdown
Contributor

Problem

The AgentLlm.vendor union in src/types/verbs.ts was hand-maintained and had drifted from the source of truth (the @jambonz/schema agent verb enum). It listed only 7 vendors and was missing baseten, azure-openai, groq, and huggingface — all valid at runtime (the @jambonz/llm adapter registry supports them) and present in the schema. The result: TypeScript rejected valid agent configs, forcing consumers into casts like vendor: 'baseten' as 'openai'.

The schema and the MCP server were both correct — only the SDK's hand-written type lagged.

Fix

Derive the vendor list from the schema instead of duplicating it by hand:

  • scripts/gen-llm-vendors.mjs — reads llm.vendor.enum from @jambonz/schema's verbs/agent.schema.json and emits src/types/llm-vendors.generated.ts (a const tuple + derived LlmVendor type).
  • AgentLlm.vendor now references the generated LlmVendor type.
  • Wired gen:types into prebuild and pretypecheck, so published artifacts and CI always track the installed schema version. A new vendor in the schema flows into the types automatically on the next build.
  • Exported LlmVendor and LLM_VENDORS for consumers (validation, UI dropdowns, etc.).
  • The generated file is committed so fresh checkouts and tsc work without a codegen step.

Drift guard

Added a test in schema-drift.test.ts asserting the committed LLM_VENDORS equals the schema enum — catches a stale generated file if the schema dep is bumped without re-running gen:types. (The existing drift tests only compared property names, not enum values, which is how this slipped through.)

Verification

  • npm run typecheck ✅ (regenerates via pretypecheck)
  • npm run build ✅ — built .d.ts now exports all 11 vendors
  • npm test ✅ 117 passing (was 116; +1 drift guard)

🤖 Generated with Claude Code

The AgentLlm.vendor union was hand-maintained and had drifted from the
schema enum — it was missing baseten, azure-openai, groq, and huggingface,
so valid vendors were rejected by TypeScript.

Generate the vendor list from @jambonz/schema (agent.schema.json
llm.vendor.enum) via scripts/gen-llm-vendors.mjs into a committed
llm-vendors.generated.ts. Wired as prebuild/pretypecheck so published
artifacts always track the installed schema version. Export LlmVendor and
LLM_VENDORS for consumers. Add a drift test asserting the committed
generated list matches the schema enum.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@davehorton davehorton merged commit 45e7a28 into main Jun 5, 2026
1 check passed
@davehorton davehorton deleted the fix/derive-llm-vendors-from-schema branch June 5, 2026 17:53
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.

1 participant