Add "Try Franklin" — in-browser wallet playground (/try) - #3
Merged
Conversation
New nav item "Try Franklin" → /try, a web preview of Franklin styled to match the site (warm-minimal + gold). Users connect a browser-extension wallet and chat with frontier models, paying per message in USDC via x402. Reuses BlockRun's existing x402 API rather than standing up new backend: - /api/blockrun/[...path] transparent proxy forwards to blockrun.ai, relaying the X-Payment request header and payment-required response header so the browser stays same-origin (no CORS, 402 visible). - Wallet/x402 stack ported from the BlockRun video playground: wagmi-config, useUsdcBalance, useX402Payment (EIP-3009 signing). - useFranklinChat: probe → 402 → wallet-sign → retry with X-Payment. Free models (nvidia/*) run with no wallet; paid models charge a few cents of USDC, settled on Base to BlockRun's wallet. UI: WalletProvider (wagmi + react-query, scoped to /try only), ConnectWallet chip with live USDC balance, FranklinChat surface with model picker, suggestions, and status/error states. Nav label localized across all 13 locales. Adds wagmi, viem, @tanstack/react-query. typecheck + production build pass; /try and the proxy verified locally (402 + payment-required relayed correctly).
Expands the /try web preview into a fuller Franklin web client. Builds on the initial chat-only version. Generation & chat - Streaming chat (fixes Cloudflare 524 on slow models); Franklin identity system prompt; reasoning (<think> + reasoning_content) shown collapsibly - Image and Video generation modes (x402-paid, inline player + lightbox) - Markdown rendering for replies: code blocks with copy + expand - Composer: in-box tool row (model select, Image/Video pills, image attach for vision), stop button Agent tool-calling (function calling, invoked automatically, not shown as UI) - web_search, make_phone_call, generate_music, get_market_price, search_prediction_markets — tool-capable models route through a tool loop; free models stream without tools Phone panel (sidebar) — dashboard-style number management: list / buy / renew / release provisioned numbers Identity & persistence (login required) - SIWE wallet sign-in: nonce → sign → verify (viem) → HMAC session cookie - Per-wallet conversation history on GCS (replicates BlockRun's storage pattern; local-dev fs fallback). Conversation id/wallet whitelisted to prevent path traversal. - Transparent /api/blockrun proxy (relays X-Payment + payment-required) Model list mirrors Franklin's curated picker (grouped). Usage stats card. Settings → interface language (en / zh / es). Warm-minimal styling. Adds wagmi, viem, @tanstack/react-query, @google-cloud/storage. Requires SESSION_SECRET in prod and GCS write access for the Cloud Run service account.
The free default model (nvidia/deepseek-v4-flash) ignores function-calling, so the prediction-market example chips answered from memory instead of calling the tool. Clicking a prediction case now forces a cheap tool-capable model (Gemini 2.5 Flash) via a send() model override so the tool actually fires.
…, phone-call confirm - session.ts: throw in production if SESSION_SECRET is unset, so the public dev fallback can never sign forgeable sessions for arbitrary wallets. - blockrun proxy: allowlist v1/<known> endpoints (decode-then-reject traversal) and add a 60 req/min per-IP rate limit to stop anonymous free-model relay abuse. - make_phone_call: require an explicit user confirm (number, task, ~$0.54 cost) before signing, so prompt injection via tool results can't silently spend.
… prod guard The module-load guard threw during `next build` (Next evaluates route modules with NODE_ENV=production but runtime env is absent), failing the build. Move the check into getSecret() so it fires on the first sign/verify at request time — verified: prod without SESSION_SECRET returns 500, with it set returns 200.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
A web preview of Franklin at /try — connect a browser wallet and chat with frontier models, generate images/videos, and let Franklin use tools, paying per request in USDC via x402. Reuses BlockRun's existing API (no new backend service); per-wallet history is stored on GCS.
Features
web_search,make_phone_call,generate_music,get_market_price,search_prediction_markets. Tool-capable models route through a tool loop; free models stream without tools.gcs-logger/image-jobspattern; local-dev fs fallback)Architecture
Deploy requirements (not automatic)
npm run deploy— push does not deploy)SESSION_SECRETenv (e.g.openssl rand -hex 32)blockrun-prod-2026-logs), same mechanism BlockRun uses for media/logsNotes / verification
npm run typecheck✅, lint clean on new fileswagmi,viem,@tanstack/react-query,@google-cloud/storageFollow-ups