AIActions exposes two layers of functionality:
- Wrapper methods on the
AIActionsinstance (lifecycle & raw completions). - 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:
The user prompt for the AI
Optional completion configuration
Promise<string>
Example:
streamCompletion
Streams a completion, firing hooks for each chunk and resolving with the full string.
Parameters:
The user prompt for the AI
Optional streaming configuration
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 aResult 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:
AI instruction describing what to find
Promise<Result>
Example:
findAll
Finds every occurrence matching the instruction.
Parameters:
AI instruction describing what to find
Promise<Result>
highlight
Highlights the first match in the editor with the specified color.
Parameters:
AI instruction describing what to highlight
Hex color code for the highlight
Promise<Result>
replace
Replaces a single match with AI-generated text.
Parameters:
AI instruction describing what to replace and how
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:
AI instruction describing what to replace and how
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:
Exact text to find
Exact replacement text
Optional replacement options
Promise<Result>
Example:
insertTrackedChange
Inserts a tracked change attributed to the configured user (e.g., “RedlineBot”).
Parameters:
AI instruction describing what change to track
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:
AI instruction describing what changes to track
Promise<Result>
insertComment
Inserts a comment annotating the first match.
Parameters:
AI instruction describing what to comment on
Promise<Result>
insertComments
Inserts comments for every match.
Parameters:
AI instruction describing what to comment on
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:
Exact text to find
Exact comment text to add
Optional search options
Promise<Result>
Example:
summarize
Returns AI-generated summary text in the suggestedText field. Streams results if the provider supports streaming.
Parameters:
AI instruction describing what to summarize
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:
AI instruction describing what content to insert
Optional insertion options
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:
Natural language instruction describing the multi-step task to perform
Optional completion configuration for the planning phase
Promise<AIPlannerExecutionResult>
Result structure:
- 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
FoundMatch
DocumentPosition
CompletionOptions
getCompletion() calls.
StreamOptions
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:
AI actions service instance
Optional array of custom tool definitions
Map<AIToolName, AIToolDefinition>
Example:
getToolDescriptions
Gets formatted descriptions of all tools in a registry for use in system prompts.
Parameters:
Tool registry map
string
Example:
isValidTool
Type guard to validate if a value is a valid tool definition.
Parameters:
Value to validate
boolean
Example:
Advanced Exports
For advanced use cases, the package exports additional classes and utilities:AIActionsService- Core service with direct access to action implementationsEditorAdapter- Editor interaction layer for custom integrationscreateAIProvider(config)- Factory function for creating AI providers- Utilities:
validateInput(),parseJSON(),removeMarkdownCodeBlocks(),generateId()

