docs-agent-router.ts is an optional Worker Route in front of the existing webview-native-ui.com
Static Assets Worker. It experiments with Jev request classification and x402 without making either
service part of the site's availability path.
The checked-in configuration uses enforce mode. Requests that explicitly accept text/markdown
receive an x402 payment challenge and the generated Markdown after payment. Requests that accept
text/html use the public static site. Ambiguous requests go directly to the
TypeSafe API using TYPESAFE_API_KEY and the jev-latest model
(POST https://api.typesafe.ai/v1/systemone). Workers AI and AI Gateway are not used.
Missing keys and classifier errors fall back to the public site.
observe logs Jev decisions while returning static HTML; off skips Jev entirely. Requests for
assets and pages without generated Markdown use the static site.
The Markdown module under workers/generated/ is a disposable build artifact and is ignored by
Git. docs:generate:content, build:docs-agent-router, and deploy:docs-agent-router recreate it
from the documentation sources before Wrangler bundles the Worker.
Production setup:
- Choose a wallet you control that can receive USDC on Base. The checked-in
X402_NETWORKis Base mainnet (eip155:8453). Copy only its public0xaddress; never put a recovery phrase or private key in this repository or Wrangler. - Set that public receiving address as a Worker secret with
npx wrangler secret put X402_PAY_TO --config wrangler.docs-agent-router.jsonc. - Create a Coinbase Developer Platform API key, then set
CDP_API_KEY_IDandCDP_API_KEY_SECRETas Worker secrets. The CDP facilitator needs these for Base mainnet; the Coinbase Wallet app account alone does not provide them. Do not create a CDP wallet secret: the external wallet inX402_PAY_TOreceives funds. Set each value withnpx wrangler secret put NAME --config wrangler.docs-agent-router.jsonc, replacingNAMEwith the corresponding variable name. - Create a TypeSafe API key, then set it as a Worker secret:
npx wrangler secret put TYPESAFE_API_KEY --config wrangler.docs-agent-router.jsonc. Paste the key at the prompt; do not put it in Wranglervarsor source control. - Deploy with
npm run deploy:docs-agent-router. - In the Cloudflare dashboard, set both
docs-agent-routerroutes to Fail open. Workers Static Assetsrun_worker_firstdoes not fall back after the Free plan request limit, so this separate fail-open Worker Route is intentional. - Check that Markdown requests receive HTTP 402 with Base USDC payment requirements and browser requests continue to receive HTML. No wallet payment was sent during this check.
Application errors, TypeSafe API errors, and x402 responses with status 5xx return the static
site. Invalid or missing payment remains an x402 402 response. Removing the Worker Routes restores
the original static site without changing the docs Worker.
For local development, copy .dev.vars.example to .dev.vars next to the Wrangler config and set
TYPESAFE_API_KEY there. If .dev.vars already exists, add the variable without overwriting the
other secrets. .dev.vars* is ignored by Git except for the empty example. Generate the Markdown
with npm run docs:generate:content, then run
npx wrangler dev --config wrangler.docs-agent-router.jsonc. The key is read per request, so each
environment uses its own secret. Existing sensitive-header redaction and URL query removal still
apply before sending request descriptions to TypeSafe.
The service name is webview-native-ui-docs-agent-router. Configure new secrets explicitly; the old-host router stays in rdlabo-dev/website and redirects moved project requests before classification/payment.