Start an app from its routes: sign-in in front, the shell and pages behind it, ids, the server connection and agent tools.
Installation
pnpm dlx shadcn@latest add checkfu/uicontext/app-bootstrapUsage
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
| Name | Type | Default | Description |
|---|---|---|---|
paths | string | AuthPathOverrides | /api/auth/* | The session routes: a base ("/auth") or single routes; /api/auth/* by default |
copy | AuthCopy | — | 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
| Name | Type | Description |
|---|---|---|
allowrequired | AllowList | What agents may touch: "Component.Action", "Component.*", or a bare "Component" to read |
tasks | TaskTool[] | — |
confirmTimeout | Parameters<typeof agentConfirmLayer>[0] extends infer O ? O extends { readonly timeout?: infer T } ? T : never : never | How long a consequential step waits for a person: 2 minutes by default |
CreateAppView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
name | string | "App" | The root component's name, for the message log and agents: "App" by default |
routesrequired | Router.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 |
auth | AuthOptions<Router.Routes["Type"]> | false | — | Sign-in before the app (the default), with its routes and words; false for an open app |
theme | AppTheme | Style[] | — | A theme from createAppTheme, or StyleX themes and styles for the root |
agent | AgentOptions | — | 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\`` |
lang | string | "en" | The document language: "en" by default |
offline | string | false | — | The words shown while the browser is offline, or false to show nothing |
AuthGateView function
Options
| Name | Type | Description |
|---|---|---|
sessionrequired | AsyncResult.AsyncResult<MeResult, unknown> | The Me query's result |
arrivalrequired | Arrival | How 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 |
copy | AuthCopy | — |
tone | "accent" | "neutral" | — |
paths | AuthPathOverrides | The sign-in screen's own session routes, over the provided AuthPaths |
ConnectionView function
Options
| Name | Type | Default | Description |
|---|---|---|---|
path | string | — | 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 |
origin | string | — | The origin to connect to; this page's by default |