App Bootstrap

Start an app from its routes: sign-in in front, the shell and pages behind it, ids, the server connection and agent tools.

Preview

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/app-bootstrap

Usage

import { createApp } from "./ui/uicontext/components/app/createApp.ts"
const AppRoute = Route.union({	Home: Route.make("/"),	Projects: Route.make("/projects"),	NotFound: Route.make("/*"),})// sign-in in front, then the page for the route inside the shellexport const app = createApp({	routes: AppRoute,	auth: { paths: "/api/auth" },	title: (title) => `${title} · Field Notes`,	page: (h, { route, me }) => {		switch (route._tag) {			case "Home": return h.h1.key("home").children(`Welcome back, ${me.name}`)			case "Projects": return h.h1.key("projects").children("Projects")			case "NotFound": return h.h1.key("missing").children("Page not found")		}	},	shell: (h, { page }) => h.main.children(page),})// src/entry.tsapp.run()

API reference

AuthView function

Options

Auth options
NameTypeDefaultDescription
pathsstring | AuthPathOverrides/api/auth/*The session routes: a base ("/auth") or single routes; /api/auth/* by default
copyAuthCopy—The sign-in screen's words
tone"accent" | "neutral"—The submit button: the accent (default), or solid neutral
arrival(route: Route) => Arrival—How the person arrived, from the route. By default a Claim route's search.code is the owner's claim link and a Join route's params.id and search.code are an invitation.

AgentView function

Options

Agent options
NameTypeDescription
allowrequiredAllowListWhat agents may touch: "Component.Action", "Component.*", or a bare "Component" to read
tasksTaskTool[]—
confirmTimeoutParameters<typeof agentConfirmLayer>[0] extends infer O ? O extends { readonly timeout?: infer T } ? T : never : neverHow long a consequential step waits for a person: 2 minutes by default

CreateAppView function

Options

CreateApp options
NameTypeDefaultDescription
namestring"App"The root component's name, for the message log and agents: "App" by default
routesrequiredRouter.Routes—The app's route union, with a /* catch-all
pagerequired(h: Html.H<AppMessage>, context: Context<Router.Routes["Type"], AuthOptions<Router.Routes["Type"]> | false>) => View.Input<AppMessage, RP>—What the current route shows; key each page by routes.printPath(route)
shell( h: Html.H<AppMessage>, context: Context<Router.Routes["Type"], AuthOptions<Router.Routes["Type"]> | false> & { readonly page: View.Input<AppMessage, RP> }, ) => View.Input<AppMessage, RS>—The frame around every page, such as AppShell with the page in its main slot
authAuthOptions<Router.Routes["Type"]> | false—Sign-in before the app (the default), with its routes and words; false for an open app
themeAppTheme | Style[]—A theme from createAppTheme, or StyleX themes and styles for the root
agentAgentOptions—The page's agent tools and the confirmation dialog for consequential steps
title(title: string) => string—The document title around each page's: (title) => \${title} · Acme\``
langstring"en"The document language: "en" by default
offlinestring | false—The words shown while the browser is offline, or false to show nothing

AuthGateView function

Options

AuthGate options
NameTypeDescription
sessionrequiredAsyncResult.AsyncResult<MeResult, unknown>The Me query's result
arrivalrequiredArrivalHow the person arrived: plain sign-in, a claim link or an invitation
signedInrequired(me: SignedInMember) => View.Input<Message, any>The signed-in app; key its root by me.id so a new person starts fresh
copyAuthCopy—
tone"accent" | "neutral"—
pathsAuthPathOverridesThe sign-in screen's own session routes, over the provided AuthPaths

ConnectionView function

Options

Connection options
NameTypeDefaultDescription
pathstring—The API's path on this origin: "/api" by default
protocol"http" | "ws""http""ws" for a WebSocket API (it also provides the browser's WebSocket); "http" by default
originstring—The origin to connect to; this page's by default

Source