Skip to content

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.

  • widget is a reference (a declared widget’s name, omfp:<name>). code is 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 only react, react/jsx-runtime, react-dom, omfp/sdk and omfp/kit, no relative file.
  • Without wait the 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: true the tool waits: the widget calls submit(value) (any JSON) or cancel() of useAnswer(), and the tool answers {"status":"submitted","value":…} or {"status":"cancelled"}; with timeoutSeconds, {"status":"timeout"}. Meanwhile the thread needs the user, as with ask; 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; none outside a waiting card) instead of asking again. Its useStored state is kept under the instance card:<toolCallId>.
  • An image in your reply’s Markdown shows too when its source is a file path (![map](out/map.png), 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>
);
}