The browser an agent works in: tabs, navigation, the address and the page.
mail.harborpine.example/inbox/remittance-4410
Remittance advice — invoice 4410
From Priya Anand, Alder Supply
We paid invoice 4410 on 16 November by bank transfer.
Amount $1,920.00
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { type BrowserTab, BrowserPanel } from "./ui/uicontext/components/kit/Browser.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const pages: Readonly<Record<string, { readonly heading: string; readonly lines: ReadonlyArray<string> }>> = { invoice: { heading: "Invoice 4410", lines: ["Alder Supply Co. · Overdue 18 days", "Packaging film, 40 rolls · $1,480.00", "Delivery · $440.00", "Total · $1,920.00"] }, remittance: { heading: "Remittance advice — invoice 4410", lines: ["From Priya Anand, Alder Supply", "We paid invoice 4410 on 16 November by bank transfer.", "Amount $1,920.00"] }, bank: { heading: "Operating ••4417", lines: ["Nov 17 · ALDER SUPPLY CO / REF 4410 · +$1,895.00", "Nov 17 · Marlow Freight · −$1,240.00"] }, blank: { heading: "New tab", lines: [] },}const all: ReadonlyArray<BrowserTab> = [ { id: "invoice", title: "Invoice 4410 · Ledger", url: "https://ledger.harborpine.example/invoices/4410", mark: { letter: "L", tone: "indigo" } }, { id: "remittance", title: "Remittance advice — 4410", url: "https://mail.harborpine.example/inbox/remittance-4410", mark: { letter: "M", tone: "blue" } }, { id: "bank", title: "Transactions · Operating", url: "https://bank.example/accounts/operating", mark: { letter: "B", tone: "green" } },]const Message = UiSchema.TaggedEnum({ PickedTab: { tab: Schema.String }, ClosedTab: { tab: Schema.String }, ClickedNewTab: {} })const styles = stylex.create({ frame: { height: 420, borderRadius: radius.lg, overflow: "hidden", borderWidth: 1, borderStyle: "solid", borderColor: color.line }, page: { display: "flex", flexDirection: "column", gap: space.sm, padding: space.xl }, heading: { margin: 0, fontSize: font.xl, fontWeight: 600 }, line: { margin: 0, color: color.muted, fontSize: font.sm },})export const AssistantBrowser = Html.component({ name: "AssistantBrowser", model: Schema.Struct({ tabs: Schema.Array(Schema.String), active: Schema.NullOr(Schema.String), opened: Schema.Number }), message: Message,}).make({ init: () => ({ tabs: ["invoice", "remittance", "bank"], active: "remittance", opened: 0 }), update: { PickedTab: ($, { tab }) => $.evolve({ active: tab }), ClosedTab: ($, { tab }) => { const index = $.model.tabs.indexOf(tab) const tabs = $.model.tabs.filter((t) => t !== tab) return $.evolve({ tabs, active: $.model.active === tab ? (tabs[Math.min(index, tabs.length - 1)] ?? null) : $.model.active }) }, ClickedNewTab: ($) => { const id = `blank-${$.model.opened + 1}` return $.evolve({ tabs: (tabs) => [...tabs, id], active: id, opened: (n) => n + 1 }) }, }, view: (h, model) => { const tabOf = (id: string): BrowserTab => all.find((t) => t.id === id) ?? { id, title: "New tab", url: "about:blank" } const page = pages[model.active?.startsWith("blank") === true ? "blank" : (model.active ?? "blank")] ?? pages.blank! return h.div.attrs(sx(styles.frame)).children(BrowserPanel(h, { label: "Accounts' browser", tabs: model.tabs.map(tabOf), active: model.active ?? undefined, onSelect: (tab) => Message.PickedTab({ tab }), onClose: (tab) => Message.ClosedTab({ tab }), onNew: Message.ClickedNewTab(), canBack: false, canForward: false, empty: "All tabs are closed.", children: [h.div.attrs(sx(styles.page)).children( h.h3.attrs(sx(styles.heading)).children(page.heading), page.lines.map((line, i) => h.p.key(`l${i}`).attrs(sx(styles.line)).children(line)), )], })) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/browserUsage
import { type BrowserTab, BrowserPanel } from "./ui/uicontext/components/kit/Browser.ts"const Message = UiSchema.TaggedEnum({ PickedTab: { tab: Schema.String }, ClosedTab: { tab: Schema.String } })// the tabs are the app's: a press asks, and the agent's browser answers with the new tabsexport const AgentBrowser = (h: Html.H<typeof Message.Type>, tabs: ReadonlyArray<BrowserTab>, active: string) => BrowserPanel(h, { label: "Accounts' browser", tabs, active, onSelect: (tab) => Message.PickedTab({ tab }), onClose: (tab) => Message.ClosedTab({ tab }), children: [h.p.children("The page the agent is reading")], })API reference
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | What this browser is, for screen readers: "Accounts' browser" |
tabsrequired | BrowserTab[] | — |
activerequired | string | The shown tab's id |
onSelect | (id: string) => Message | — |
onClose | (id: string) => Message | — |
onNew | Message | — |
onBack | Message | — |
onForward | Message | — |
onReload | Message | — |
canBack | boolean | — |
canForward | boolean | — |
childrenrequired | View.Children | The shown tab's page |
empty | string | What shows with no tabs open |
style | Style | — |