Skip to content

feat(gateways): AI-generated plugin for cohere - #5

Open
startupmini wants to merge 15 commits into
mainfrom
ai/gateway/cohere
Open

feat(gateways): AI-generated plugin for cohere#5
startupmini wants to merge 15 commits into
mainfrom
ai/gateway/cohere

Conversation

@startupmini

Copy link
Copy Markdown
Owner

AI-generated gateway plugin for \cohere\ (mode: bootstrap).

Reviewed before merge, per docs/08_Gateway_Plugin_Security.md:

  • Confirm the plugin only uses secrets registered in \packages/collectors/src/core/gateway-secrets.ts.
  • Add the gateway API key as a repository secret so nightly collection can use it.
  • Run \pnpm --filter @basemodel/collectors run verify \ to smoke-test with a live key.

startupmini and others added 15 commits August 1, 2026 18:24
Adds a gateway generator that lets a free-tier LLM (Gemini flash-lite by
default, OpenRouter :free fallback) produce custom gateway plugins for
providers whose APIs do not match the OpenAI-compatible shape.

How it works:
- Register a gateway in packages/collectors/manifest.json (url, auth,
  secrets, optional static sample).
- pnpm gen-gateway <id> probes the endpoint (or uses the sample), captures
  a redacted fixture, summarizes the response shape, and asks the LLM for a
  complete CustomGateway plugin. Output is structurally validated (importable,
  correct id, has collect(), no forbidden patterns) and retried up to 3 times.
- heal mode (--heal) regenerates a plugin from the existing fixture when a
  sample changes or a mapping breaks.
- .github/workflows/gateway-ai.yml runs the generator on demand and opens a
  review PR; it also validates the manifest on PRs that touch it.

Includes the first generated example: cohere.ts (written by the LLM from a
static sample), its fixture, a generic harness test that validates generated
plugins against their fixtures, and the COHERE_API_KEY secret registration.
…y loop

The generator now treats typecheck failures and live collection errors as
validation failures, so the LLM is asked to fix them (up to 3 attempts)
instead of shipping a plugin that compiles structurally but breaks
typecheck or maps live API data to invalid Model records.

- validateGeneratedPlugin: forbidden patterns + structural + tsc --noEmit + optional live check
- runTypecheck: spawns node with the local tsc.js (no shell, cross-platform)
- bootstrap/heal pass liveSecrets into the loop; duplicate post-hoc live check removed
- cohere.ts: fix pagination field (next_page -> next_page_token) from review of AI output
probeGateway now probes the live endpoint first when the gateway's key is
available, falling back to the manifest sample when it is not (or when the
live probe fails). This feeds the LLM the real response shape (field names,
nulls, pagination) instead of a stale static sample, so generated plugins
match the live API and the loop's live check converges.

Also instruct the LLM to never use 'any' (use unknown + narrowing) so
attempts are not wasted on forbidden patterns.
checkCollection now captures the first ModelSchema issue per invalid record
(up to 5 unique examples) so the retry prompt tells the LLM exactly which
field fails and why (e.g. 'context_window: expected number, received null')
instead of a bare count, letting it converge within the attempt budget.
…fallback

OpenRouter (deepseek-chat-v3-0324:free by default) is now the primary LLM
provider when OPENROUTER_API_KEY is set, falling back to Gemini on failure.
LLM_PROVIDER=openrouter|gemini forces a single provider. This gives the
retry loop a stronger code-generation model than flash-lite so plugins
converge within the attempt budget.
- llm.ts: add Requesty provider (router.requesty.ai) with free model
  mistral/leanstral-1-5 by default; provider order requesty -> gemini ->
  openrouter; LLM_PROVIDER env override; OpenRouter free candidates rotate
  (deepseek :free no longer available).
- gateway-ai.yml: pass REQUESTY_API_KEY to the generator env.
- prompts.ts: forbid unused variables (noUnusedLocals) explicitly.
- manifest sample: add next_page_token and null context_length/tokenizer_url
  entries so the LLM learns pagination and nullable fields.
- generate/heal: raise default maxAttempts to 4.
- cohere.ts: regenerated plugin handles pagination (next_page_token,
  maxPages) and nullable fields; passes forbidden/typecheck/unit validation.
…s, truncate heal feedback, handle non-positive context_length
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