@eigenpal/docx-editor-core/types/agentApi
Agent API Types
TypeScript interfaces for the agent API: - Position and Range types - Command types for document manipulation - Context types for AI agents
Functions(7)
comparePositions
Compare two positions Returns: -1 if a b, 0 if equal, 1 if a b
declare function comparePositions(a: Position, b: Position): -1 | 0 | 1;createCollapsedRange
Create a collapsed range (cursor) at a position
declare function createCollapsedRange(position: Position): Range;createCommand
Create a command with generated ID
declare function createCommand<T extends AgentCommand>(command: Omit<T, 'id'>): T;createRange
Create a range from two positions
declare function createRange(start: Position, end: Position): Range;getActionDescription
Get action description
declare function getActionDescription(action: AIAction): string;getActionLabel
Get action label
declare function getActionLabel(action: AIAction): string;isPositionInRange
Check if a position is within a range
declare function isPositionInRange(position: Position, range: Range): boolean;Interfaces(28)
AgentContent
Content block in agent response
interface AgentContent| Member | Type | Summary |
|---|---|---|
| formatting? | Partial<TextFormatting> | Formatting |
| imageSrc? | string | Image src (for image type) |
| paragraphFormatting? | Partial<ParagraphFormatting> | Paragraph formatting |
| tableData? | string[][] | Table data (for table type) |
| text? | string | Text content |
| type | 'text' | 'paragraph' | 'table' | 'image' | Content type |
AgentContext
Document context for AI agents
interface AgentContext| Member | Type | Summary |
|---|---|---|
| availableStyles | StyleInfo[] | Available styles |
| characterCount | number | Total character count |
| hasHyperlinks | boolean | Has hyperlinks |
| hasImages | boolean | Has images |
| hasTables | boolean | Has tables |
| language? | string | Document language |
| outline | ParagraphOutline[] | Content outline (first N chars per paragraph) |
| paragraphCount | number | Total paragraph count |
| sections | SectionInfo[] | Document sections info |
| variableCount | number | Variable count |
| variables | string[] | Detected template variables |
| wordCount | number | Total word count (approximate) |
AgentResponse
Response from an agent action
interface AgentResponse| Member | Type | Summary |
|---|---|---|
| commands? | AgentCommand[] | Commands to execute |
| error? | string | Error message if failed |
| metadata? | Record<string, unknown> | Metadata about the response |
| newContent? | AgentContent[] | New formatted content |
| newText? | string | New text to insert (for rewrite/expand/etc.) |
| success | boolean | Success status |
| warnings? | string[] | Warning messages |
AIActionRequest
AI action request
interface AIActionRequest| Member | Type | Summary |
|---|---|---|
| action | AIAction | Action type |
| context | SelectionContext | Selection context |
| customPrompt? | string | Custom prompt (for 'custom' action) |
| options? | Record<string, unknown> | Additional options |
| targetLanguage? | string | Target language (for 'translate' action) |
ApplyStyleCommand
Apply a named style to a paragraph
interface ApplyStyleCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| paragraphIndex | number | Paragraph index |
| styleId | string | Style ID to apply |
| type | 'applyStyle' |
ApplyVariablesCommand
Apply all template variables
interface ApplyVariablesCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| type | 'applyVariables' | |
| values | Record<string, string> | Variable values |
BaseCommand
Base command interface
interface BaseCommand| Member | Type | Summary |
|---|---|---|
| id? | string | Unique command ID (for undo tracking) |
| type | string | Command type |
DeleteTextCommand
Delete text in a range
interface DeleteTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| range | Range | Range to delete |
| type | 'deleteText' |
FormatParagraphCommand
Apply paragraph formatting
interface FormatParagraphCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| formatting | Partial<ParagraphFormatting> | Formatting to apply |
| paragraphIndex | number | Paragraph index |
| type | 'formatParagraph' |
FormatTextCommand
Apply formatting to a range
interface FormatTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| formatting | Partial<TextFormatting> | Formatting to apply |
| range | Range | Range to format |
| type | 'formatText' |
InsertHyperlinkCommand
Insert a hyperlink at a range
interface InsertHyperlinkCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| displayText? | string | Display text (replaces range text if provided) |
| range | Range | Range to make into a hyperlink |
| tooltip? | string | Tooltip |
| type | 'insertHyperlink' | |
| url | string | URL of the hyperlink |
InsertImageCommand
Insert an image at a position
interface InsertImageCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| alt? | string | Alt text |
| height? | number | Image height in pixels |
| position | Position | Position to insert at |
| src | string | Image source (base64 or URL) |
| type | 'insertImage' | |
| width? | number | Image width in pixels |
InsertParagraphBreakCommand
Insert a paragraph break
interface InsertParagraphBreakCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| position | Position | Position to break at |
| type | 'insertParagraphBreak' |
InsertTableCommand
Insert a table at a position
interface InsertTableCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| columns | number | Number of columns |
| data? | string[][] | Optional table data |
| hasHeader? | boolean | Optional header row |
| position | Position | Position to insert at |
| rows | number | Number of rows |
| type | 'insertTable' |
InsertTextCommand
Insert text at a position
interface InsertTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| formatting? | TextFormatting | Optional formatting for the inserted text |
| position | Position | Position to insert at |
| text | string | Text to insert |
| type | 'insertText' |
MergeParagraphsCommand
Merge paragraphs
interface MergeParagraphsCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| count | number | Number of paragraphs to merge with |
| paragraphIndex | number | First paragraph index |
| type | 'mergeParagraphs' |
ParagraphContext
Paragraph context for selection
interface ParagraphContext| Member | Type | Summary |
|---|---|---|
| fullText | string | Full paragraph text |
| index | number | Paragraph index |
| style? | string | Paragraph style |
| wordCount | number | Word count |
ParagraphOutline
Paragraph outline for context
interface ParagraphOutline| Member | Type | Summary |
|---|---|---|
| headingLevel? | number | Heading level (1-9) |
| index | number | Paragraph index |
| isEmpty? | boolean | Is empty paragraph |
| isHeading? | boolean | Is heading |
| isListItem? | boolean | Is list item |
| preview | string | First N characters |
| style? | string | Paragraph style |
Position_2
Position within a document
interface Position| Member | Type | Summary |
|---|---|---|
| contentIndex? | number | Optional: Content index within paragraph (run, hyperlink, etc.) |
| offset | number | Offset within the paragraph in characters |
| paragraphIndex | number | Index of the paragraph (0-indexed) |
| sectionIndex? | number | Optional: Section index |
Range_2
Range within a document
interface Range| Member | Type | Summary |
|---|---|---|
| collapsed? | boolean | Whether the range is collapsed (cursor position) |
| end | Position | End position |
| start | Position | Start position |
RemoveHyperlinkCommand
Remove a hyperlink but keep the text
interface RemoveHyperlinkCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| range | Range | Range containing the hyperlink |
| type | 'removeHyperlink' |
ReplaceTextCommand
Replace text in a range
interface ReplaceTextCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| formatting? | TextFormatting | Optional formatting for the new text |
| range | Range | Range to replace |
| text | string | Replacement text |
| type | 'replaceText' |
SectionInfo
Section information
interface SectionInfo| Member | Type | Summary |
|---|---|---|
| hasFooter? | boolean | Has footer |
| hasHeader? | boolean | Has header |
| index | number | Section index |
| isLandscape? | boolean | Is landscape |
| pageSize? | {
width: number;
height: number;
} | Page size |
| paragraphCount | number | Number of paragraphs |
SelectionContext
Context about the current selection
interface SelectionContext| Member | Type | Summary |
|---|---|---|
| formatting | Partial<TextFormatting> | Current formatting of selection |
| inHyperlink? | boolean | Is selection within a hyperlink |
| inTable? | boolean | Is selection within a table |
| paragraph | ParagraphContext | Paragraph containing selection |
| paragraphFormatting | Partial<ParagraphFormatting> | Current paragraph formatting |
| range | Range | Selection range |
| selectedText | string | Selected text |
| suggestedActions? | SuggestedAction[] | Suggested actions based on selection |
| textAfter | string | Text after selection (context) |
| textBefore | string | Text before selection (context) |
SetVariableCommand
Set template variable value
interface SetVariableCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| name | string | Variable name |
| type | 'setVariable' | |
| value | string | Variable value |
SplitParagraphCommand
Split a paragraph
interface SplitParagraphCommand extends BaseCommand| Member | Type | Summary |
|---|---|---|
| position | Position | Position to split at |
| type | 'splitParagraph' |
StyleInfo
Style information for context
interface StyleInfo| Member | Type | Summary |
|---|---|---|
| builtIn? | boolean | Is built-in style |
| id | string | Style ID |
| name | string | Display name |
| type | 'paragraph' | 'character' | 'table' | Style type |
SuggestedAction
Suggested action for context menu
interface SuggestedAction| Member | Type | Summary |
|---|---|---|
| description? | string | Description |
| icon? | string | Icon name |
| id | string | Action ID |
| label | string | Display label |
| priority? | number | Priority (higher = more prominent) |
Type aliases(5)
AgentCommand
Union of all command types
type AgentCommand = InsertTextCommand | ReplaceTextCommand | DeleteTextCommand | FormatTextCommand | FormatParagraphCommand | ApplyStyleCommand | InsertTableCommand | InsertImageCommand | InsertHyperlinkCommand | RemoveHyperlinkCommand | InsertParagraphBreakCommand | MergeParagraphsCommand | SplitParagraphCommand | SetVariableCommand | ApplyVariablesCommand;AIAction
AI action types for context menu
type AIAction = 'askAI' | 'rewrite' | 'expand' | 'summarize' | 'translate' | 'explain' | 'fixGrammar' | 'makeFormal' | 'makeCasual' | 'custom';AIRequestHandler
AI request handler function type
type AIRequestHandler = (request: AIActionRequest) => Promise<AgentResponse>;CommandHandler
Command handler function type
type CommandHandler<T extends AgentCommand = AgentCommand> = (command: T) => Promise<boolean>;CommandType
Get command type
type CommandType = AgentCommand['type'];Variables(2)
_default
_default: {
createCollapsedRange: typeof createCollapsedRange;
createRange: typeof createRange;
isPositionInRange: typeof isPositionInRange;
comparePositions: typeof comparePositions;
getActionLabel: typeof getActionLabel;
getActionDescription: typeof getActionDescription;
createCommand: typeof createCommand;
DEFAULT_AI_ACTIONS: AIAction[];
}DEFAULT_AI_ACTIONS
Default AI actions for context menu
DEFAULT_AI_ACTIONS: AIAction[]