Skip to content

Add "Try Franklin" — in-browser wallet playground (/try) - #3

Merged
1bcMax merged 5 commits into
masterfrom
try-franklin
May 26, 2026
Merged

Add "Try Franklin" — in-browser wallet playground (/try)#3
1bcMax merged 5 commits into
masterfrom
try-franklin

Conversation

@KillerQueen-Z

Copy link
Copy Markdown
Collaborator

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

  • Chat — streaming (avoids Cloudflare 524 on slow models), Franklin identity prompt, collapsible reasoning, markdown + code blocks (copy / expand)
  • Image & Video generation modes (inline player + lightbox)
  • Agent tools (function calling, auto-invoked, no 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 — dashboard-style number management (list / buy / renew / release)
  • Sign-in with Ethereum — nonce → sign → verify (viem) → HMAC session cookie; login required
  • Per-wallet history on GCS (replicates BlockRun's gcs-logger/image-jobs pattern; local-dev fs fallback)
  • Model list mirrors Franklin's curated picker; usage/spend stats card; interface language (en/zh/es)

Architecture

browser (wallet signs x402)  →  /api/blockrun/* (transparent proxy)  →  blockrun.ai
SIWE login → HMAC session cookie → /api/try/conversations (GCS, per verified wallet)

Deploy requirements (not automatic)

  • Deploy to Cloud Run (npm run deploy — push does not deploy)
  • Set SESSION_SECRET env (e.g. openssl rand -hex 32)
  • The franklin-run Cloud Run service account needs write access to the GCS bucket (blockrun-prod-2026-logs), same mechanism BlockRun uses for media/logs
  • Phone calls require Bland.ai configured on the BlockRun backend

Notes / verification

  • npm run typecheck ✅, lint clean on new files
  • SIWE login + session + history CRUD verified end-to-end locally (signed with viem, local fs store); wallet-paid flows (generation, tools, phone) follow BlockRun's proven x402 pattern but need a live wallet + tool-capable model to exercise
  • Security review: per-wallet access derived from the verified session only (no cross-wallet reads); proxy is host-locked to blockrun.ai and does not forward the session cookie upstream; conversation id/wallet whitelisted (no path traversal); model output rendered as escaped React text (no XSS)
  • Adds wagmi, viem, @tanstack/react-query, @google-cloud/storage

Follow-ups

  • Media permanence (re-host generated media to our own bucket)
  • More tools (swaps, defillama), streaming through the tool loop, mobile polish

KillerQueen-Z and others added 5 commits May 23, 2026 02:07
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.
@1bcMax
1bcMax merged commit 5a7fce1 into master May 26, 2026
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