What an agent may do in each app (always, ask first or never), and the moment it asks to use one.
- FilesRead and edit files in your drive
- MailRead, draft and send email
- Team chatRead channels and post messages
- CRMRead accounts and dealsNot connected
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { type AppAccess, type AppPermission, PermissionList } from "./ui/uicontext/components/kit/PermissionSheet.ts"import { sx } from "./ui/uicontext/components/Sx.ts"const Access = Schema.Literals(["always", "ask", "never"])const Message = UiSchema.TaggedEnum({ ChangedAccess: { app: Schema.String, access: Access } })const apps: ReadonlyArray<Omit<AppPermission, "access">> = [ { id: "files", name: "Files", mark: { letter: "F", tone: "blue" }, description: "Read and edit files in your drive" }, { id: "mail", name: "Mail", mark: { letter: "M", tone: "red" }, description: "Read, draft and send email" }, { id: "chat", name: "Team chat", mark: { letter: "T", tone: "purple" }, description: "Read channels and post messages" }, { id: "crm", name: "CRM", mark: { letter: "R", tone: "yellow" }, description: "Read accounts and deals", disconnected: true },]const styles = stylex.create({ frame: { width: "min(100%, 40rem)" } })export const AppPermissions = Html.component({ name: "PermissionListExample", model: Schema.Struct({ access: Schema.Record(Schema.String, Access) }), message: Message,}).make({ init: () => ({ access: { files: "always", mail: "ask", chat: "ask", crm: "ask" } }), update: { ChangedAccess: ($, { app, access }) => $.evolve({ access: (all) => ({ ...all, [app]: access }) }) }, view: (h, model) => h.div.attrs(sx(styles.frame)).children(PermissionList(h, { apps: apps.map((app) => ({ ...app, access: (model.access[app.id] ?? "ask") as AppAccess })), onChange: (app, access) => Message.ChangedAccess({ app, access }), })),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/permission-sheetUsage
import { PermissionList, PermissionRequest } from "./ui/uicontext/components/kit/PermissionSheet.ts"const Message = UiSchema.TaggedEnum({ ChangedAccess: { app: Schema.String, access: Schema.Literals(["always", "ask", "never"]) }, Answered: { request: Schema.String, allow: Schema.Boolean },})// the settings list goes in a Sheet; the request goes in the conversation where the task stoppedexport const Permissions = (h: Html.H<typeof Message.Type>) => [ PermissionList(h, { apps: [{ id: "mail", name: "Mail", mark: { letter: "M", tone: "red" }, description: "Read, draft and send email", access: "ask" }], onChange: (app, access) => Message.ChangedAccess({ app, access }), }), PermissionRequest(h, { agent: "Work", state: "pending", apps: [{ id: "mail", name: "Mail", mark: { letter: "M", tone: "red" }, scope: "full", warning: "Can send email as you" }], onAllow: Message.Answered({ request: "p1", allow: true }), onDeny: Message.Answered({ request: "p1", allow: false }), }),]Examples
When a task asks
Each app with its scope, and a warning where it reaches far. Deny or Allow for this session; the answer stays as a receipt.
Work wants to use:
- Team chatFull controlCan post as you
- AccountingView only
You'll be asked again next task. Change this for good in Permissions.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import { Schema } from "effect"import { Button } from "./ui/uicontext/components/Button.ts"import { PermissionRequest } from "./ui/uicontext/components/kit/PermissionSheet.ts"const Message = UiSchema.TaggedEnum({ Answered: { allow: Schema.Boolean }, ClickedReset: {} })export const AskToUse = Html.component({ name: "PermissionRequestExample", model: Schema.Struct({ state: Schema.Literals(["pending", "allowed", "denied"]) }), message: Message,}).make({ init: () => ({ state: "pending" }), update: { Answered: ($, { allow }) => $.evolve({ state: allow ? "allowed" : "denied" }), ClickedReset: ($) => $.evolve({ state: "pending" }), }, view: (h, model) => h.div.children( PermissionRequest(h, { agent: "Work", state: model.state, apps: [ { id: "chat", name: "Team chat", mark: { letter: "T", tone: "purple" }, scope: "full", warning: "Can post as you" }, { id: "books", name: "Accounting", mark: { letter: "A", tone: "orange" }, scope: "view" }, ], note: "You'll be asked again next task. Change this for good in Permissions.", onAllow: Message.Answered({ allow: true }), onDeny: Message.Answered({ allow: false }), }), model.state !== "pending" && Button(h, { size: "sm", emphasis: "ghost" }).on("click", Message.ClickedReset()).children("Ask again"), ),})API reference
PermissionListView function
Options
| Name | Type | Description |
|---|---|---|
appsrequired | AppPermission[] | — |
onChangerequired | (app: string, access: AppAccess) => Message | — |
label | string | — |
style | Style | — |
PermissionRequestView function
Options
| Name | Type | Description |
|---|---|---|
agentrequired | string | Who asks: the agent's name |
appsrequired | RequestedApp[] | — |
note | string | A sentence under the apps: what happens while it works |
staterequired | "pending" | "allowed" | "denied" | — |
onAllowrequired | Message | — |
onDenyrequired | Message | — |
answering | boolean | The answer is on its way: the buttons wait |
style | Style | — |