Workers

Extension gateway

The gateway between the Ultron browser extension and the rest of the platform. Each connected user has their own Durable Object instance holding extension state: open tabs, queued events, current selection, last command. Acts as a thin authenticated proxy so the extension never has direct credentials for downstream surfaces.

Updated today

Overview

At a glance
Worker
extension-gateway
Durable Object
UserExtensionDO
DO key
(user_id, extension_session)
Purpose
Proxy + per-user state for the browser extension
Auth
Short-lived tokens issued by edge-auth, validated per call

Worker shape

wrangler.toml (key bindings)toml
1name = "extension-gateway"
2main = "src/index.ts"
3
4[[durable_objects.bindings]]
5class_name = "UserExtensionDO"
6name = "USER_EXT"
7
8[vars]
9APP_ORIGIN = "https://app.51ultron.com"

UserExtensionDO

One DO per connected user.

src/index.ts (DO sketch)ts
1export class UserExtensionDO {
2 // Storage keys:
3 // open_tabs : Array<TabInfo> (most-recent first, capped at 32)
4 // queued_events : Array<EventMsg> (drained on each /flush)
5 // last_selection : { text, url, ts }
6 // pinned_brain_notes : Array<NoteRef> (extension can pin notes for quick access)
7
8 async fetch(req: Request) {
9 // Routes:
10 // POST /report-tab update open_tabs
11 // POST /report-selection update last_selection
12 // POST /queue enqueue event
13 // GET /flush drain queued_events, return JSON
14 // POST /act run a chat-v2 invocation (proxy)
15 // GET /state read snapshot of DO state
16 }
17}
Note
The DO is the single source of truth for the extension's state. A page reload in the browser does not lose anything; the next ping pulls the state back from the DO.

Endpoints

Method + pathBodyReturns
POST /report-tab{ tabId, url, title, ts }ok
POST /report-selection{ text, url, ts }ok
POST /queue{ kind, payload }ok (event queued)
GET /flush-Array of queued events; clears the queue
POST /act{ prompt, scopes? }Streams the chat-v2 response back to the extension
GET /state-Snapshot of DO state for diagnostics
POST /pin-note{ noteId }Pin a brain note for quick access

Per-tab session state

The extension reports tab events into the gateway so the DO always knows what page the user is looking at. When the user invokes the extension, the gateway can build context from current tab + recent tabs without an extra round trip to the browser. This makes "summarise this page" or "save this contact to leads" actions fast and stateless on the extension side.

State keyUpdated byUsed by
open_tabsPOST /report-tabPOST /act when the prompt needs current-tab context
last_selectionPOST /report-selectionPOST /act for selection-driven prompts
queued_eventsPOST /queueGET /flush from a follow-up extension call
pinned_brain_notesPOST /pin-notePOST /act injects pinned notes as context

File map

cf-workers/extension-gateway
wrangler.toml
src
index.tsDO class, route table, app proxy
auth.tstoken validation against edge-auth
act.tsstreaming proxy to chat-v2