docxodus 6.0.0 → 6.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/types.d.ts CHANGED
@@ -58,6 +58,45 @@ export declare enum EmptyParagraphMode {
58
58
  /** Skip empty paragraphs entirely — they don't appear in the markdown or the anchor index. */
59
59
  Suppress = 2
60
60
  }
61
+ /**
62
+ * How anchor ids are rendered inside `{#…}` tokens (and keyed in
63
+ * {@link MarkdownProjection.anchorIndex}). Mirrors the .NET
64
+ * `Docxodus.AnchorIdRendering` enum.
65
+ *
66
+ * `Anchor.token` (and any `AnchorRef` returned by `DocxSession` mutations)
67
+ * always carries the full Unid regardless of rendering — the choice only
68
+ * affects the markdown text. The returned `anchorIndex` is dual-keyed so
69
+ * lookups by either the rendered id or the full Unid work for the
70
+ * `Abbreviated`/`Sequential` modes.
71
+ */
72
+ export declare enum AnchorIdRendering {
73
+ /** Full 32-char hex Unid (default; e.g. `{#h:body:a1b2c3d4e5f6789012345678901234ab}`). */
74
+ FullUnid = 0,
75
+ /** Shortest unique prefix per (kind, scope) bucket, 4-char floor (e.g. `{#h:body:a1b2}`).
76
+ * Saves 5-10% of projection-token budget for LLM consumption. */
77
+ Abbreviated = 1,
78
+ /** Sequential numeric ids per (kind, scope) bucket in document order (e.g. `{#h:body:1}`).
79
+ * Maximally token-efficient for one-shot LLM contexts. NOT stable across
80
+ * `project()` calls and must NOT be persisted. */
81
+ Sequential = 2
82
+ }
83
+ /**
84
+ * How far below the target anchor to include in
85
+ * {@link DocxSession.projectAnchor}. Mirrors the .NET
86
+ * `Docxodus.ProjectionDepth` enum.
87
+ */
88
+ export declare enum ProjectionDepth {
89
+ /** Just the target block itself (its anchor + its own text). For headings,
90
+ * returns only the heading paragraph, not the section under it. */
91
+ SelfOnly = 0,
92
+ /** Self + descendants. Most useful for `tbl` anchors (returns the whole table);
93
+ * for paragraphs it's the same as `SelfOnly`. */
94
+ Subtree = 1,
95
+ /** Self + descendants + following siblings up to (but not including) the next
96
+ * sibling at the same or higher heading level. For non-heading anchors,
97
+ * equivalent to `Subtree`. Dominant "give me this section" case; the default. */
98
+ SubtreeAndFollowingSiblings = 2
99
+ }
61
100
  /**
62
101
  * Settings controlling the markdown projection. Mirrors the .NET
63
102
  * `WmlToMarkdownConverterSettings` class — see `docs/architecture/markdown_projection.md`.
@@ -71,6 +110,16 @@ export interface MarkdownProjectionSettings {
71
110
  trackedChanges?: TrackedChangeMode;
72
111
  resolveNumbering?: boolean;
73
112
  emptyParagraphs?: EmptyParagraphMode;
113
+ /**
114
+ * How anchor ids are rendered in markdown output. Default `FullUnid`.
115
+ * Set to `Abbreviated` for terse LLM-friendly ids; `Sequential` for
116
+ * 1-based per-scope counters (best for replay logs / human review).
117
+ * `Anchor.token` (and any `AnchorRef`) always reflects the full Unid
118
+ * regardless; this only affects the markdown text. Use the returned
119
+ * {@link MarkdownProjection.anchorIndex} (dual-keyed for Abbreviated /
120
+ * Sequential) to translate rendered ids back to full Unids.
121
+ */
122
+ anchorIdRendering?: AnchorIdRendering;
74
123
  }
75
124
  /**
76
125
  * Resolved location of an anchor in the underlying OOXML package — sufficient to walk
@@ -82,6 +131,14 @@ export interface MarkdownAnchorTarget {
82
131
  scope: string;
83
132
  unid: string;
84
133
  partUri: string;
134
+ /** First ~80 characters of the element's flat text — for previewing/picking anchors. */
135
+ textPreview: string;
136
+ /** Resolved auto-numbering prefix (e.g. "1.", "First") for paragraphs/headings/list
137
+ * items whose style or `w:numPr` produces numbering. Absent when the element has
138
+ * no numbering. The prefix is NOT included in {@link textPreview} because
139
+ * textPreview reflects only the run text; this field gives callers the value
140
+ * Word actually renders before the element's text. */
141
+ autoNumberPrefix?: string;
85
142
  }
86
143
  /**
87
144
  * Output of the markdown projection: rendered text plus the anchor index mapping
@@ -460,6 +517,12 @@ export interface DocxodusWasmExports {
460
517
  GenerateAnnotationCss: (labelsJson: string, extAnnotCssClassPrefix: string, extAnnotLabelMode: number) => string;
461
518
  };
462
519
  DocumentComparer: {
520
+ /**
521
+ * Force the comparison code path hot by running a real comparison against
522
+ * tiny in-memory seed documents. Returns "ok" or a JSON error object.
523
+ * Idempotent — assemblies load only once.
524
+ */
525
+ Warmup: () => string;
463
526
  CompareDocuments: (originalBytes: Uint8Array, modifiedBytes: Uint8Array, authorName: string) => Uint8Array;
464
527
  CompareDocumentsToHtml: (originalBytes: Uint8Array, modifiedBytes: Uint8Array, authorName: string) => string;
465
528
  CompareDocumentsToHtmlWithOptions: (originalBytes: Uint8Array, modifiedBytes: Uint8Array, authorName: string, renderTrackedChanges: boolean) => string;
@@ -474,8 +537,11 @@ export interface DocxodusWasmExports {
474
537
  OpenSession: (bytes: Uint8Array, settingsJson: string) => number;
475
538
  CloseSession: (handle: number) => void;
476
539
  Project: (handle: number) => string;
540
+ ProjectAnchor: (handle: number, anchorId: string, depth: number) => string;
477
541
  ReplaceText: (handle: number, anchor: string, md: string) => string;
478
542
  DeleteBlock: (handle: number, anchor: string) => string;
543
+ DeleteRange: (handle: number, fromAnchorId: string, toAnchorIdExclusive: string) => string;
544
+ DeleteSection: (handle: number, headingAnchorId: string) => string;
479
545
  InsertParagraph: (handle: number, anchor: string, pos: string, md: string) => string;
480
546
  SplitParagraph: (handle: number, anchor: string, offset: number) => string;
481
547
  MergeParagraphs: (handle: number, first: string, second: string) => string;
@@ -492,11 +558,25 @@ export interface DocxodusWasmExports {
492
558
  GrepCrossBlock: (handle: number, pattern: string, optionsJson: string) => string;
493
559
  ReplaceTextRange: (handle: number, anchor: string, find: string, replace: string, optionsJson: string) => string;
494
560
  ReplaceTextAtSpan: (handle: number, anchor: string, spanStart: number, spanLength: number, replace: string) => string;
495
- FindPlaceholders: (handle: number, kinds: number, scope: number) => string;
561
+ ReplaceInner: (handle: number, matchText: string, anchor: string, spanStart: number, spanLength: number, newInner: string) => string;
562
+ FindPlaceholders: (handle: number, kinds: number, scope: number, contextChars: number, boundary: number) => string;
563
+ GetEditSummary: (handle: number) => string;
564
+ RemainingPlaceholders: (handle: number, kinds: number) => string;
565
+ GetDiff: (handle: number, format: number) => string;
496
566
  FindByAnnotation: (handle: number, annotationId: string) => string;
497
567
  FindByLabel: (handle: number, labelId: string) => string;
498
568
  FindByBookmark: (handle: number, bookmarkName: string) => string;
569
+ GetAnchorInfo: (handle: number, anchorId: string) => string;
570
+ GetAnchorInfos: (handle: number, anchorIdsJson: string) => string;
571
+ GetBlockMetadata: (handle: number, anchorId: string) => string;
572
+ GetBlockMetadatas: (handle: number, anchorIdsJson: string) => string;
573
+ GetListMembership: (handle: number, anchorId: string) => string;
574
+ GetSectionInfo: (handle: number, anchorId: string) => string;
499
575
  ListAnnotations: (handle: number) => string;
576
+ AddAnnotation: (handle: number, anchorId: string, spanJson: string, annotationJson: string) => string;
577
+ SessionRemoveAnnotation: (handle: number, annotationId: string) => string;
578
+ UpdateAnnotation: (handle: number, annotationId: string, updateJson: string) => string;
579
+ MoveAnnotation: (handle: number, annotationId: string, newAnchorId: string, newSpanJson: string) => string;
500
580
  Undo: (handle: number) => boolean;
501
581
  Redo: (handle: number) => boolean;
502
582
  Save: (handle: number) => Uint8Array;
@@ -559,6 +639,12 @@ export interface DocxSessionSettings {
559
639
  * straight-quoted text adjacent to surrounding already-curly text. Default false.
560
640
  */
561
641
  smartQuotes?: boolean;
642
+ /**
643
+ * When `true` (default), the session projects the document at construction
644
+ * time so {@link DocxSession.getDiff} can compare initial vs. current.
645
+ * Set to `false` to skip the ~200ms upfront cost if you don't plan to diff.
646
+ */
647
+ captureInitialProjection?: boolean;
562
648
  }
563
649
  export interface DocxSessionProjection {
564
650
  markdown: string;
@@ -567,6 +653,7 @@ export interface DocxSessionProjection {
567
653
  unid: string;
568
654
  kind: string;
569
655
  scope: string;
656
+ textPreview: string;
570
657
  }>;
571
658
  }
572
659
  /**
@@ -665,11 +752,132 @@ export declare const PlaceholderKinds: {
665
752
  readonly Instruction: 4;
666
753
  readonly All: 7;
667
754
  };
755
+ /**
756
+ * Numeric flag layout matching the .NET `DiffFormat` enum. Use with
757
+ * {@link DocxSession.getDiff}.
758
+ *
759
+ * - `Json` (default) — anchor-keyed structured diff. Returns a `DiffEntry[]`.
760
+ * - `Unified` — `patch(1)`-compatible unified diff over the markdown projection.
761
+ * Returns a single string (`""` when nothing changed).
762
+ * - `SideBySide` — two-column human-review diff (`diff -y` style) over the
763
+ * markdown projection. Returns a single string.
764
+ */
765
+ export declare const DiffFormat: {
766
+ readonly Json: 0;
767
+ readonly Unified: 1;
768
+ readonly SideBySide: 2;
769
+ };
770
+ /**
771
+ * A single anchor-keyed change in the diff between an initial and current projection.
772
+ */
773
+ export interface DiffEntry {
774
+ op: "delete" | "insert" | "modify";
775
+ anchorId: string;
776
+ /** Pre-change text content for delete/modify; absent for insert. */
777
+ before?: string;
778
+ /** Post-change text content for insert/modify; absent for delete. */
779
+ after?: string;
780
+ }
781
+ /**
782
+ * Aggregate snapshot of edit-state introspection signals returned by
783
+ * {@link DocxSession.getEditSummary}.
784
+ */
785
+ export interface EditSummary {
786
+ totalAnchors: number;
787
+ remainingPlaceholders: TemplatePlaceholder[];
788
+ bareUnderscoreRuns: TextMatch[];
789
+ footnoteCount: number;
790
+ inlineFootnoteRefCount: number;
791
+ commentCount: number;
792
+ }
793
+ /**
794
+ * Numeric flag layout matching the .NET `ContextBoundary` enum. Controls
795
+ * how `Grep` / `GrepCrossBlock` / `FindPlaceholders` decide where to stop
796
+ * walking outward when computing `TextMatch.contextBefore` / `contextAfter`.
797
+ *
798
+ * - `Char` (default) — truncate at `contextChars`. Matches legacy behavior.
799
+ * - `Bracket` — stop at `[` or `]`. Use for template fills: each placeholder's
800
+ * context is unambiguously its own even when multiple placeholders crowd
801
+ * into one sentence.
802
+ * - `Sentence` — stop at `.`, `!`, `?`, `:`, `;`.
803
+ * - `Comma` — stop at `,`. For matches inside enumerations.
804
+ */
805
+ export declare const ContextBoundary: {
806
+ readonly Char: 0;
807
+ readonly Bracket: 1;
808
+ readonly Sentence: 2;
809
+ readonly Comma: 3;
810
+ };
668
811
  export interface TemplatePlaceholder {
669
812
  kind: PlaceholderKind;
670
813
  /** For `instruction` placeholders: the inner text with surrounding brackets/asterisks stripped. */
671
814
  hint?: string;
672
815
  match: TextMatch;
816
+ /**
817
+ * Additional plausible classifications when the primary `kind` is borderline.
818
+ * Empty by default. The classic case is a long bracketed clause that happens
819
+ * to contain a `_______` blank: primary `kind` stays `"blank_fill"`
820
+ * (back-compat) and `alternativeKinds` contains `"alternative_clause"`.
821
+ */
822
+ alternativeKinds: PlaceholderKind[];
823
+ }
824
+ /**
825
+ * Options for {@link DocxSession.fillPlaceholders}.
826
+ */
827
+ export interface FillOptions {
828
+ /** Which placeholder kinds to fill. Defaults to `PlaceholderKinds.All` so the
829
+ * picker is invoked for every kind in the doc. Narrow with e.g.
830
+ * `PlaceholderKinds.BlankFill | PlaceholderKinds.Instruction` to ignore
831
+ * bracketed alternative clauses. */
832
+ kinds?: number;
833
+ /** Which package parts to scan. Defaults to body (1). */
834
+ scope?: number;
835
+ /** Max iteration passes for multi-pass nested-bracket scenarios. Default 8. */
836
+ maxPasses?: number;
837
+ /** When the match starts with `$` and the picker's return value doesn't,
838
+ * preserve the `$` by prepending it. Default true. */
839
+ preserveDollarPrefix?: boolean;
840
+ /** Cap on `contextBefore` / `contextAfter` length on each side. Default 80. */
841
+ contextChars?: number;
842
+ /** Where to stop walking outward when computing context. Numeric layout
843
+ * matching {@link ContextBoundary}. Default `Char` (0). */
844
+ boundary?: number;
845
+ /** When the picker returns an empty string (and after `$`-prefix preservation
846
+ * has been applied), look at the chars immediately adjacent to the placeholder
847
+ * span and absorb surrounding whitespace / leading-space-before-punctuation /
848
+ * matched-brackets so the dropped placeholder doesn't leave cosmetic
849
+ * artifacts. Default `false` (preserve the literal-delete behavior).
850
+ *
851
+ * Rules: whitespace on both sides collapses to one space; whitespace before
852
+ * and clause-terminating punctuation (`. , ; : ! ?`) after drops the leading
853
+ * space; matched open/close brackets (`()` `[]` `{}`) on either side drop
854
+ * both. NBSP / narrow NBSP / thin space are treated as whitespace.
855
+ *
856
+ * Caveat: `$`-prefix preservation runs first, so a picker returning `""` for
857
+ * `$[xxx]` with `preserveDollarPrefix: true` (default) ends up replacing with
858
+ * `"$"` and coalescing is skipped. Set `preserveDollarPrefix: false` when you
859
+ * want the `$` to drop along with the brackets. */
860
+ coalesceWhitespaceAroundEmptyFill?: boolean;
861
+ }
862
+ /**
863
+ * Aggregate result returned by {@link DocxSession.fillPlaceholders}.
864
+ *
865
+ * `skipped` counts placeholders the picker returned null for in the first pass
866
+ * that saw them — it stays > 0 even if later passes finished those same
867
+ * placeholders. Use `stillPresent` (post-loop document state) for the
868
+ * trustworthy "is the template done?" check; `skipped > 0 && stillPresent === 0`
869
+ * means "picker said no the first time but later passes resolved it."
870
+ */
871
+ export interface BulkEditResult {
872
+ filled: number;
873
+ skipped: number;
874
+ /** Number of placeholders matching `options.kinds` in `options.scope` that
875
+ * remain in the document after the final pass. `0` means the template is
876
+ * fully filled for the requested kinds/scope. */
877
+ stillPresent: number;
878
+ passes: number;
879
+ unfilled: TemplatePlaceholder[];
880
+ errors: EditError[];
673
881
  }
674
882
  /**
675
883
  * Options for {@link DocxSession.grep}.
@@ -692,6 +900,13 @@ export interface GrepOptions {
692
900
  * - 1 = Normalize (fold NBSP / narrow-NBSP / thin-space to ASCII space before matching)
693
901
  */
694
902
  whitespace?: number;
903
+ /**
904
+ * Where to stop walking outward when computing `TextMatch.contextBefore` /
905
+ * `contextAfter`. Numeric layout matching the .NET `ContextBoundary` enum;
906
+ * use the {@link ContextBoundary} const. Default `Char` (0) — truncate at
907
+ * `contextChars`.
908
+ */
909
+ boundary?: number;
695
910
  }
696
911
  /**
697
912
  * Resolved location of an anchor — what {@link DocxSession.findByAnnotation} and
@@ -701,13 +916,85 @@ export interface GrepOptions {
701
916
  */
702
917
  export interface AnchorTargetRef extends AnchorRef {
703
918
  partUri: string;
919
+ /** First ~80 characters of the element's flat text — for previewing/picking anchors. */
920
+ textPreview: string;
921
+ /** Resolved auto-numbering prefix (e.g. "1.", "First") when the element carries
922
+ * numbering. Absent otherwise. See {@link MarkdownAnchorTarget.autoNumberPrefix}. */
923
+ autoNumberPrefix?: string;
924
+ }
925
+ /**
926
+ * The shape returned by {@link DocxSession.getAnchorInfo}.
927
+ * Use {@link MarkdownAnchorTarget} when iterating a full projection — it
928
+ * includes the same fields plus `unid` and `partUri`.
929
+ */
930
+ export interface AnchorInfo {
931
+ id: string;
932
+ kind: string;
933
+ scope: string;
934
+ textPreview: string;
935
+ /** Resolved auto-numbering prefix (e.g. "1.", "First") when the element carries
936
+ * numbering. Absent for un-numbered paragraphs or non-paragraph kinds. */
937
+ autoNumberPrefix?: string;
938
+ }
939
+ /** Six list formats supported by the list write surface (decimal, upperLetter,
940
+ * lowerLetter, upperRoman, lowerRoman, bullet). Surfaced on
941
+ * {@link ListMembership.format} as a string union (mirrors the JSON wire format). */
942
+ export type NumberFormat = "decimal" | "upperLetter" | "lowerLetter" | "upperRoman" | "lowerRoman" | "bullet";
943
+ /** Numbering facts for a list-item paragraph. Returned by
944
+ * {@link DocxSession.getListMembership} and surfaced as {@link BlockMetadata.list}. */
945
+ export interface ListMembership {
946
+ /** The w:numId the paragraph belongs to (the w:num instance). */
947
+ numId: number;
948
+ /** The w:abstractNumId the paragraph's w:num points at. */
949
+ abstractNumId: number;
950
+ /** The paragraph's level (w:ilvl), 0-8. */
951
+ level: number;
952
+ /** Resolved format for this level. */
953
+ format: NumberFormat;
954
+ /** Always true for a paragraph carrying w:numPr (inline or via style). */
955
+ isAutoNumbered: boolean;
956
+ /** True when the w:numPr is inherited from the paragraph's style chain. */
957
+ fromStyle: boolean;
958
+ /** Start-override from w:lvlOverride/w:startOverride for this level, if any. */
959
+ startOverride?: number;
960
+ /** Resolved label (e.g. "1.", "(a)") — same value surfaced via AnchorInfo.autoNumberPrefix. */
961
+ generatedLabel?: string;
962
+ }
963
+ /** Block-level structural metadata. Returned by {@link DocxSession.getBlockMetadata}. */
964
+ export interface BlockMetadata {
965
+ anchorId: string;
966
+ kind: string;
967
+ scope: string;
968
+ styleId?: string;
969
+ styleName?: string;
970
+ /** 0-based outline level (Word convention). */
971
+ outlineLevel?: number;
972
+ list?: ListMembership;
973
+ /** True when any descendant w:r carries a non-empty w:rPr. */
974
+ hasInlineFormatting: boolean;
975
+ }
976
+ /** Page-layout snapshot for the w:sectPr that governs an anchor.
977
+ * Returned by {@link DocxSession.getSectionInfo}. */
978
+ export interface SectionInfo {
979
+ sectionUnid: string;
980
+ pageWidthTwips: number;
981
+ pageHeightTwips: number;
982
+ landscape: boolean;
983
+ marginTopTwips: number;
984
+ marginBottomTwips: number;
985
+ marginLeftTwips: number;
986
+ marginRightTwips: number;
987
+ columns: number;
988
+ headerPartUris: string[];
989
+ footerPartUris: string[];
704
990
  }
705
991
  /**
706
992
  * A custom annotation persisted in the document via Docxodus' annotation system.
707
993
  * Returned by {@link DocxSession.listAnnotations}; mirrors the wire-relevant
708
- * fields of the .NET `DocumentAnnotation` type. Stale page caches and arbitrary
709
- * metadata are omitted to keep the JSON payload compact — callers that need them
710
- * can use the .NET API directly.
994
+ * fields of the .NET `DocumentAnnotation` type. The page-info cache fields
995
+ * (`startPage`/`endPage`/`pageInfoStale`/`pageInfoComputedAt`) are omitted to
996
+ * keep the JSON payload compact — callers that need them can use the .NET API
997
+ * directly. The `metadata` bag is emitted only when non-empty.
711
998
  *
712
999
  * See `docs/architecture/custom_annotations.md` for the persistence design.
713
1000
  */
@@ -728,6 +1015,21 @@ export interface DocumentAnnotation {
728
1015
  created?: string;
729
1016
  /** The text content covered by the annotation's bookmark, populated when reading. */
730
1017
  annotatedText?: string;
1018
+ /** Arbitrary string→string metadata bag persisted with the annotation. */
1019
+ metadata?: Record<string, string>;
1020
+ }
1021
+ /**
1022
+ * Partial-update payload for {@link DocxSession.updateAnnotation}.
1023
+ * Null/missing fields leave the existing value unchanged. `metadataPatch`
1024
+ * is a per-key merge: a non-null value sets the key, an explicit `null`
1025
+ * removes it, a missing key leaves it unchanged.
1026
+ */
1027
+ export interface AnnotationUpdate {
1028
+ labelId?: string;
1029
+ label?: string;
1030
+ color?: string;
1031
+ author?: string;
1032
+ metadataPatch?: Record<string, string | null>;
731
1033
  }
732
1034
  /**
733
1035
  * Severity level for comparison log entries.
@@ -1275,7 +1577,7 @@ export interface DocumentMetadata {
1275
1577
  /**
1276
1578
  * Message types sent from main thread to worker.
1277
1579
  */
1278
- export type WorkerRequestType = "init" | "convertDocxToHtml" | "compareDocuments" | "compareDocumentsToHtml" | "getRevisions" | "getDocumentMetadata" | "getVersion";
1580
+ export type WorkerRequestType = "init" | "convertDocxToHtml" | "compareDocuments" | "compareDocumentsToHtml" | "getRevisions" | "getDocumentMetadata" | "getVersion" | "prepare" | "sessionOpen" | "sessionClose" | "sessionAddAnnotation" | "sessionRemoveAnnotation" | "sessionUpdateAnnotation" | "sessionMoveAnnotation";
1279
1581
  /**
1280
1582
  * Base structure for worker requests.
1281
1583
  */
@@ -1351,10 +1653,74 @@ export interface WorkerGetDocumentMetadataRequest extends WorkerRequestBase {
1351
1653
  export interface WorkerGetVersionRequest extends WorkerRequestBase {
1352
1654
  type: "getVersion";
1353
1655
  }
1656
+ /**
1657
+ * Warm up the comparison code path so the next compare triggers no further
1658
+ * WASM assembly fetches. Carries no payload.
1659
+ */
1660
+ export interface WorkerPrepareRequest extends WorkerRequestBase {
1661
+ type: "prepare";
1662
+ }
1663
+ /**
1664
+ * Open a DocxSession in the worker.
1665
+ */
1666
+ export interface WorkerSessionOpenRequest extends WorkerRequestBase {
1667
+ type: "sessionOpen";
1668
+ /** Document bytes transferred to the worker */
1669
+ documentBytes: Uint8Array;
1670
+ /** Session settings as JSON */
1671
+ settingsJson?: string;
1672
+ }
1673
+ /**
1674
+ * Close a worker DocxSession.
1675
+ */
1676
+ export interface WorkerSessionCloseRequest extends WorkerRequestBase {
1677
+ type: "sessionClose";
1678
+ /** Session handle returned by sessionOpen */
1679
+ handle: number;
1680
+ }
1681
+ /**
1682
+ * Add an annotation via a worker DocxSession.
1683
+ */
1684
+ export interface WorkerSessionAddAnnotationRequest extends WorkerRequestBase {
1685
+ type: "sessionAddAnnotation";
1686
+ handle: number;
1687
+ anchorId: string;
1688
+ /** CharSpan as JSON, or empty string for block-level */
1689
+ spanJson: string;
1690
+ annotationJson: string;
1691
+ }
1692
+ /**
1693
+ * Remove an annotation via a worker DocxSession.
1694
+ */
1695
+ export interface WorkerSessionRemoveAnnotationRequest extends WorkerRequestBase {
1696
+ type: "sessionRemoveAnnotation";
1697
+ handle: number;
1698
+ annotationId: string;
1699
+ }
1700
+ /**
1701
+ * Update an annotation via a worker DocxSession.
1702
+ */
1703
+ export interface WorkerSessionUpdateAnnotationRequest extends WorkerRequestBase {
1704
+ type: "sessionUpdateAnnotation";
1705
+ handle: number;
1706
+ annotationId: string;
1707
+ updateJson: string;
1708
+ }
1709
+ /**
1710
+ * Move an annotation via a worker DocxSession.
1711
+ */
1712
+ export interface WorkerSessionMoveAnnotationRequest extends WorkerRequestBase {
1713
+ type: "sessionMoveAnnotation";
1714
+ handle: number;
1715
+ annotationId: string;
1716
+ newAnchorId: string;
1717
+ /** CharSpan as JSON, or empty string for block-level */
1718
+ newSpanJson: string;
1719
+ }
1354
1720
  /**
1355
1721
  * Union type of all possible worker requests.
1356
1722
  */
1357
- export type WorkerRequest = WorkerInitRequest | WorkerConvertRequest | WorkerCompareRequest | WorkerCompareToHtmlRequest | WorkerGetRevisionsRequest | WorkerGetDocumentMetadataRequest | WorkerGetVersionRequest;
1723
+ export type WorkerRequest = WorkerInitRequest | WorkerConvertRequest | WorkerCompareRequest | WorkerCompareToHtmlRequest | WorkerGetRevisionsRequest | WorkerGetDocumentMetadataRequest | WorkerGetVersionRequest | WorkerPrepareRequest | WorkerSessionOpenRequest | WorkerSessionCloseRequest | WorkerSessionAddAnnotationRequest | WorkerSessionRemoveAnnotationRequest | WorkerSessionUpdateAnnotationRequest | WorkerSessionMoveAnnotationRequest;
1358
1724
  /**
1359
1725
  * Base structure for worker responses.
1360
1726
  */
@@ -1420,10 +1786,39 @@ export interface WorkerGetVersionResponse extends WorkerResponseBase {
1420
1786
  /** Version information */
1421
1787
  version?: VersionInfo;
1422
1788
  }
1789
+ /**
1790
+ * Response from prepare request. Carries no payload beyond success/error.
1791
+ */
1792
+ export interface WorkerPrepareResponse extends WorkerResponseBase {
1793
+ type: "prepare";
1794
+ }
1795
+ /**
1796
+ * Response from sessionOpen request.
1797
+ */
1798
+ export interface WorkerSessionOpenResponse extends WorkerResponseBase {
1799
+ type: "sessionOpen";
1800
+ /** Integer handle identifying the session in the worker */
1801
+ handle?: number;
1802
+ }
1803
+ /**
1804
+ * Response from sessionClose request.
1805
+ */
1806
+ export interface WorkerSessionCloseResponse extends WorkerResponseBase {
1807
+ type: "sessionClose";
1808
+ }
1809
+ /**
1810
+ * Response from session annotation write operations.
1811
+ * The `result` field is the serialised EditResult from the WASM bridge.
1812
+ */
1813
+ export interface WorkerSessionEditResponse extends WorkerResponseBase {
1814
+ type: "sessionAddAnnotation" | "sessionRemoveAnnotation" | "sessionUpdateAnnotation" | "sessionMoveAnnotation";
1815
+ /** EditResult returned by the session operation */
1816
+ result?: EditResult;
1817
+ }
1423
1818
  /**
1424
1819
  * Union type of all possible worker responses.
1425
1820
  */
1426
- export type WorkerResponse = WorkerInitResponse | WorkerConvertResponse | WorkerCompareResponse | WorkerCompareToHtmlResponse | WorkerGetRevisionsResponse | WorkerGetDocumentMetadataResponse | WorkerGetVersionResponse;
1821
+ export type WorkerResponse = WorkerInitResponse | WorkerConvertResponse | WorkerCompareResponse | WorkerCompareToHtmlResponse | WorkerGetRevisionsResponse | WorkerGetDocumentMetadataResponse | WorkerGetVersionResponse | WorkerPrepareResponse | WorkerSessionOpenResponse | WorkerSessionCloseResponse | WorkerSessionEditResponse;
1427
1822
  /**
1428
1823
  * Options for creating a worker-based Docxodus instance.
1429
1824
  */