@eigenpal/docx-editor-core/agent

Document Agent

Headless, framework-agnostic API for inspecting and editing the Document model. Used by @eigenpal/docx-editor-agents and any adapter that wants agent capabilities without UI.

Functions (50)

addRepeatingSectionItemfunctionSource ↗

Add a new repeating-section item, cloned from an existing one and inserted after it. afterIndex is the item ordinal to clone/insert after (default: the last item). Returns a new [Document](Document).

declare function addRepeatingSectionItem(doc: Document, filter: ContentControlFilter, options?: {
    afterIndex?: number;
}): Document;

buildExtendedSelectionContextfunctionSource ↗

Build extended selection context with additional details

declare function buildExtendedSelectionContext(doc: Document, range: Range, options?: SelectionContextOptions): ExtendedSelectionContext;

buildSelectionContextfunctionSource ↗

Build selection context for AI operations

declare function buildSelectionContext(doc: Document, range: Range, options?: SelectionContextOptions): SelectionContext;

buildSelectionContextFromContextfunction

Build selection context for AI operations

declare function buildSelectionContext$1(doc: Document, range: Range, options?: SelectionContextOptions$1): SelectionContext;

comparePositionsfunctionSource ↗

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;

countCharactersfunctionSource ↗

Count characters in text

declare function countCharacters(text: string, includeSpaces?: boolean): number;

countWordsfunctionSource ↗

Count words in text

declare function countWords(text: string): number;

createAgentfunctionSource ↗

Create a DocumentAgent from a DOCX buffer

declare function createAgent(buffer: ArrayBuffer): Promise<DocumentAgent>;

createAgentFromDocumentfunctionSource ↗

Create a DocumentAgent from a parsed Document

declare function createAgentFromDocument(document: Document): DocumentAgent;

createCollapsedRangefunctionSource ↗

Create a collapsed range (cursor) at a position

declare function createCollapsedRange(position: Position): Range;

createCommandfunctionSource ↗

Create a command with generated ID

declare function createCommand<T extends AgentCommand>(command: Omit<T, 'id'>): T;

createRangefunctionSource ↗

Create a range from two positions

declare function createRange(start: Position, end: Position): Range;

executeCommandfunctionSource ↗

Execute an agent command on a document Returns a new document with the command applied (immutable)

Dispatch order: 1. Try plugin handlers first (allows plugins to override built-in commands) 2. Fall back to built-in handlers

declare function executeCommand(doc: Document, command: AgentCommand): Document;

executeCommandsfunctionSource ↗

Execute multiple commands in sequence

declare function executeCommands(doc: Document, commands: AgentCommand[]): Document;

findContentControlfunctionSource ↗

Convenience: the first control matching filter, or undefined.

declare function findContentControl(input: Document | DocumentBody, filter: ContentControlFilter): ContentControlInfo | undefined;

findContentControlsfunctionSource ↗

Find every block-level content control in the document, optionally filtered by tag/alias/id/type. Results are in document order; nested controls follow their parent. Searches the body and controls nested inside controls. Table cells are not searched (the current model/parser does not surface cell-level controls), and headers/footers live in a separate content tree.

declare function findContentControls(input: Document | DocumentBody, filter?: ContentControlFilter): ContentControlInfo[];

formatSdtDatefunctionSource ↗

Format an ISO date (yyyy-mm-dd) with a subset of OOXML date tokens.

declare function formatSdtDate(iso: string, pattern?: string): string;

getActionDescriptionfunctionSource ↗

Get action description

declare function getActionDescription(action: AIAction): string;

getActionLabelfunctionSource ↗

Get action label

declare function getActionLabel(action: AIAction): string;

getAgentContextfunctionSource ↗

Build agent context from a document

declare function getAgentContext(doc: Document, options?: AgentContextOptions): AgentContext;

getBlockIndexForParagraphfunctionSource ↗

Get block index for a paragraph index

declare function getBlockIndexForParagraph(body: DocumentBody, paragraphIndex: number): number;

getBodyCharacterCountfunctionSource ↗

Get character count from document body

declare function getBodyCharacterCount(body: DocumentBody): number;

getBodyTextfunctionSource ↗

Get plain text from document body

declare function getBodyText(body: DocumentBody): string;

getBodyWordCountfunctionSource ↗

Get word count from document body

declare function getBodyWordCount(body: DocumentBody): number;

getContentControlTextfunctionSource ↗

Plain text of a control's content, descending into tables and nested SDTs.

declare function getContentControlText(control: BlockSdt): string;

getDocumentSummaryfunctionSource ↗

Get a simple document summary for quick context

declare function getDocumentSummary(doc: Document): string;

getFormattingAtPositionfunctionSource ↗

Get formatting at a specific position in a paragraph

declare function getFormattingAtPosition(paragraph: Paragraph, offset: number): Partial<TextFormatting>;

getHyperlinkAtPositionfunctionSource ↗

Get hyperlink at position

declare function getHyperlinkAtPosition(paragraph: Paragraph, offset: number): Hyperlink | undefined;

getHyperlinkTextfunctionSource ↗

Get plain text from a hyperlink

declare function getHyperlinkText(hyperlink: Hyperlink): string;

getParagraphAtIndexfunctionSource ↗

Get paragraph at index from document body

declare function getParagraphAtIndex(body: DocumentBody, index: number): Paragraph | undefined;

getParagraphsfunctionSource ↗

Get all paragraphs from document body

declare function getParagraphs(body: DocumentBody): Paragraph[];

getParagraphTextfunctionSource ↗

Get plain text from a paragraph

declare function getParagraphText(paragraph: Paragraph): string;

getRunTextfunctionSource ↗

Get plain text from a run

declare function getRunText(run: Run): string;

getSelectionFormattingSummaryfunctionSource ↗

Get formatting summary for a selection

declare function getSelectionFormattingSummary(doc: Document, range: Range): FormattingSummary;

getTableTextfunctionSource ↗

Get plain text from a table

declare function getTableText(table: Table): string;

getTextAfterfunctionSource ↗

Get text after a position

declare function getTextAfter(paragraphs: Paragraph[], position: Position, maxChars: number): string;

getTextBeforefunctionSource ↗

Get text before a position

declare function getTextBefore(paragraphs: Paragraph[], position: Position, maxChars: number): string;

Check if document body has hyperlinks

declare function hasHyperlinks(body: DocumentBody): boolean;

hasImagesfunctionSource ↗

Check if document body has images

declare function hasImages(body: DocumentBody): boolean;

hasTablesfunctionSource ↗

Check if document body has tables

declare function hasTables(body: DocumentBody): boolean;

isHeadingStylefunctionSource ↗

Check if style ID represents a heading

declare function isHeadingStyle(styleId?: string): boolean;

Check if position is within a hyperlink

declare function isPositionInHyperlink(paragraph: Paragraph, offset: number): boolean;

isPositionInRangefunctionSource ↗

Check if a position is within a range

declare function isPositionInRange(position: Position, range: Range): boolean;

isRepeatingSectionfunctionSource ↗

The control's raw w:sdtPr declares it a repeating section (the container).

declare function isRepeatingSection(props: SdtProperties): boolean;

isRepeatingSectionItemfunctionSource ↗

The control's raw w:sdtPr declares it a repeating-section item.

declare function isRepeatingSectionItem(props: SdtProperties): boolean;

parseHeadingLevelfunctionSource ↗

Parse heading level from style ID

declare function parseHeadingLevel(styleId?: string): number | undefined;

removeContentControlfunctionSource ↗

Remove the first control matching filter from the document. With keepContent: true the control's blocks are unwrapped in place (the box goes away, the content stays) — useful for "resolve this conditional section into plain content". Otherwise the whole region is deleted.

Unwrapping a repeating-section (item) is refused unless force, since lifting its blocks out would orphan the (w15) repeating structure.

Throws [ContentControlNotFoundError](ContentControlNotFoundError) / [ContentControlLockedError](ContentControlLockedError) as [setContentControlContent](setContentControlContent) does.

declare function removeContentControl(doc: Document, filter: ContentControlFilter, options?: {
    force?: boolean;
    keepContent?: boolean;
}): Document;

removeRepeatingSectionItemfunctionSource ↗

Remove the repeating-section item at ordinal index. Keeps at least one item (Word does not allow removing the last). Returns a new [Document](Document).

declare function removeRepeatingSectionItem(doc: Document, filter: ContentControlFilter, index: number): Document;

setContentControlContentfunctionSource ↗

Replace the content of the first control matching filter. replacement may be a string (split into paragraphs on newlines) or block content. The control's properties, tag/alias, and lossless raw w:sdtPr are preserved — only the contained blocks change, so the result still round-trips.

When the control was showing its placeholder (w:showingPlcHdr), that flag is cleared so Word doesn't render the new content as placeholder text.

Throws [ContentControlNotFoundError](ContentControlNotFoundError) if nothing matches, [ContentControlLockedError](ContentControlLockedError) if the control's lock forbids editing, and [ContentControlTypeError](ContentControlTypeError) if the control is a typed (dropdown/date/…) control whose value shouldn't be set as free text. Pass { force: true } to override the lock/type guards.

declare function setContentControlContent(doc: Document, filter: ContentControlFilter, replacement: string | BlockContent[], options?: {
    force?: boolean;
}): Document;

setContentControlValuefunctionSource ↗

Set a typed value (dropdown selection / checkbox / date) on the first control matching filter, returning a new [Document](Document). Updates both the visible content and the structured raw state, so the result round-trips and Word shows the new value. Throws [ContentControlNotFoundError](ContentControlNotFoundError) if nothing matches, [ContentControlLockedError](ContentControlLockedError) if content-locked, [ContentControlBoundError](ContentControlBoundError) if data-bound (the store would override the write), and [ContentControlValueError](ContentControlValueError) if the value doesn't fit the control type. The lock/bound guards are overridable with { force: true }.

declare function setContentControlValue(doc: Document, filter: ContentControlFilter, value: ContentControlValue, options?: {
    force?: boolean;
}): Document;

Classes (7)

ContentControlBoundErrorclassSource ↗

The control is bound to a Custom XML data store (w:dataBinding). Writing its content won't stick — Word re-renders the control from the bound XML node — so the write is refused. Update the data store instead, or pass { force: true }.

declare class ContentControlBoundError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `ContentControlBoundError` class

ContentControlLockedErrorclassSource ↗

The matched control's lock forbids the attempted edit (pass force to override).

declare class ContentControlLockedError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `ContentControlLockedError` class

ContentControlNotFoundErrorclassSource ↗

No control matched the filter.

declare class ContentControlNotFoundError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `ContentControlNotFoundError` class

ContentControlTypeErrorclassSource ↗

The control's type doesn't support free text/block replacement (e.g. a dropdown, date, checkbox, or picture control), so writing arbitrary content would desync the type marker from its value. Use a type-specific setter, or pass { force: true } to override.

declare class ContentControlTypeError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `ContentControlTypeError` class

ContentControlValueErrorclassSource ↗

The control doesn't support the requested value kind, or the value is invalid.

declare class ContentControlValueError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `ContentControlValueError` class

DocumentAgentclassSource ↗

DocumentAgent provides a fluent API for document manipulation

declare class DocumentAgent
```ts
const agent = new DocumentAgent(buffer);

// Read operations
const text = agent.getText();
const wordCount = agent.getWordCount();
const variables = agent.getVariables();

// Write operations (returns new agent)
const newAgent = agent
  .insertText({ paragraphIndex: 0, offset: 0 }, 'Hello ', { formatting: { bold: true } })
  .applyStyle({ paragraphIndex: 0, offset: 0 }, { paragraphIndex: 0, offset: 5 }, 'Heading1');

// Export
const newBuffer = await newAgent.toBuffer();
```
MemberTypeSummary
(constructor)Create a new DocumentAgent
applyFormattingApply text formatting to a range
applyParagraphFormattingApply paragraph formatting
applyStyleApply a named style to a paragraph
applyVariablesApply all pending template variables
clearPendingVariablesClear pending variables
deleteRangeDelete text in a range
executeCommandsExecute multiple commands in sequence
fromBufferCreate a DocumentAgent from a DOCX buffer (async)
fromDocumentCreate a DocumentAgent from a Document object
getAgentContextGet document context for AI agents
getCharacterCountGet character count
getDocumentGet the underlying document
getFormattedTextGet formatted text segments
getPageCountGet approximate page count
getParagraphCountGet paragraph count
getPendingVariablesGet pending variable values
getStylesGet available styles from the document
getTableCountGet table count
getTextGet plain text content of the document
getVariablesGet detected template variables
getWordCountGet word count
insertImageInsert an image at a position
insertParagraphBreakInsert a paragraph break
insertTableInsert a table at a position
insertTextInsert text at a position
mergeParagraphsMerge consecutive paragraphs
replaceRangeReplace text in a range
setVariableSet a template variable value
setVariablesSet multiple template variables
toBlobExport document to Blob
toBufferExport document to DOCX ArrayBuffer

RepeatingSectionErrorclassSource ↗

Raised when an operation targets something that isn't a repeating section/item.

declare class RepeatingSectionError extends Error
MemberTypeSummary
(constructor)Constructs a new instance of the `RepeatingSectionError` class

Interfaces (38)

AgentContextinterfaceSource ↗

Document context for AI agents

interface AgentContext
MemberTypeSummary
availableStylesStyleInfo[]Available styles
characterCountnumberTotal character count
hasImagesbooleanHas images
hasTablesbooleanHas tables
language?stringDocument language
outlineParagraphOutline[]Content outline (first N chars per paragraph)
paragraphCountnumberTotal paragraph count
sectionsSectionInfo[]Document sections info
variableCountnumberVariable count
variablesstring[]Detected template variables
wordCountnumberTotal word count (approximate)

AgentContextOptionsinterfaceSource ↗

Options for building agent context

interface AgentContextOptions
MemberTypeSummary
includeFormatting?booleanInclude detailed formatting info (default: false)
includeTableContent?booleanInclude table content in context (default: false)
maxOutlineParagraphs?numberMaximum paragraphs to include in outline (default: 50)
outlineMaxChars?numberMaximum characters per paragraph in outline (default: 100)

AgentResponseinterfaceSource ↗

Response from an agent action

interface AgentResponse
MemberTypeSummary
commands?AgentCommand[]Commands to execute
error?stringError message if failed
metadata?Record<string, unknown>Metadata about the response
newContent?AgentContent[]New formatted content
newText?stringNew text to insert (for rewrite/expand/etc.)
successbooleanSuccess status
warnings?string[]Warning messages

AgentSelectionContextinterface

Context about the current selection

interface SelectionContext
MemberTypeSummary
formattingPartial<TextFormatting>Current formatting of selection
inTable?booleanIs selection within a table
paragraphParagraphContextParagraph containing selection
paragraphFormattingPartial<ParagraphFormatting>Current paragraph formatting
rangeRangeSelection range
selectedTextstringSelected text
suggestedActions?SuggestedAction[]Suggested actions based on selection
textAfterstringText after selection (context)
textBeforestringText before selection (context)

AIActionRequestinterfaceSource ↗

AI action request

interface AIActionRequest
MemberTypeSummary
actionAIActionAction type
contextSelectionContextSelection context
customPrompt?stringCustom prompt (for 'custom' action)
options?Record<string, unknown>Additional options
targetLanguage?stringTarget language (for 'translate' action)

ApplyStyleCommandinterfaceSource ↗

Apply a named style to a paragraph

interface ApplyStyleCommand extends BaseCommand
MemberTypeSummary
paragraphIndexnumberParagraph index
styleIdstringStyle ID to apply
type'applyStyle'

ApplyVariablesCommandinterfaceSource ↗

Apply all template variables

interface ApplyVariablesCommand extends BaseCommand
MemberTypeSummary
type'applyVariables'
valuesRecord<string, string>Variable values

ContentControlFilterinterfaceSource ↗

Filter for [findContentControls](findContentControls). All provided fields must match (AND).

interface ContentControlFilter
MemberTypeSummary
alias?stringFriendly name (`w:alias`), exact match.
id?numberNumeric id (`w:id`), exact match.
tag?stringDeveloper identifier (`w:tag`), exact match.
type?SdtTypeControl type projection (`richText`, `dropDownList`, …).

ContentControlInfointerfaceSource ↗

A discovered content control plus enough context to address and edit it.

interface ContentControlInfo
MemberTypeSummary
alias?stringFriendly name (`w:alias`).
checked?booleanCheckbox state, for checkbox controls.
dataBinding?SdtDataBindingXML data binding (`w:dataBinding`), if the control is bound.
dateFormat?stringDate format string, for date controls.
depthnumberNesting depth (0 = direct child of the body).
id?numberNumeric id (`w:id`).
listItems?{ displayText: string; value: string; }[]Dropdown/combobox list items, if modeled.
lock?SdtProperties['lock']Lock setting, if any. A locked control should refuse content edits.
pathnumber[]Block-index path from the document body to this control. Top-level controls are `[i]`; a control nested inside the i-th body block's content is `[i, j]`, and so on. Stable address for a follow-up edit.
placeholder?stringPlaceholder docPart reference, if any.
sdtTypeSdtTypeControl type projection.
showingPlaceholder?booleanWhether the control is currently showing placeholder text (`w:showingPlcHdr`).
tag?stringDeveloper identifier (`w:tag`).
textstringPlain text of the control's content (paragraphs/tables/nested controls flattened).

ContextSelectionOptionsinterface

Options for building selection context

interface SelectionContextOptions$1
MemberTypeSummary
contextChars?numberCharacters of context before/after selection (default: 200)
includeSuggestions?booleanInclude suggested actions (default: true)

DeleteTextCommandinterfaceSource ↗

Delete text in a range

interface DeleteTextCommand extends BaseCommand
MemberTypeSummary
rangeRangeRange to delete
type'deleteText'

ExtendedSelectionContextinterfaceSource ↗

Extended selection context with additional details

interface ExtendedSelectionContext extends SelectionContext
MemberTypeSummary
characterCount?numberSelection character count
contentType?'prose' | 'list' | 'heading' | 'table' | 'mixed'Content type hints
detectedLanguage?stringLanguage detection hint
documentSummary?stringDocument summary for additional context
isMultiParagraph?booleanIs selection multi-paragraph
paragraphIndices?number[]Selected paragraph indices
wordCount?numberSelection word count

FormatParagraphCommandinterfaceSource ↗

Apply paragraph formatting

interface FormatParagraphCommand extends BaseCommand
MemberTypeSummary
formattingPartial<ParagraphFormatting>Formatting to apply
paragraphIndexnumberParagraph index
type'formatParagraph'

FormattedTextSegmentinterfaceSource ↗

Formatted text segment

interface FormattedTextSegment
MemberTypeSummary
formatting?TextFormattingApplied formatting
hyperlinkUrl?stringHyperlink URL if applicable
textstringText content

FormatTextCommandinterfaceSource ↗

Apply formatting to a range

interface FormatTextCommand extends BaseCommand
MemberTypeSummary
formattingPartial<TextFormatting>Formatting to apply
rangeRangeRange to format
type'formatText'

FormattingSummaryinterfaceSource ↗

Selection formatting summary

interface FormattingSummary
MemberTypeSummary
allFormattingPartial<TextFormatting>[]All formatting found
isConsistentbooleanIs formatting consistent across selection
predominantPartial<TextFormatting>Predominant formatting

InsertHyperlinkCommandinterfaceSource ↗

Insert a hyperlink at a range

interface InsertHyperlinkCommand extends BaseCommand
MemberTypeSummary
displayText?stringDisplay text (replaces range text if provided)
rangeRangeRange to make into a hyperlink
tooltip?stringTooltip
type'insertHyperlink'
urlstringURL of the hyperlink

InsertHyperlinkOptionsinterfaceSource ↗

Options for inserting hyperlink

interface InsertHyperlinkOptions
MemberTypeSummary
displayText?stringDisplay text (overrides selected text)
tooltip?stringTooltip on hover

InsertImageCommandinterfaceSource ↗

Insert an image at a position

interface InsertImageCommand extends BaseCommand
MemberTypeSummary
alt?stringAlt text
height?numberImage height in pixels
positionPositionPosition to insert at
srcstringImage source (base64 or URL)
type'insertImage'
width?numberImage width in pixels

InsertImageOptionsinterfaceSource ↗

Options for inserting image

interface InsertImageOptions
MemberTypeSummary
alt?stringAlt text for accessibility
height?numberImage height in pixels
width?numberImage width in pixels

InsertParagraphBreakCommandinterfaceSource ↗

Insert a paragraph break

interface InsertParagraphBreakCommand extends BaseCommand
MemberTypeSummary
positionPositionPosition to break at
type'insertParagraphBreak'

InsertTableCommandinterfaceSource ↗

Insert a table at a position

interface InsertTableCommand extends BaseCommand
MemberTypeSummary
columnsnumberNumber of columns
data?string[][]Optional table data
hasHeader?booleanOptional header row
positionPositionPosition to insert at
rowsnumberNumber of rows
type'insertTable'

InsertTableOptionsinterfaceSource ↗

Options for inserting table

interface InsertTableOptions
MemberTypeSummary
data?string[][]Table data (2D array of strings)
hasHeader?booleanWhether first row is a header

InsertTextCommandinterfaceSource ↗

Insert text at a position

interface InsertTextCommand extends BaseCommand
MemberTypeSummary
formatting?TextFormattingOptional formatting for the inserted text
positionPositionPosition to insert at
textstringText to insert
type'insertText'

InsertTextOptionsinterfaceSource ↗

Options for inserting text

interface InsertTextOptions
MemberTypeSummary
formatting?TextFormattingText formatting

MergeParagraphsCommandinterfaceSource ↗

Merge paragraphs

interface MergeParagraphsCommand extends BaseCommand
MemberTypeSummary
countnumberNumber of paragraphs to merge with
paragraphIndexnumberFirst paragraph index
type'mergeParagraphs'

ParagraphContextinterfaceSource ↗

Paragraph context for selection

interface ParagraphContext
MemberTypeSummary
fullTextstringFull paragraph text
indexnumberParagraph index
style?stringParagraph style
wordCountnumberWord count

ParagraphOutlineinterfaceSource ↗

Paragraph outline for context

interface ParagraphOutline
MemberTypeSummary
headingLevel?numberHeading level (1-9)
indexnumberParagraph index
isEmpty?booleanIs empty paragraph
isHeading?booleanIs heading
isListItem?booleanIs list item
previewstringFirst N characters
style?stringParagraph style

Position_2interface

Position within a document

interface Position
MemberTypeSummary
contentIndex?numberOptional: Content index within paragraph (run, hyperlink, etc.)
offsetnumberOffset within the paragraph in characters
paragraphIndexnumberIndex of the paragraph (0-indexed)
sectionIndex?numberOptional: Section index

Range_2interface

Range within a document

interface Range
MemberTypeSummary
collapsed?booleanWhether the range is collapsed (cursor position)
endPositionEnd position
startPositionStart position

RemoveHyperlinkCommandinterfaceSource ↗

Remove a hyperlink but keep the text

interface RemoveHyperlinkCommand extends BaseCommand
MemberTypeSummary
rangeRangeRange containing the hyperlink
type'removeHyperlink'

ReplaceTextCommandinterfaceSource ↗

Replace text in a range

interface ReplaceTextCommand extends BaseCommand
MemberTypeSummary
formatting?TextFormattingOptional formatting for the new text
rangeRangeRange to replace
textstringReplacement text
type'replaceText'

SectionInfointerfaceSource ↗

Section information

interface SectionInfo
MemberTypeSummary
hasFooter?booleanHas footer
hasHeader?booleanHas header
indexnumberSection index
isLandscape?booleanIs landscape
pageSize?{ width: number; height: number; }Page size
paragraphCountnumberNumber of paragraphs

SelectionContextOptionsinterfaceSource ↗

Options for building selection context

interface SelectionContextOptions
MemberTypeSummary
contextCharsAfter?numberCharacters of context after selection (default: 200)
contextCharsBefore?numberCharacters of context before selection (default: 200)
includeDocumentSummary?booleanInclude document summary (default: true)
includeSuggestions?booleanInclude suggested actions (default: true)
maxSuggestions?numberMaximum suggested actions (default: 8)

SetVariableCommandinterfaceSource ↗

Set template variable value

interface SetVariableCommand extends BaseCommand
MemberTypeSummary
namestringVariable name
type'setVariable'
valuestringVariable value

SplitParagraphCommandinterfaceSource ↗

Split a paragraph

interface SplitParagraphCommand extends BaseCommand
MemberTypeSummary
positionPositionPosition to split at
type'splitParagraph'

StyleInfointerfaceSource ↗

Style information for context

interface StyleInfo
MemberTypeSummary
builtIn?booleanIs built-in style
idstringStyle ID
namestringDisplay name
type'paragraph' | 'character' | 'table'Style type

SuggestedActioninterfaceSource ↗

Suggested action for context menu

interface SuggestedAction
MemberTypeSummary
description?stringDescription
icon?stringIcon name
idstringAction ID
labelstringDisplay label
priority?numberPriority (higher = more prominent)

Type aliases (3)

AgentCommandtypeSource ↗

Union of all command types

type AgentCommand = InsertTextCommand | ReplaceTextCommand | DeleteTextCommand | FormatTextCommand | FormatParagraphCommand | ApplyStyleCommand | InsertTableCommand | InsertImageCommand | InsertHyperlinkCommand | RemoveHyperlinkCommand | InsertParagraphBreakCommand | MergeParagraphsCommand | SplitParagraphCommand | SetVariableCommand | ApplyVariablesCommand;

AIActiontypeSource ↗

AI action types for context menu

type AIAction = 'askAI' | 'rewrite' | 'expand' | 'summarize' | 'translate' | 'explain' | 'fixGrammar' | 'makeFormal' | 'makeCasual' | 'custom';

ContentControlValuetypeSource ↗

A typed value to apply to a content control.

type ContentControlValue = {
    kind: 'dropdown';
    value: string;
} | {
    kind: 'checkbox';
    checked: boolean;
} | {
    kind: 'date';
    date: string;
};

Variables (1)

DEFAULT_AI_ACTIONSconstSource ↗

Default AI actions for context menu

DEFAULT_AI_ACTIONS: AIAction[]

On this page

FunctionsaddRepeatingSectionItembuildExtendedSelectionContextbuildSelectionContextbuildSelectionContextFromContextcomparePositionscountCharacterscountWordscreateAgentcreateAgentFromDocumentcreateCollapsedRangecreateCommandcreateRangeexecuteCommandexecuteCommandsfindContentControlfindContentControlsformatSdtDategetActionDescriptiongetActionLabelgetAgentContextgetBlockIndexForParagraphgetBodyCharacterCountgetBodyTextgetBodyWordCountgetContentControlTextgetDocumentSummarygetFormattingAtPositiongetHyperlinkAtPositiongetHyperlinkTextgetParagraphAtIndexgetParagraphsgetParagraphTextgetRunTextgetSelectionFormattingSummarygetTableTextgetTextAftergetTextBeforehasHyperlinkshasImageshasTablesisHeadingStyleisPositionInHyperlinkisPositionInRangeisRepeatingSectionisRepeatingSectionItemparseHeadingLevelremoveContentControlremoveRepeatingSectionItemsetContentControlContentsetContentControlValueClassesContentControlBoundErrorContentControlLockedErrorContentControlNotFoundErrorContentControlTypeErrorContentControlValueErrorDocumentAgentRepeatingSectionErrorInterfacesAgentContextAgentContextOptionsAgentResponseAgentSelectionContextAIActionRequestApplyStyleCommandApplyVariablesCommandContentControlFilterContentControlInfoContextSelectionOptionsDeleteTextCommandExtendedSelectionContextFormatParagraphCommandFormattedTextSegmentFormatTextCommandFormattingSummaryInsertHyperlinkCommandInsertHyperlinkOptionsInsertImageCommandInsertImageOptionsInsertParagraphBreakCommandInsertTableCommandInsertTableOptionsInsertTextCommandInsertTextOptionsMergeParagraphsCommandParagraphContextParagraphOutlinePosition_2Range_2RemoveHyperlinkCommandReplaceTextCommandSectionInfoSelectionContextOptionsSetVariableCommandSplitParagraphCommandStyleInfoSuggestedActionType aliasesAgentCommandAIActionContentControlValueVariablesDEFAULT_AI_ACTIONS