Proposed edits you can review, accept or reject.
- Assignee
- MPMira PatelTriage assistantsuggests Assignee: Mira Patel
Mira changed the invoice template on Tuesday, and VAT shows twice since then.
Also considered: - Project
- EU invoicingAutoTriage assistantsuggests Project: EU invoicing
Four of the last five VAT bugs were filed under EU invoicing.
- Labels
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Suggest, SuggestStatus } from "./ui/uicontext/components/kit/Suggest.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ // an issue's properties, label on the left and value on the right, as in a side panel properties: { display: "grid", gridTemplateColumns: "6.5rem minmax(0, 1fr)", alignItems: "center", rowGap: space.md, columnGap: space.lg, inlineSize: "min(100%, 26rem)", margin: 0, }, label: { fontSize: font.sm, color: color.muted }, value: { margin: 0, minWidth: 0 },})const Message = UiSchema.TaggedEnum({ RequestedAssignee: { value: Schema.String }, DismissedAssignee: {}, UndidProject: {},})const silent = { RequestedUndo: () => undefined, OpenedWhy: () => undefined, RequestedAction: () => undefined }export const IssueSuggestions = Html.component({ name: "IssueSuggestions", model: Schema.Struct({ assignee: SuggestStatus, picked: Schema.String, project: SuggestStatus }), message: Message,}).make({ init: () => ({ assignee: "pending", picked: "mira", project: "auto-applied" }), update: { // accepting is a request: here the app takes it at once RequestedAssignee: ($, { value }) => $.evolve({ assignee: "accepted", picked: value }), DismissedAssignee: ($) => $.evolve({ assignee: "dismissed" }), UndidProject: ($) => $.evolve({ project: "undone" }), }, view: (h, { assignee, picked, project }) => h.dl.attrs(sx(styles.properties)).children( h.dt.attrs(sx(styles.label)).children("Assignee"), h.dd.attrs(sx(styles.value)).children(Suggest(h, { key: "assignee", props: { agentId: "suggest-demo:assignee", id: "pay-415-assignee", field: "Assignee", value: picked === "omar" ? { value: "omar", label: "Omar Haddad", glyph: { _tag: "Person", id: "omar", name: "Omar Haddad", agent: false } } : { value: "mira", label: "Mira Patel", glyph: { _tag: "Person", id: "mira", name: "Mira Patel", agent: false } }, alternatives: [{ value: "omar", label: "Omar Haddad" }], status: assignee, reason: "Mira changed the invoice template on Tuesday, and VAT shows twice since then.", source: "Triage assistant", }, onEmit: { ...silent, RequestedAccept: ({ value }) => Message.RequestedAssignee({ value }), RequestedDismiss: () => Message.DismissedAssignee() }, })), h.dt.attrs(sx(styles.label)).children("Project"), h.dd.attrs(sx(styles.value)).children(Suggest(h, { key: "project", props: { agentId: "suggest-demo:project", id: "pay-415-project", field: "Project", value: { value: "eu-invoices", label: "EU invoicing" }, status: project, reason: "Four of the last five VAT bugs were filed under EU invoicing.", source: "Triage assistant", }, onEmit: { ...silent, RequestedAccept: () => undefined, RequestedDismiss: () => undefined, RequestedUndo: () => Message.UndidProject() }, })), h.dt.attrs(sx(styles.label)).children("Labels"), h.dd.attrs(sx(styles.value)).children(Suggest(h, { key: "labels", props: { agentId: "suggest-demo:labels", id: "pay-415-labels", field: "Labels", value: { value: "", label: "" }, status: "processing" }, onEmit: { ...silent, RequestedAccept: () => undefined, RequestedDismiss: () => undefined }, })), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/suggestUsage
import { Suggest, type SuggestStatus } from "./ui/uicontext/components/kit/Suggest.ts"const Message = UiSchema.TaggedEnum({ RequestedAssignee: { value: Schema.String }, DismissedAssignee: {},})export const AssigneeSuggestion = (h: Html.H<typeof Message.Type>, status: SuggestStatus) => Suggest(h, { props: { id: "pay-415-assignee", field: "Assignee", value: { value: "mira", label: "Mira Patel" }, status, reason: "Mira changed the invoice template on Tuesday.", }, onEmit: { // set the assignee, then pass `status: "accepted"` RequestedAccept: ({ value }) => Message.RequestedAssignee({ value }), RequestedDismiss: () => Message.DismissedAssignee(), RequestedUndo: () => undefined, OpenedWhy: () => undefined, RequestedAction: () => undefined, }, })Examples
An offer, with the change
As a card, a suggestion holds a bigger proposal and shows the change in its detail slot.
Juno
Move Thursday's standup so Lena can join?
Lena has a customer call 9:30–10:15 every Thursday this month.
− Thu 9:45–10:00 Standup + Thu 10:30–10:45 Standup
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { Suggest, SuggestStatus } from "./ui/uicontext/components/kit/Suggest.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"const styles = stylex.create({ frame: { inlineSize: "min(100%, 30rem)" }, diff: { margin: 0, padding: space.md, borderRadius: radius.md, backgroundColor: color.raised, fontFamily: font.mono, fontSize: font.xs, lineHeight: 1.6, overflowX: "auto", whiteSpace: "pre", }, removed: { color: color.danger }, added: { color: color.success },})const Message = UiSchema.TaggedEnum({ AnsweredOffer: { status: SuggestStatus } })export const ScheduleOffer = Html.component({ name: "ScheduleOffer", model: Schema.Struct({ status: SuggestStatus }), message: Message,}).make({ init: () => ({ status: "pending" }), update: { AnsweredOffer: ($, { status }) => $.evolve({ status }) }, view: (h, { status }) => h.div.attrs(sx(styles.frame)).children(Suggest(h, { props: { agentId: "suggest-offer", id: "standup-move", layout: "card", title: "Move Thursday's standup so Lena can join?", field: "Calendar", value: { value: "move", label: "Move it" }, status, reason: "Lena has a customer call 9:30–10:15 every Thursday this month.", source: "Juno", acceptLabel: "Move it", dismissLabel: "Keep 9:45", actions: [{ id: "mute", label: "Don't suggest calendar changes" }], }, onEmit: { RequestedAccept: () => Message.AnsweredOffer({ status: "accepted" }), RequestedDismiss: () => Message.AnsweredOffer({ status: "dismissed" }), RequestedUndo: () => undefined, OpenedWhy: () => undefined, RequestedAction: () => undefined, }, // the change itself, for the person to check before accepting slots: { detail: h.pre.attrs(sx(styles.diff)).children( h.span.attrs(sx(styles.removed)).children("− Thu 9:45–10:00 Standup\n"), h.span.attrs(sx(styles.added)).children("+ Thu 10:30–10:45 Standup"), ), }, })),})API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
agentId | string | — | This suggestion's id for agents, unique on the page; suggestion:<id> when left out |
idrequired | string | — | Identifies the suggestion in the events it sends |
fieldrequired | string | — | The property it would set: "Assignee" |
valuerequired | SuggestValue | — | The value it would set, with its label and glyph |
alternatives | SuggestValue[] | — | Other values the model considered, offered after the main one |
statusrequired | SuggestStatus | — | Where it stands: processing, pending, accepted, auto-applied, dismissed, undone, stale or unavailable |
reason | string | — | The model's reason; leave out until loaded (the chip reports OpenedWhy) |
reasonLoading | boolean | — | The reason is being fetched: Why shows a placeholder |
source | string | — | What made it: "Triage Intelligence" |
can | Can(["accept"]) | — | "accept" shows Accept; leave it out of the list for a viewer, or the agent that made it. Allowed when left out. |
acceptLabel | string | "Accept" | The accept button's label; "Accept" by default |
dismissLabel | string | "Dismiss" | The dismiss button's label; "Dismiss" by default |
reapply | string | — | An undone suggestion may be applied again: the button's label ("Apply again"); it asks with RequestedAccept |
title | string | — | A card's heading: "Want me to look into this?" |
layout | "chip" | "card" | "chip" | A compact chip beside the property, or a card with a title and actions; "chip" by default |
actions | { id, label }[] | — | More choices on a card: "Don't suggest in this channel" |
notice | string | — | Why the last request was refused, as a sentence |
Events
| Event | Payload | Description |
|---|---|---|
RequestedAccept | { id: string; value: string } | The person accepted the suggested value or an alternative |
RequestedDismiss | { id: string } | The person dismissed the suggestion |
RequestedUndo | { id: string } | Undo an auto-applied value: the app clears or restores the property |
OpenedWhy | { id: string } | The reason was asked for; load it if reason is missing |
RequestedAction | { id: string; action: string } | The person picked one of a card's actions |
Slots
detail
Accessibility
- Accept and Dismiss are buttons, and Why opens a popover with the reason that closes with Escape.
- Accepting, undoing and a refusal are announced as they happen.
- Agents see the field, the value and why it's suggested; accepting or dismissing must name the suggestion they read.