A file, document or code an agent made, as a card that opens a viewer.
Forge: Done. The retry fix and its test are ready to review.
src/payments · 16 linesSession: checkout retries
Summary · 2 min readSession: checkout retries
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { ArtifactCard, ArtifactViewer } from "./ui/uicontext/components/kit/Artifact.ts"import { Sheet } from "./ui/uicontext/components/Sheet.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font } from "./ui/uicontext/components/tokens.stylex.ts"import { artifacts, forge } from "./artifacts.ts"const styles = stylex.create({ reply: { display: "grid", gap: 10, inlineSize: "min(100%, 30rem)" }, text: { margin: 0, fontSize: font.base, lineHeight: 1.55, color: color.fg },})const Message = UiSchema.TaggedEnum({ OpenedArtifact: { id: Schema.String }, ClosedViewer: {}, ChoseVersion: { version: Schema.String },})export const AgentDeliverables = Html.component({ name: "AgentDeliverables", model: Schema.Struct({ open: Schema.NullOr(Schema.String), version: Schema.String }), message: Message,}).make({ init: () => ({ open: null, version: "v2" }), update: { OpenedArtifact: ($, { id }) => $.evolve({ open: id }), ClosedViewer: ($) => $.evolve({ open: null }), ChoseVersion: ($, { version }) => $.evolve({ version }), }, view: (h, { open, version }) => { const shown = artifacts.find((a) => a.id === open) return h.div.attrs(sx(styles.reply)).children( h.p.attrs(sx(styles.text)).children(`${forge.name}: Done. The retry fix and its test are ready to review.`), ...artifacts.map((a) => ArtifactCard(h, { key: a.id, props: { agentId: `artifact-demo:${a.id}`, id: a.id, kind: a.kind, title: a.title, detail: a.detail, origin: { label: "Session: checkout retries" }, actions: [{ id: "download", label: "Download" }] }, // no `href`: opening asks the app, which shows the viewer onEmit: { Opened: ({ id }) => Message.OpenedArtifact({ id }), RequestedAction: () => undefined }, })), Sheet(h, { open: shown !== undefined, size: "lg", title: shown?.title ?? "Artifact", onRequestedClose: Message.ClosedViewer(), children: [ shown !== undefined && ArtifactViewer(h, { key: shown.id, props: { agentId: `artifact-demo-viewer:${shown.id}`, id: shown.id, kind: shown.kind, title: shown.title, detail: shown.detail, content: shown.content, ...(shown.id === "patch" ? { versions: [{ id: "v2", label: "Version 2" }, { id: "v1", label: "Version 1" }], version } : {}), actions: [{ id: "download", label: "Download" }], attribution: { actor: forge }, }, onEmit: { RequestedAction: () => undefined, ChoseVersion: ({ version }) => Message.ChoseVersion({ version }) }, }), ], }), ) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/artifactUsage
import { ArtifactCard } from "./ui/uicontext/components/kit/Artifact.ts"const Message = UiSchema.TaggedEnum({ OpenedArtifact: { id: Schema.String } })export const PatchCard = (h: Html.H<typeof Message.Type>) => ArtifactCard(h, { props: { id: "patch-412", kind: "code", title: "retry.ts", detail: "src/payments · 16 lines" }, // without `href`, opening asks the app: show an ArtifactViewer in a Sheet or a page onEmit: { Opened: ({ id }) => Message.OpenedArtifact({ id }), RequestedAction: () => undefined }, })Examples
While it's made, and after
A card says when the work is still running, a draft, failed with the reason, or gone.
Migration plan
Generating…Reading 38 tables✦
DraftEdited 4 minutes ago
Load test report
The staging cluster stopped answering after 6 minutes. Run it again once it's back.
orders_schema_v1.sql
DeletedDeleted yesterday
import type { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { ArtifactCard } from "./ui/uicontext/components/kit/Artifact.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { forge } from "./artifacts.ts"const styles = stylex.create({ stack: { display: "grid", gap: 10, inlineSize: "min(100%, 30rem)" },})const none = { Opened: () => undefined, RequestedAction: () => undefined }export const ArtifactStates = <M>(h: Html.H<M>) => h.div.attrs(sx(styles.stack)).children( ArtifactCard(h, { key: "generating", props: { agentId: "artifact-states:generating", id: "migration", kind: "code", title: "Migration plan", status: "generating", progress: 0.4, detail: "Reading 38 tables", attribution: { actor: forge } }, onEmit: none, }), ArtifactCard(h, { key: "draft", props: { agentId: "artifact-states:draft", id: "release-notes", kind: "document", title: "Release notes 2.14", status: "draft", detail: "Edited 4 minutes ago" }, onEmit: none, }), ArtifactCard(h, { key: "failed", props: { agentId: "artifact-states:failed", id: "load-test", kind: "report", title: "Load test report", status: "failed", notice: "The staging cluster stopped answering after 6 minutes. Run it again once it's back." }, onEmit: none, }), ArtifactCard(h, { key: "deleted", props: { agentId: "artifact-states:deleted", id: "old-schema", kind: "file", title: "orders_schema_v1.sql", status: "deleted", detail: "Deleted yesterday" }, onEmit: none, }), )API reference
ArtifactCardComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
agentId | string | — | The id agents see this card by; artifact:<id> when left out |
idrequired | string | — | Identifies the artifact in the events it sends |
kindrequired | string | — | Document, deck, spreadsheet, chart, dashboard, image, video, page, report, pull-request, code, file, or the app's word |
titlerequired | string | — | The artifact's name: "Q3 planning deck" |
href | string | — | Where it opens: a real link. Without one, opening asks the app (Opened). |
status | ArtifactStatus | "ready" | Generating, ready, draft, failed, blocked, deleted or unavailable; "ready" by default |
detail | string | — | "Version 3 · edited 2 minutes ago", "12 slides" |
notice | string | — | For failed and blocked: why, as a sentence |
progress | number | — | 0 to 1, while generating |
preview | { src, alt } | — | A thumbnail for the tile |
attribution | AttributionData | — | Who made it, for whom, and how |
origin | ArtifactOrigin | — | Where it was made: a thread, a task, a run |
actions | ArtifactAction[] | — | What the menu offers: Download, Share, Delete |
layout | "card" | "tile" | "row" | "card" | A card, a tile with a preview, or a compact row; "card" by default |
pinned | boolean | — | Marks the artifact as pinned |
Events
| Event | Payload | Description |
|---|---|---|
Opened | { id: string } | The person opened an artifact that has no href |
RequestedAction | { id: string; action: string } | The person picked one of actions |
ArtifactViewerComponent
Props
| Name | Type | Default | Description |
|---|---|---|---|
agentId | string | — | The id agents see this viewer by; derived from id when left out |
idrequired | string | — | Identifies the artifact in the events it sends |
kindrequired | string | — | Document, deck, spreadsheet, image, page, code, or the app's word |
titlerequired | string | — | The artifact's name, as the viewer's heading |
status | ArtifactStatus | "ready" | Generating, ready, draft, failed, blocked, deleted or unavailable; "ready" by default |
detail | string | — | A line under the title: "Version 3 · edited 2 minutes ago" |
versions | { id, label }[] | — | Earlier versions to switch between, newest first |
version | string | — | The id of the version shown |
actions | ArtifactAction[] | — | What the toolbar offers: Download, Share, Delete |
notice | ArtifactNotice | — | A banner above the content, with its own actions: "Someone else edited this" |
content | ArtifactContent | — | What to show; leave out and fill the body slot instead (an editor, a table) |
pendingEdits | number | — | Unsaved edits: Save and Discard show, sent as RequestedAction "save" and "discard" |
attribution | AttributionData | — | Who made it, for whom, and how |
origin | ArtifactOrigin | — | Where it was made: a thread, a task, a run |
Events
| Event | Payload | Description |
|---|---|---|
RequestedAction | { id: string; action: string } | The person picked an action, a notice's action, Save or Discard |
ChoseVersion | { id: string; version: string } | The person picked another version from versions |
Slots
body
Accessibility
- Each card is an article named by its title; its status is announced, and a failure is read as an alert.
- Its actions sit behind a button named for the artifact, in a popover that closes with Escape.
- The viewer's version picker is a labelled select, and unsaved edits are announced. Agents can open, switch versions and run actions, and a destructive action waits for a person to confirm.