API Reference for AI Toolkit Suggestions

This page contains the API reference of all AI Toolkit methods related to suggestions.

The Suggestion object

A Suggestion represents a proposed change to a range of content in the editor, typically generated by an AI agent. It allows previewing, reviewing, and applying changes, and can include multiple replacement options.

Properties

  • id (string): A unique identifier for the suggestion.
  • range (Range): The range of content in the editor that the suggestion applies to.
  • replacementOptions (ReplacementOption[]): One or more possible replacements for the selected range.
    • id (string): Unique identifier for this replacement option.
    • content (string | Slice): The replacement content.
    • metadata? (Record<string, any>): Optional extra metadata for this replacement option.
  • displayOptions? (DisplayOptions): Optional display options to control how the suggestion is rendered.
  • reviewMode? ('preview' | 'review'): The review mode of the suggestion.
  • isInlineGroup? (boolean): Whether this suggestion represents grouped inline changes.
  • metadata? (Record<string, any>): Optional extra metadata for the suggestion.

Style Suggestions

Learn more about how to customize the appearance of suggestions with the Style suggestions guide.

Example

// Get all active suggestions
const suggestions = toolkit.getSuggestions()

setSuggestions / addSuggestions

Replace or append suggestions.

Parameters

  • suggestions (Suggestion[]): A list of suggestions to display.

Returns

void

Example

// Set suggestions
toolkit.setSuggestions([
  {
    id: 'suggestion-1',
    range: { from: 0, to: 5 },
    replacementOptions: [{ id: '1', content: 'Improved text' }],
  },
])

// Clear all suggestions
toolkit.setSuggestions([])

acceptSuggestion

Accepts a specific suggestion.

Returns

AcceptSuggestionResult

Example

// Accept a suggestion by id and get feedback
const result = toolkit.acceptSuggestion('suggestion-1')
result.aiFeedback.events

rejectSuggestion

Rejects a specific suggestion without applying it.

Returns

RejectSuggestionResult

Example

// Reject a suggestion by id and get feedback
const result = toolkit.rejectSuggestion('suggestion-1')
result.aiFeedback.events

invertSuggestions

Applies all current suggestions to a copy of the document and returns the resulting document along with inverted suggestions that would undo those changes.

Returns

InvertSuggestionsResult

Example

const toolkit = getAiToolkit(editor)
const { doc, suggestions } = toolkit.invertSuggestions()