[Frontend] Edge Intelligence — browser model + silent Nostr identity signing #65

Open
opened 2026-03-21 00:47:09 +00:00 by replit · 0 comments
Owner

What & Why

Move the cheapest cognitive work to the browser GPU so it never touches the server. A Transformers.js Web Worker runs a small classification model locally to pre-screen requests before submission. Simultaneously, nostr-tools (3kb) lets the browser sign Nostr challenge nonces to prove identity — enabling free-tier access — without any private key ever leaving the device. Combined effect: Timmy's free-tier users identify themselves and get filtered responses at zero upstream cost.

Done looks like

  • On first load, browser downloads and caches a small classification model (~80MB, stored via existing service worker). A subtle indicator shows "local intelligence active" once ready
  • When user types a message, local model scores it: trivial / moderate / complex. Trivial requests handled by edge model and shown immediately with a "local" badge — no network call made
  • Complex/moderate requests show user a cost preview ("this will cost ~X sats" or "covered by your free tier") before they hit Send
  • If user has a Nostr identity stored locally (npub/nsec in localStorage or browser extension like nos2x), browser silently signs the server challenge and attaches identity token to every outbound request — enabling free-tier access with no user friction
  • When no Nostr identity is present, a subtle "Identify with Nostr" prompt appears in the sidebar; flow is entirely optional and non-blocking

Out of scope

  • Model fine-tuning or weight hosting
  • nos2x integration for the mobile app (Expo task)
  • Privacy analysis of edge data classification

Tasks

  1. Web Worker setuppublic/edge-worker.js: import Transformers.js, load Xenova/distilbert-base-uncased-finetuned-sst-2-english (lightest useful model), expose classify(text){label, score}. Post status events back to main thread.
  2. Complexity classifier — Map model confidence to trivial/moderate/complex thresholds. Trivial: respond locally with a canned Timmy reply. Moderate/complex: show cost preview badge before submit.
  3. Silent Nostr identity signing — On page load, if localStorage has nostr_nsec, silently call GET /api/identity/challenge + sign nonce with nostr-tools signEvent + call POST /api/identity/verify → store returned token. If window.nostr (nos2x) available, use window.nostr.signEvent instead.
  4. "Identify with Nostr" prompt — If no identity signed in, show subtle CTA in sidebar. Click → open keypair generation modal (generates ephemeral keypair locally) OR prompt for existing nsec. After first verify, dismiss prompt permanently.
  5. Model readiness indicator — Small status dot in UI header: loading / ready / error. "Ready" = model warm and identity resolved.

Relevant files

  • the-matrix/index.html
  • the-matrix/js/ui.js
  • the-matrix/js/websocket.js
  • the-matrix/js/session.js
  • artifacts/api-server/src/routes/identity.ts
## What & Why Move the cheapest cognitive work to the browser GPU so it never touches the server. A Transformers.js Web Worker runs a small classification model locally to pre-screen requests before submission. Simultaneously, `nostr-tools` (3kb) lets the browser sign Nostr challenge nonces to prove identity — enabling free-tier access — without any private key ever leaving the device. Combined effect: Timmy's free-tier users identify themselves and get filtered responses at zero upstream cost. ## Done looks like - On first load, browser downloads and caches a small classification model (~80MB, stored via existing service worker). A subtle indicator shows "local intelligence active" once ready - When user types a message, local model scores it: trivial / moderate / complex. Trivial requests handled by edge model and shown immediately with a "local" badge — no network call made - Complex/moderate requests show user a cost preview ("this will cost ~X sats" or "covered by your free tier") before they hit Send - If user has a Nostr identity stored locally (npub/nsec in localStorage or browser extension like nos2x), browser silently signs the server challenge and attaches identity token to every outbound request — enabling free-tier access with no user friction - When no Nostr identity is present, a subtle "Identify with Nostr" prompt appears in the sidebar; flow is entirely optional and non-blocking ## Out of scope - Model fine-tuning or weight hosting - nos2x integration for the mobile app (Expo task) - Privacy analysis of edge data classification ## Tasks 1. **Web Worker setup** — `public/edge-worker.js`: import Transformers.js, load `Xenova/distilbert-base-uncased-finetuned-sst-2-english` (lightest useful model), expose `classify(text)` → `{label, score}`. Post status events back to main thread. 2. **Complexity classifier** — Map model confidence to trivial/moderate/complex thresholds. Trivial: respond locally with a canned Timmy reply. Moderate/complex: show cost preview badge before submit. 3. **Silent Nostr identity signing** — On page load, if localStorage has `nostr_nsec`, silently call `GET /api/identity/challenge` + sign nonce with `nostr-tools signEvent` + call `POST /api/identity/verify` → store returned token. If `window.nostr` (nos2x) available, use `window.nostr.signEvent` instead. 4. **"Identify with Nostr" prompt** — If no identity signed in, show subtle CTA in sidebar. Click → open keypair generation modal (generates ephemeral keypair locally) OR prompt for existing nsec. After first verify, dismiss prompt permanently. 5. **Model readiness indicator** — Small status dot in UI header: loading / ready / error. "Ready" = model warm and identity resolved. ## Relevant files - `the-matrix/index.html` - `the-matrix/js/ui.js` - `the-matrix/js/websocket.js` - `the-matrix/js/session.js` - `artifacts/api-server/src/routes/identity.ts`
replit added the aifrontendnostr labels 2026-03-21 00:47:09 +00:00
claude was assigned by Rockachopa 2026-03-22 23:37:09 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: replit/timmy-tower#65