Cards in the chat
For what the user needs for one moment of the conversation — a terminal showing something, a chart of a result, a
question with its own controls — draw a card: omfp_card { widget | code, props?, title?, wait?, timeoutSeconds? }
puts a widget in that tool call’s card in the chat. Nothing goes into the views and no file is written. Content that
should stay belongs in a mount (omfp://docs/views); a question with a few plain answers belongs in ask.
widgetis a reference (a declared widget’s name,omfp:<name>).codeis the source of a one-file component (default export) compiled at the call; a compile error is the tool’s error (card.tsx:line:column: message). It imports onlyreact,react/jsx-runtime,react-dom,omfp/sdkandomfp/kit, no relative file.- Without
waitthe tool answers{"status":"shown"}at once and the card stays live: a terminal (omfp:terminal { command }), a file you made (omfp:file { path }shows an image or a PDF). It stays open after your reply until the user’s next message, then collapses. - With
wait: truethe tool waits: the widget callssubmit(value)(any JSON) orcancel()ofuseAnswer(), and the tool answers{"status":"submitted","value":…}or{"status":"cancelled"}; withtimeoutSeconds,{"status":"timeout"}. Meanwhile the thread needs the user, as withask; the card always offers Cancel, and the first answer from any window wins. - The widget mounts again from the call’s arguments whenever the card is shown open (a reload, another window, a
collapsed card reopened). A waiting widget must draw its finished state from
useAnswer().state(waiting,submitted,cancelled,timeout,aborted;noneoutside a waiting card) instead of asking again. ItsuseStoredstate is kept under the instancecard:<toolCallId>. - An image in your reply’s Markdown shows too when its source is a file path (
, relative to the workspace folder, or absolute): no card needed.
import { Button, Card, Checkbox } from "omfp/kit";import { useAnswer } from "omfp/sdk";import { useState } from "react";export default function PickFiles({ files }: { files: string[] }) { const answer = useAnswer(); const [picked, setPicked] = useState<string[]>([]); if (answer.state !== "waiting") { const chosen = answer.state === "submitted" ? (answer.value as string[]) : []; return <Card title="Files">{answer.state === "submitted" ? chosen.join(", ") || "none" : answer.state}</Card>; } return ( <Card title="Which files go in?" actions={<Button onPress={() => answer.submit(picked)}>Include</Button>}> {files.map((file) => ( <Checkbox key={file} isSelected={picked.includes(file)} onChange={(on) => setPicked(on ? [...picked, file] : picked.filter((f) => f !== file))} > {file} </Checkbox> ))} </Card> );}