Interactive Answers
Co-edit Doc
A document the agent edits next to you — its own labelled caret, insertions and strike-throughs as suggestions, and margin notes on why, each to accept or reject.
1 variantMIT
Preview
Pricing page brief
You · Agent idle
§1Goal
Ship the new pricing page before the Q4 sales kickoff, so reps can link to it in outbound from day one.
§2Plans
Three plans: Starter, Team and Enterprise. Team costs $24 per seat a month, billed annually. Every plan includes unlimited AI credits.
Enterprise adds SSO, audit logs and a named support contact.
§3Launch
Go live on Monday, Nov 24, with the announcement email going out the same morning at 9:00 PT.
Installation
Copies the component into components/ui and installs its dependencies and theme tokens.
pnpm dlx shadcn@latest add https://tuffui.com/r/co-edit-doc.jsonUsage
Pass your own data and wire the callbacks to your agent runtime.
import { CoEditDoc, type CoEditSection } from "@/components/ui/co-edit-doc";
// The agent edits the brief next to the user. Each change it streams becomes a
// suggestion in the paragraph; its caret follows the one it is writing.
export function SharedBrief({ doc, agent }: Props) {
const [decisions, setDecisions] = useState<Record<string, CoEditDecision>>({});
const sections: CoEditSection[] = doc.sections.map((s) => ({
id: s.id,
label: s.ref, // "§2"
title: s.title, // "Plans"
paragraphs: s.paragraphs.map((p) =>
p.map((run) =>
run.suggestion
? {
id: run.suggestion.id,
delete: run.suggestion.before, // "$24"
insert: run.suggestion.after, // "$20", grows while the agent types
comment: run.suggestion.reason,
}
: run.text,
),
),
}));
return (
<CoEditDoc
title={doc.title}
sections={sections}
decisions={decisions}
onDecide={(id, decision) => {
setDecisions((d) => ({ ...d, [id]: decision }));
runTool(decision === "accepted" ? "apply_suggestion" : "drop_suggestion", { id });
}}
agentCaret={agent.cursor?.suggestionId ?? null}
agentTyping={agent.isTyping}
userAvatar={{ name: currentUser.name, src: currentUser.avatarUrl }}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
| sections* | CoEditSection[] | — | The document. Each section has a label, a title and paragraphs; a paragraph is a run of plain strings and suggestions. |
| decisions | Record<string, CoEditDecision> | — | Controlled decisions by suggestion id: "accepted" merges the insertion and drops the deletion, "rejected" does the opposite. Missing ids stay open. |
| defaultDecisions | Record<string, CoEditDecision> | {} | Starting decisions when uncontrolled. |
| onDecide | (id: string, decision: CoEditDecision) => void | — | Called by Accept and Reject on a margin note, and once per open suggestion by Accept all and Reject all. |
| agentCaret | string | null | — | Suggestion the agent's labelled caret sits after. Change it and the caret glides there; grow that suggestion's `insert` and it types. |
| agentTyping | boolean | false | Holds the caret solid while the agent types. Otherwise it blinks. |
| agentName | string | "Agent" | On the caret flag, the margin notes and the presence line. |
| userName | string | "You" | First name in the presence line. |
| userAvatar | { name: string; src?: string } | — | The user's avatar in the presence line. Defaults to initials of `userName`. |
| agentActivity | ReactNode | — | Replaces "Agent editing §2", which is built from the section the caret is in. |
| activeId | string | null | — | Suggestion picked out in the text and the margin, for example the one the agent mentions in chat. Hover does the same. |
| comments | boolean | true | Shows the margin notes: beside the text in wide cards, under each paragraph in narrow ones. |
| icon | Icon | FileText | Phosphor icon in the header tile. |
| title | ReactNode | "Untitled doc" | Document title in the header. |
| className | string | — | Extra classes for the root element. |
type CoEditSuggestion = {
id: string;
delete?: string; // "$24", struck through while open
insert?: string; // "$20", tinted while open
comment?: ReactNode; // the agent's margin note on why
};
type CoEditSegment = string | CoEditSuggestion;
type CoEditSection = {
id: string;
label?: string; // "§2"
title: string; // "Plans"
paragraphs: CoEditSegment[][];
};
type CoEditDecision = "accepted" | "rejected";
// Also exported: resolveText(segments, decisions) => the paragraph as plain text.