Comments
Read, create, resolve, and agent-drive text-anchored comment threads.
Comments are threads anchored to text ranges, rendered as margin chips, and preserved on DOCX round trip (except detached threads).
Read threads#
const { commentThreads, activeCommentId, commentsOpen } =
editor.review.getState();interface ReviseCommentThread {
root: ReviseCommentRecord;
replies: ReviseCommentRecord[];
anchor: { blockId: string; start: number; end: number } | null;
relatedSuggestionIds: string[];
detached: boolean;
}Deleting anchored text keeps the thread in the document with detached: true and anchor: null. Word requires a text anchor, so .docx export drops detached threads. On revise/server, doc.export({ format: "docx" }) reports unanchored comment counts in warnings. Resolve, delete, or re-anchor detached threads before exporting if they must survive round trip.
Add and manage comments#
Bodies are Markdown. Creation methods accept optional mentions as the last argument and return the new comment ID (or null if the target no longer exists):
editor.review.addCommentAtSelection("Is this cap mutual?");
editor.review.addCommentToRanges(
[{ blockId: "b12", start: 0, end: 24 }],
"Confirm the notice period.",
);
editor.review.addCommentToBlock("b12", "Needs legal review.");
editor.review.addCommentForSuggestion(suggestionId, "Why this wording?");
editor.review.replyToComment(commentId, "Agreed. Updated.");
editor.review.setCommentResolved(commentId, true);
editor.review.deleteComment(commentId);Panel and selection#
editor.view.setCommentsOpen(true);
editor.review.selectComment(commentId); // scrolls and opens panel
editor.review.selectComment(commentId, { openPanel: false }); // scrolls, keeps panel closed
editor.review.selectComment(null); // clear active threadThe SDK renders no built-in comments toggle button; your UI opens the panel (chrome). Selecting text in an editable document displays a margin insert-comment chip unless a draft is open, the document is read-only, or the selection already has a thread.
Linked suggestions#
const ids = editor.review.getRelatedSuggestionIds(commentId);
editor.review.acceptCommentSuggestions(commentId); // returns ReviseSuggestionDecision
editor.review.rejectCommentSuggestions(commentId); // returns ReviseSuggestionDecisionAgent comments#
Agents comment via leave_comment:
await editor.tools.execute("leave_comment", {
id: "b12",
anchor: { text: "capped at the fees paid in the preceding twelve months" },
comment: "Consider making this cap mutual.",
});Anchor forms: { text }, { start_text, end_text }, or { whole_block: true }. To reply, omit id and anchor:
await editor.tools.execute("leave_comment", {
reply_to_comment_id: threadId,
comment: "Agreed. The mutual version is market standard.",
});leave_comment only anchors to text the agent has read in the current
session. Call a read tool (read_blocks_from_index, etc.) first.
If the anchor text is absent from the requested block id but uniquely matches another read block, the comment anchors there and returns both data.blockId and data.requestedBlockId.
Read tools include existing threads as <comment-thread> elements in context.html. Starting a thread that overlaps an unresolved thread is rejected unless its ID is listed in acknowledge_existing_thread_ids. Tool comments are signed "Revise Agent" unless agent.name is set.
Comment agents#
editor.comments runs a delegated agent scoped to one comment thread:
await editor.comments.run(threadId, "Draft a redline that addresses this.");
editor.comments.steer(threadId, "Keep it to one sentence.");
editor.comments.cancel(threadId);
const state = editor.comments.getState(threadId);
useEffect(() => editor.comments.subscribe(setThreadRuns), [editor]);subscribe() publishes a ReadonlyMap<string, ReviseCommentAgentState> of active runs.