Skip to content

Add Vercel and Cloudflare as Jev providers with an ordered fallback chain - #3

Merged
fatwang2 merged 2 commits into
mainfrom
feat/jev-provider-chain
Sep 19, 2026
Merged

fatwang2 merged 2 commits into
mainfrom
feat/jev-provider-chain

Conversation

@fatwang2

Copy link
Copy Markdown
Member

Why

TypeSafe ran out of credit on 2026-09-19 and every search failed with HTTP 402, even though Search1API was healthy. Jev is also served by Vercel AI Gateway (typesafe-ai/jev) and Cloudflare Workers AI (typesafe/jev). This PR lets a deployment use any of the three and fall back between them.

What changes

  • Provider chain. src/lib/typesafe.ts speaks all three dialects behind the existing TypeSafe-shaped interface. The chain tries providers in order and moves on only for HTTP 402 (no credit), 429 (throttled) or 5xx. Client errors such as 400/401 are not retried, and nothing is retried after the request is cancelled. Each hop is logged.
  • One switch. The JEV_PROVIDERS secret lists the enabled providers in order of preference. Unset means typesafe only, so the committed defaults are unchanged; unlisted providers stay off even when their credentials exist. src/lib/judge-config.ts builds the chain from the environment.
  • Vercel. POST https://ai-gateway.vercel.sh/v4/ai/evaluation-model (the AI SDK evaluation-model protocol, read from @ai-sdk/gateway source). noul questions become boolean; TypeSafe's confidence is read from provider metadata.
  • Cloudflare. Workers AI binding AI added to wrangler.jsonc; idle unless listed. Binding errors such as "Insufficient AI Gateway credits" map to 402 so the chain continues.
  • Observability. The intent event carries judge, the provider that answered.
  • Docs. README gets a full variable table, switch semantics and billing notes per provider. .dev.vars.example lists every secret.

Behaviour after merge

No change for the hosted demo until secrets are uploaded: with no JEV_PROVIDERS secret the Worker uses TypeSafe alone, as today. Enabling fallbacks is two wrangler secret put commands and needs no redeploy.

Verification

  • 108 tests pass (26 for the client, 6 for config), pnpm build, pnpm cf-typegen diff clean, wrangler deploy --dry-run pass.
  • Real calls: Vercel gateway returned 200 with the expected answer shape; a local search with JEV_PROVIDERS=vercel,typesafe,cloudflare reported judge: vercel.
  • Fallback exercised for real: with TypeSafe at 402 the chain completed on Vercel; with Cloudflare first, the binding's "Insufficient AI Gateway credits" mapped to 402 and the chain completed on TypeSafe.

🤖 Generated with Claude Code

…hain

TypeSafe ran out of credit and every search failed with HTTP 402. Jev is
also served by Vercel AI Gateway (typesafe-ai/jev) and Cloudflare Workers
AI (typesafe/jev), so the client now speaks all three dialects behind the
same TypeSafe-shaped interface and tries them in order.

- JEV_PROVIDERS secret lists the enabled providers in order of preference;
  unset means typesafe only. Unlisted providers stay off even when their
  credentials exist, so the committed defaults stay TypeSafe-only while a
  deployment can run e.g. "vercel,typesafe,cloudflare".
- A request moves to the next provider only on 402, 429 or 5xx, never on
  client errors or after cancellation. Each hop is logged.
- Vercel: POST /v4/ai/evaluation-model; noul questions become boolean,
  TypeSafe's confidence is read from provider metadata.
- Cloudflare: Workers AI binding; "Insufficient AI Gateway credits" and
  similar binding errors map to 402 so the chain continues.
- The intent event carries `judge`, the provider that answered.
- README documents every variable, the switch semantics and provider
  billing notes; .dev.vars.example lists all secrets.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 19, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
jev-search c0c8be1 Commit Preview URL

Branch Preview URL
Sep 19 2026, 09:34 AM

`wrangler versions upload` refuses to deploy when a secret listed in
`secrets.required` is missing, which broke Workers Builds on the PR because
JEV_PROVIDERS and AI_GATEWAY_API_KEY are optional. Without the list,
local dev injects every key from .dev.vars, so fallbacks remain testable.

Type generation now reads `.dev.vars.example` via `--env-file`, so the
committed worker-configuration.d.ts no longer depends on a developer's
private .dev.vars and matches in CI.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@fatwang2
fatwang2 merged commit 8b34965 into main Sep 19, 2026
2 checks passed
@fatwang2
fatwang2 deleted the feat/jev-provider-chain branch September 19, 2026 09:59
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