Skip to main content
Reference for AIActions helpers and the high-level action surface. AIActions exposes two layers of functionality:
  1. Wrapper methods on the AIActions instance (lifecycle & raw completions).
  2. Action helpers under ai.action, which combine prompting, response parsing, and editor updates.

Instance methods

waitUntilReady

Resolves once provider/user set-up completes. Safe to call multiple times. Returns: Promise<void> Example:

getIsReady

Returns true after initialisation. Returns: boolean Example:

getCompletion

Single-shot completion that includes the serialized document context. Parameters:
string
required
The user prompt for the AI
CompletionOptions
Optional completion configuration
Returns: Promise<string> Example:

streamCompletion

Streams a completion, firing hooks for each chunk and resolving with the full string. Parameters:
string
required
The user prompt for the AI
StreamOptions
Optional streaming configuration
Returns: Promise<string> Example:

getDocumentContext

Retrieves the current document context for AI processing. Returns the plain text content of the active editor document. Returns: string Example:

Action helpers

All actions return a Result object containing { success: boolean; results: FoundMatch[] }. Each FoundMatch includes the AI text (originalText, suggestedText) alongside the resolved document positions.

find

Finds the first occurrence and resolves its document positions. Parameters:
string
required
AI instruction describing what to find
Returns: Promise<Result> Example:

findAll

Finds every occurrence matching the instruction. Parameters:
string
required
AI instruction describing what to find
Returns: Promise<Result>

highlight

Highlights the first match in the editor with the specified color. Parameters:
string
required
AI instruction describing what to highlight
string
default:"#6CA0DC"
Hex color code for the highlight
Returns: Promise<Result>

replace

Replaces a single match with AI-generated text. Parameters:
string
required
AI instruction describing what to replace and how
Returns: Promise<Result> Example:
Note: Replacements are inserted as fresh text, so existing styling (bold, numbering, etc.) might not carry over. Re-apply any required formatting after the AI edit.

replaceAll

Replaces every match with AI-generated text. Parameters:
string
required
AI instruction describing what to replace and how
Returns: Promise<Result>

literalReplace

Performs literal text replacement when you have exact find and replace text. Prefer this over replaceAll when the user provides explicit text pairs (e.g., “change X to Y”, “replace A with B”). Automatically replaces all instances. Parameters:
string
required
Exact text to find
string
required
Exact replacement text
object
Optional replacement options
Returns: Promise<Result> Example:

insertTrackedChange

Inserts a tracked change attributed to the configured user (e.g., “RedlineBot”). Parameters:
string
required
AI instruction describing what change to track
Returns: Promise<Result> Example:
Note: Tracked changes are also inserted as newly generated text, which can strip local formatting. Double-check for styling regressions after accepting or rejecting the change.

insertTrackedChanges

Inserts tracked changes for multiple matches. Parameters:
string
required
AI instruction describing what changes to track
Returns: Promise<Result>

insertComment

Inserts a comment annotating the first match. Parameters:
string
required
AI instruction describing what to comment on
Returns: Promise<Result>

insertComments

Inserts comments for every match. Parameters:
string
required
AI instruction describing what to comment on
Returns: Promise<Result>

literalInsertComment

Inserts a comment when you have exact find text and comment text. Prefer this over insertComments when the user provides explicit text to find and exact comment text to add. Automatically adds comments to all instances. Parameters:
string
required
Exact text to find
string
required
Exact comment text to add
object
Optional search options
Returns: Promise<Result> Example:

summarize

Returns AI-generated summary text in the suggestedText field. Streams results if the provider supports streaming. Parameters:
string
required
AI instruction describing what to summarize
Returns: Promise<Result> Example:

insertContent

Inserts AI-generated content into the document at the current cursor position, or appends it to the end if no cursor location is set. Content streams directly into the editor as it arrives from the provider. Parameters:
string
required
AI instruction describing what content to insert
object
Optional insertion options
Returns: Promise<Result> Example:

AI Planner

The AI Planner enables multi-step AI workflows where the AI can plan and execute a sequence of actions automatically.

planner

Access the planner instance via the planner property. The planner is lazily initialized on first access. Returns: AIPlanner Example:

planner.execute

Executes a user instruction by having the AI plan and execute a sequence of actions. Parameters:
string
required
Natural language instruction describing the multi-step task to perform
CompletionOptions
Optional completion configuration for the planning phase
Returns: Promise<AIPlannerExecutionResult> Result structure:
Example:
Use cases:
  • Complex multi-step document reviews
  • Automated document improvement workflows
  • Batch operations across multiple document sections
  • Conditional workflows based on document content
The planner automatically selects and sequences the appropriate tools based on your instruction. You don’t need to specify which tools to use - the AI decides the best approach.

Types

Result

Standard result structure returned by all AI actions.

FoundMatch

Represents a match found by AI operations, with optional original text, suggested replacement, and document positions.

DocumentPosition

Position range in the document (character offsets).

CompletionOptions

Configuration options for getCompletion() calls.

StreamOptions

Configuration options for streamCompletion() calls. Extends CompletionOptions with a stream flag.

Tool utilities

The package exports utilities for working with AI tools and the tool registry:

createToolRegistry

Creates a tool registry with built-in and custom tools. Used internally by the planner but can be used for custom implementations. Parameters:
AIToolActions
required
AI actions service instance
AIToolDefinition[]
Optional array of custom tool definitions
Returns: Map<AIToolName, AIToolDefinition> Example:

getToolDescriptions

Gets formatted descriptions of all tools in a registry for use in system prompts. Parameters:
Map<AIToolName, AIToolDefinition>
required
Tool registry map
Returns: string Example:

isValidTool

Type guard to validate if a value is a valid tool definition. Parameters:
unknown
required
Value to validate
Returns: boolean Example:

Advanced exports

For advanced use cases, the package exports additional classes and utilities:
  • AIActionsService - Core service with direct access to action implementations
  • EditorAdapter - Editor interaction layer for custom integrations
  • createAIProvider(config) - Factory function for creating AI providers
  • Utilities: validateInput(), parseJSON(), removeMarkdownCodeBlocks(), generateId()