A live view of the computer an agent is using, full size or as a thumbnail with Take over.
Ledger bot's browser
Needs youLedger bot is working for Grace
https://portal.northwind.example/sign-in
The agent needs you. Sign in to the supplier portal. I'll carry on with the October invoices when you're done.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import type { Outcome } from "./ui/uicontext/components/domain/Outcome.ts"import { ComputerView } from "./ui/uicontext/components/kit/Computer.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { screen } from "./screen.ts"const Control = Schema.Literals(["agent", "offered", "person"])const Message = UiSchema.TaggedEnum({ RequestedTakeControlComputer: {}, RequestedReturnControlComputer: {}, CompletedControl: { control: Control },})// Stands in for the app handing the machine over: half a second, then it's done.const HandOver = Command.make("HandOverComputer", { args: { control: Control } }, ({ control }) => Effect.sleep("500 millis").pipe(Effect.as(Message.CompletedControl({ control }))),)const styles = stylex.create({ frame: { inlineSize: "min(100%, 40rem)" } })export const TakingControl = Html.component({ name: "TakingControl", model: Schema.Struct({ control: Control, pending: Schema.NullOr(Control) }), message: Message,}).make({ init: () => ({ control: "offered" as const, pending: null }), update: { RequestedTakeControlComputer: ($) => $.evolve({ pending: "person" }).run(HandOver.make({ control: "person" })), RequestedReturnControlComputer: ($) => $.evolve({ pending: "agent" }).run(HandOver.make({ control: "agent" })), CompletedControl: ($, { control }) => $.evolve({ control, pending: null }), }, view: (h, model) => { const outcome: Outcome | null = model.pending === null ? null : { _tag: "Pending", request: model.pending === "person" ? "take" : "return" } return h.div.attrs(sx(styles.frame)).children( ComputerView(h, { props: { id: "supplier-portal", agentId: "computer-taking-control", label: "Ledger bot's browser", state: "live", source: { _tag: "Image", src: screen(model.control !== "agent") }, url: model.control === "agent" ? "https://portal.northwind.example/invoices" : "https://portal.northwind.example/sign-in", activity: model.control === "person" ? "You're driving" : "Ledger bot is working for Grace", control: model.control, ...(model.control === "offered" ? { controlNote: "Sign in to the supplier portal. I'll carry on with the October invoices when you're done." } : {}), can: ["take", "return"], timeZone: "UTC", outcome, }, onEmit: { RequestedTakeControl: () => Message.RequestedTakeControlComputer(), RequestedReturnControl: () => Message.RequestedReturnControlComputer(), RequestedStartRecording: () => undefined, RequestedStopRecording: () => undefined, RequestedAction: () => undefined, RequestedReconnect: () => undefined, }, }), ) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/computerUsage
import type { ComputerControl } from "./ui/uicontext/components/kit/Computer.ts"import { ComputerView } from "./ui/uicontext/components/kit/Computer.ts"const Message = UiSchema.TaggedEnum({ TookControl: {}, ReturnedControl: {}, Reconnected: {} })// your app owns who drives and the machine's state; the view asks for changesexport const AgentScreen = (h: Html.H<typeof Message.Type>, frame: string, control: ComputerControl) => ComputerView(h, { props: { id: "vm-1", label: "Ledger bot's browser", state: "live", source: { _tag: "Image", src: frame }, control, can: ["take", "return", "reconnect"], timeZone: "Europe/London", }, onEmit: { RequestedTakeControl: () => Message.TookControl(), RequestedReturnControl: () => Message.ReturnedControl(), RequestedReconnect: () => Message.Reconnected(), RequestedStartRecording: () => undefined, RequestedStopRecording: () => undefined, RequestedAction: () => undefined, }, })Examples
Losing the connection
The view keeps the last frame, dimmed, and says the agent is still working. Reconnect tries again; the first try fails here, the second gets through.
Ledger bot's browser
OfflineLedger bot is working for Grace
https://portal.northwind.example/invoices
Lost connection
The view lost its connection. Ledger bot keeps working.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { ComputerView } from "./ui/uicontext/components/kit/Computer.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { screen } from "./screen.ts"const State = Schema.Literals(["offline", "reconnecting", "live"])const Message = UiSchema.TaggedEnum({ RequestedReconnectComputer: {}, CompletedReconnect: { reached: Schema.Boolean }, ClickedDropConnection: {},})// Stands in for reaching the machine: a second and a half, failing the first time.const Reconnect = Command.make("ReconnectComputer", { args: { attempt: Schema.Number } }, ({ attempt }) => Effect.sleep("1500 millis").pipe(Effect.as(Message.CompletedReconnect({ reached: attempt > 1 }))),)const styles = stylex.create({ frame: { inlineSize: "min(100%, 40rem)" } })export const ConnectionLost = Html.component({ name: "ConnectionLost", model: Schema.Struct({ state: State, attempts: Schema.Number }), message: Message,}).make({ init: () => ({ state: "offline" as const, attempts: 0 }), update: { RequestedReconnectComputer: ($) => $.evolve({ state: "reconnecting", attempts: (n) => n + 1 }).run(Reconnect.make({ attempt: $.model.attempts + 1 })), CompletedReconnect: ($, { reached }) => $.evolve({ state: reached ? "live" : "offline" }), ClickedDropConnection: ($) => $.evolve({ state: "offline", attempts: 0 }), }, view: (h, model) => h.div.attrs(sx(styles.frame)).children( ComputerView(h, { props: { id: "ledger-vm", agentId: "computer-connection-lost", label: "Ledger bot's browser", state: model.state, source: { _tag: "Image", src: screen(false) }, url: "https://portal.northwind.example/invoices", activity: "Ledger bot is working for Grace", ...(model.state === "offline" ? { reason: model.attempts === 0 ? "The view lost its connection. Ledger bot keeps working." : "Couldn't reach the machine. Check your network and try again.", } : {}), control: "agent", can: ["take", "reconnect"], timeZone: "UTC", actions: [{ id: "drop", label: "Simulate a dropped connection" }], }, onEmit: { RequestedTakeControl: () => undefined, RequestedReturnControl: () => undefined, RequestedStartRecording: () => undefined, RequestedStopRecording: () => undefined, RequestedAction: () => Message.ClickedDropConnection(), RequestedReconnect: () => Message.RequestedReconnectComputer(), }, }), ),})Screen beside a conversation
The agent's screen as a thumbnail with a live dot. When it needs you, it says why; Take over, then Hand back.
The portal wants the code sent to your phone. Take over to enter it; I'll wait.
import { Command, UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Effect, Schema } from "effect"import { ComputerPreview } from "./ui/uicontext/components/kit/Computer.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { screen } from "./screen.ts"const Control = Schema.Literals(["agent", "offered", "person"])const Message = UiSchema.TaggedEnum({ ClickedTakeOver: {}, ClickedHandBack: {}, CompletedControl: { control: Control } })// Stands in for the app handing the machine over.const HandOver = Command.make("HandOverPreview", { args: { control: Control } }, ({ control }) => Effect.sleep("400 millis").pipe(Effect.as(Message.CompletedControl({ control }))))const styles = stylex.create({ panel: { width: "min(100%, 20rem)" } })export const ScreenPreview = Html.component({ name: "ScreenPreview", model: Schema.Struct({ control: Control, busy: Schema.Boolean }), message: Message,}).make({ init: () => ({ control: "offered" as const, busy: false }), update: { ClickedTakeOver: ($) => $.evolve({ busy: true }).run(HandOver.make({ control: "person" })), ClickedHandBack: ($) => $.evolve({ busy: true }).run(HandOver.make({ control: "agent" })), CompletedControl: ($, { control }) => $.evolve({ control, busy: false }), }, view: (h, model) => h.div.attrs(sx(styles.panel)).children(ComputerPreview(h, { src: screen(model.control !== "agent"), label: "Vendor Bills' screen", live: model.control === "agent", control: model.control, note: "The portal wants the code sent to your phone. Take over to enter it; I'll wait.", onTakeOver: Message.ClickedTakeOver(), onHandBack: Message.ClickedHandBack(), busy: model.busy, })),})API reference
ComputerViewComponent
Props
| Name | Type | Description |
|---|---|---|
idrequired | string | Identifies the computer in the events the view sends |
labelrequired | string | What it is, for the label and the image's alt: "Research bot's screen", "Browser" |
source | ComputerSource | null | What to show: a live image or stream, a recording, or an interactive frame; null before there's a screen |
staterequired | ComputerState | The machine's lifecycle: unassigned, booting, live, idle, asleep, maintenance, offline or ended |
stateLabel | string | The product's words for the state, and why: "Updating", "Asleep: idle for 10 minutes" |
reason | string | Why it's in this state, shown under the screen: "Lost connection 2 minutes ago" |
activity | string | Who is on screen and for whom: "Research bot is working for Ada" |
url | string | The page the browser is on, shown in an address bar |
controlrequired | ComputerControl | Who drives: the agent, the person, the agent offering control, or nobody |
controlNote | string | Why the agent asks: "Sign in to your bank; I'll wait." |
recording | { state, endsAt, note } | Recording what the person shows: off, recording or processing, and when it stops |
actions | ComputerAction[] | The machine's own actions: Update, Restart browser, Reset computer |
canrequired | ("take" | "return" | "record" | "reconnect")[] | What this person may do: take or return control, record, and reconnect a lost view |
timeZonerequired | string | The person's time zone, for times shown |
locale | string | Formats times shown; the reader's own when left out |
aspect | "16/9" | "16/10" | "4/3" | The screen's shape; "16/10" by default |
href | string | Opens the live view on its own (a larger window) |
outcome | Outcome | null | The app's answer to the request in flight; its request is the action's id |
agentId | string | This view's id for agents; defaults to computer:<id> |
Events
| Event | Payload | Description |
|---|---|---|
RequestedTakeControl | { id: string } | The person asked to take control, after confirming when the agent is working |
RequestedReturnControl | { id: string } | "Hand back" |
RequestedStartRecording | { id: string } | The person started recording what they show the agent |
RequestedStopRecording | { id: string } | The person stopped the recording |
RequestedAction | { id: string; action: string } | The person picked one of actions, after confirming a destructive one |
RequestedReconnect | { id: string } | The person asked to reach the machine again after the view lost it |
Agent actions
| Action | Description |
|---|---|
ClickedTakeControl | Take control of the screen (the agent pauses). Taking it from a working agent asks first. |
ConfirmedTakeControlasks first | Take control from the working agent. Name the computer as your target. |
ClickedReturnControl | Hand control back to the agent |
ClickedReconnect | Reach the machine again after the view lost its connection |
ClickedStartRecording | Start recording a task to teach it |
ClickedStopRecording | Stop recording |
ClickedAction | Run one of the machine's actions by id (see page_query). Destructive ones ask first. |
ConfirmedActionasks first | Run the destructive action being confirmed. Name it as your target. |
ComputerPreviewView function
Options
| Name | Type | Description |
|---|---|---|
srcrequired | string | The latest frame of the screen; a quiet blank before there is one |
labelrequired | string | What it is: "Chief of Staff's screen"; the caption and the image's description |
liverequired | boolean | The agent is working on it now: a live dot |
controlrequired | "agent" | "offered" | "person" | "none" | Who drives: the agent, the person, or the agent asking the person to take over |
note | string | Why the agent asks for the person: "Sign in to the bank portal; I'll wait." |
onOpen | Message | Opens the full view |
onTakeOver | Message | — |
onHandBack | Message | — |
busy | boolean | A control change is on its way |
Accessibility
- The screen is an image, video or frame named for the computer and the page it shows; what the agent is doing is announced as it changes.
- When the agent needs you, an alert says so with a Take over button. Taking control from a working agent asks first, and Hand back returns it.
- Agents can take or return control and run its actions, and must name the computer when a step can't be undone.