affectUI › Components › Agents

Prompt History

A chat's prompts on a rail like git – edit any of them and a new version branches out right there, while the one you left fades back but stays.

Part of affectUI Pro. Install: npx shadcn@latest add https://www.affectui.com/r/prompt-history.json · Import from @/components/ui/prompt-history

When to use

  • Chats where people rework their prompts – edit one and the agent answers again from there, without losing the old answer
  • Showing every version of a conversation at once: the way to the answer you're on in blue, the versions you left faded beside it
  • Agents that write or change files – each answer carries a tag with the files it touched and what it cost

When not to use

  • An agent's own run, step by step – use Agent Checkpoints
  • Saved prompts to reuse – use Prompt Library
  • The conversation itself, message by message – use a chat thread

Usage

import { PromptHistory, type PromptTurn } from "@/components/ui/prompt-history";

const turns: PromptTurn[] = [
  { id: "t1", prompt: "Draft a launch email for our new pricing", files: ["Pricing launch/", "launch-email.docx", "pricing.xlsx"], cost: 0.04 },
  { id: "t2", parent: "t1", prompt: "Make it shorter", files: ["launch-email.docx"], cost: 0.02 },
  // A second turn after t1 is an edit of t2 – a new version branches out
  { id: "t3", parent: "t1", prompt: "Make it more playful", files: ["launch-email.docx"], status: "writing" },
];

export function History() {
  return (
    <PromptHistory
      turns={turns}
      head="t3"
      chat="Launch email"
      agent={{ id: "writer", name: "Writer" }}
      onEdit={(turn, prompt) => chat.resend(turn.parent, prompt)}
      onOpen={(turn) => chat.open(turn.id)}
    />
  );
}

Props

NameTypeDefaultDescription
turnsPromptTurn[]{ id, prompt, parent?, status?, files?, cost? } in the order they were asked – pass them again whenever one is added or changes
parentstringPer turn, the one it follows – a turn whose parent already has a later one is an edit and starts a new version on its own lane
status"writing" | "done" | "failed" | "stopped""done"Per turn – writing shimmers and its mark twinkles, failed gets a badge, stopped means you moved on while the agent answered
filesstring[]Per turn, the files its answer wrote or changed – a name ending in "/" is a folder; the first one names the tag, the rest count as +N
headstringthe last turnId of the turn you're on – the way to it is blue, every version off it fades back
onEdit(turn: PromptTurn, prompt: string) => voidA prompt was edited – add a new turn with the same parent and the new text. Without it, the prompts have no Edit
onOpen(turn: PromptTurn) => voidA version left behind was opened – move head to its last turn. Without it, those prompts have no Open
draft{ id: string; text: string } | nullShows the edit box on a turn with this text, without taking focus – to play an edit back, e.g. in a demo
agent{ id: string; name: string }{ id: "assistant", name: "Assistant" }The agent that answers – every answer gets its own pixel mark from its id and the turn's
chatstringWhat the chat is about, next to the title
fileIcon(name: string) => ReactNodeA logo of your own for a file – return nothing to keep the built-in one
formatCost(amount: number) => stringdollars, e.g. "$0.04"Formats each turn's cost and the total in the bar on top
titlestring"Prompt history"Heading of the bar
classNamestringExtra class on the root

Keyboard

  • ↑ / ↓: Moves between the prompts
  • Home / End: Jumps to the first or the last prompt
  • Enter / Space: Edits the focused prompt in place – or opens a version you left
  • Enter: In the edit box: sends the prompt as a new version
  • Esc: Closes the edit box and returns to the prompt

Accessibility

  • The prompts are an ordered list with one tab stop; the arrow keys move between them
  • Every prompt is a button that says its text, its version, its status, its files and whether it's a version you left
  • The edit box is labelled and Send is disabled until the text changes; Esc returns focus to the prompt, and after sending it moves to the new version
  • The count in the bar on top is announced politely when it changes
  • Status is never color alone: failed has a badge, stopped says so, versions carry v2, v3

Responsive

  • Every row has a fixed height, so nothing jumps when an answer finishes or fails
  • Past fourteen prompts the list scrolls inside the card and keeps the one you're on in view
  • Long prompts end in an ellipsis and say themselves in full on hover; long file names shorten before their extension, so .docx stays in view; an empty prompt says so
  • Narrow, the chat name, the file names, each turn's cost and the version count give way – the prompt keeps room, the logos, +N and the total stay
  • Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"

Requirements

  • React 19

Related

  • Agent Checkpoints – An agent's run as a line of checkpoints, like git for agents – rewind to any of them and a new attempt branches out of it, while the one it left fades back but stays
  • Prompt Library – Saved prompt templates with variables – type straight into the sentence, watch the finished prompt assemble below, and use it once every variable is filled
  • Chat Composer – Prompt composer with model picker, voice input, app connections and approval request
  • Agent Tree – Who started whom – an orchestrator and its sub-agents as a live tree, with status, cost and time on every card, costs rolling up each branch, and branches that fold to one line