@zeke-02/docx-editor-agents 0.1.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.
Files changed (59) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +126 -0
  3. package/dist/agent-types-C8RvQB7n.d.mts +36 -0
  4. package/dist/agent-types-C8RvQB7n.d.ts +36 -0
  5. package/dist/ai-sdk/react.d.mts +57 -0
  6. package/dist/ai-sdk/react.d.ts +57 -0
  7. package/dist/ai-sdk/react.js +1 -0
  8. package/dist/ai-sdk/react.mjs +1 -0
  9. package/dist/ai-sdk/server.d.mts +80 -0
  10. package/dist/ai-sdk/server.d.ts +80 -0
  11. package/dist/ai-sdk/server.js +1 -0
  12. package/dist/ai-sdk/server.mjs +1 -0
  13. package/dist/ai-sdk/vue.d.ts +32 -0
  14. package/dist/ai-sdk/vue.js +1 -0
  15. package/dist/ai-sdk/vue.mjs +28 -0
  16. package/dist/bridge.d.mts +19 -0
  17. package/dist/bridge.d.ts +19 -0
  18. package/dist/bridge.js +1 -0
  19. package/dist/bridge.mjs +1 -0
  20. package/dist/chunk-24MVJKCP.mjs +8 -0
  21. package/dist/chunk-2RGRAPLW.js +5 -0
  22. package/dist/chunk-53PAUP4S.js +2 -0
  23. package/dist/chunk-AU3KR5IN.mjs +5 -0
  24. package/dist/chunk-KMEZXSKR.mjs +2 -0
  25. package/dist/chunk-RI5S75JY.js +8 -0
  26. package/dist/chunk-UNUH3LRU.mjs +1 -0
  27. package/dist/chunk-VXAJD6QK.js +1 -0
  28. package/dist/docx-editor-agents.css +2 -0
  29. package/dist/index.d.mts +178 -0
  30. package/dist/index.d.ts +178 -0
  31. package/dist/index.js +1 -0
  32. package/dist/index.mjs +1 -0
  33. package/dist/mcp.d.mts +200 -0
  34. package/dist/mcp.d.ts +200 -0
  35. package/dist/mcp.js +4 -0
  36. package/dist/mcp.mjs +4 -0
  37. package/dist/react.d.mts +251 -0
  38. package/dist/react.d.ts +251 -0
  39. package/dist/react.js +9 -0
  40. package/dist/react.mjs +9 -0
  41. package/dist/server-uWvnaIh-.d.mts +620 -0
  42. package/dist/server-uWvnaIh-.d.ts +620 -0
  43. package/dist/server.d.mts +35 -0
  44. package/dist/server.d.ts +35 -0
  45. package/dist/server.js +1 -0
  46. package/dist/server.mjs +1 -0
  47. package/dist/vue/components/AIContextMenu.d.ts +33 -0
  48. package/dist/vue/components/AIResponsePreview.d.ts +40 -0
  49. package/dist/vue/components/AgentChatLog.d.ts +37 -0
  50. package/dist/vue/components/AgentComposer.d.ts +30 -0
  51. package/dist/vue/components/AgentPanel.d.ts +49 -0
  52. package/dist/vue/components/AgentSuggestionChip.d.ts +10 -0
  53. package/dist/vue/components/AgentTimeline.d.ts +19 -0
  54. package/dist/vue/composables/useAgentBridge.d.ts +19 -0
  55. package/dist/vue/types.d.ts +5 -0
  56. package/dist/vue.d.ts +72 -0
  57. package/dist/vue.js +20 -0
  58. package/dist/vue.mjs +2026 -0
  59. package/package.json +157 -0
@@ -0,0 +1,620 @@
1
+ import { Document } from '@zeke-02/docx-editor-core/headless';
2
+
3
+ interface HeadingBlock {
4
+ type: 'heading';
5
+ index: number;
6
+ /** Stable Word `w14:paraId`. Use this as the anchor for live-editor operations. */
7
+ paraId?: string;
8
+ level: number;
9
+ text: string;
10
+ }
11
+ interface ParagraphBlock {
12
+ type: 'paragraph';
13
+ index: number;
14
+ /** Stable Word `w14:paraId`. Use this as the anchor for live-editor operations. */
15
+ paraId?: string;
16
+ text: string;
17
+ }
18
+ interface TableBlock {
19
+ type: 'table';
20
+ index: number;
21
+ rows: string[][];
22
+ /** Per-cell paraIds, parallel to `rows`. cells[r][c] is the first paraId in that cell. */
23
+ cellParaIds?: (string | undefined)[][];
24
+ }
25
+ interface ListItemBlock {
26
+ type: 'list-item';
27
+ index: number;
28
+ /** Stable Word `w14:paraId`. Use this as the anchor for live-editor operations. */
29
+ paraId?: string;
30
+ text: string;
31
+ listLevel: number;
32
+ listType: 'bullet' | 'number';
33
+ }
34
+ type ContentBlock = HeadingBlock | ParagraphBlock | TableBlock | ListItemBlock;
35
+ interface GetContentOptions {
36
+ fromIndex?: number;
37
+ toIndex?: number;
38
+ /** Annotate tracked changes inline. Default: true */
39
+ includeTrackedChanges?: boolean;
40
+ /** Annotate comments inline. Default: true */
41
+ includeCommentAnchors?: boolean;
42
+ }
43
+ interface ReviewChange {
44
+ id: number;
45
+ type: 'insertion' | 'deletion' | 'moveFrom' | 'moveTo';
46
+ author: string;
47
+ date: string | null;
48
+ text: string;
49
+ context: string;
50
+ paragraphIndex: number;
51
+ }
52
+ interface ReviewCommentReply {
53
+ id: number;
54
+ author: string;
55
+ date: string | null;
56
+ text: string;
57
+ }
58
+ interface ReviewComment {
59
+ id: number;
60
+ author: string;
61
+ date: string | null;
62
+ text: string;
63
+ anchoredText: string;
64
+ paragraphIndex: number;
65
+ replies: ReviewCommentReply[];
66
+ done: boolean;
67
+ }
68
+ interface ChangeFilter {
69
+ author?: string;
70
+ type?: 'insertion' | 'deletion' | 'moveFrom' | 'moveTo';
71
+ }
72
+ interface CommentFilter {
73
+ author?: string;
74
+ done?: boolean;
75
+ }
76
+ /**
77
+ * Live-editor (bridge) action options — anchored by Word `w14:paraId`.
78
+ * Stable across edits; the agent gets paraIds from `read_document` / `find_text`.
79
+ */
80
+ interface AddCommentByParaIdOptions {
81
+ paraId: string;
82
+ text: string;
83
+ author?: string;
84
+ /** Optional: anchor to a specific phrase within the paragraph (must be unique). */
85
+ search?: string;
86
+ }
87
+ /**
88
+ * Headless / DocxReviewer action options — anchored by ordinal paragraph index.
89
+ * Used by the static-document review pipeline.
90
+ */
91
+ interface AddCommentOptions {
92
+ paragraphIndex: number;
93
+ text: string;
94
+ author?: string;
95
+ /** Optional: anchor to specific text. Omit to anchor whole paragraph. */
96
+ search?: string;
97
+ }
98
+ interface ReplyOptions {
99
+ text: string;
100
+ author?: string;
101
+ }
102
+ /**
103
+ * Live-editor change. Pass `replaceWith: ''` to delete; pass `search: ''` to
104
+ * insert at end of paragraph; pass both non-empty for a replacement.
105
+ */
106
+ interface ProposeChangeOptions {
107
+ paraId: string;
108
+ search: string;
109
+ replaceWith: string;
110
+ author?: string;
111
+ }
112
+ interface ProposeReplacementOptions {
113
+ paragraphIndex: number;
114
+ search: string;
115
+ replaceWith: string;
116
+ author?: string;
117
+ }
118
+ interface ProposeInsertionOptions {
119
+ paragraphIndex: number;
120
+ insertText: string;
121
+ author?: string;
122
+ position?: 'before' | 'after';
123
+ search?: string;
124
+ }
125
+ interface ProposeDeletionOptions {
126
+ paragraphIndex: number;
127
+ search: string;
128
+ author?: string;
129
+ }
130
+ /** Per-match handle returned by `findText` — pass `paraId` + `match` back as `search`. */
131
+ interface FoundMatch {
132
+ paraId: string;
133
+ match: string;
134
+ before: string;
135
+ after: string;
136
+ }
137
+ /** @public */
138
+ interface SelectionInfo {
139
+ paraId: string | null;
140
+ selectedText: string;
141
+ paragraphText: string;
142
+ before: string;
143
+ after: string;
144
+ }
145
+ /**
146
+ * Character formatting marks the agent can apply.
147
+ *
148
+ * Mirrors Word JS API `Range.font.*`. A `false` value clears that mark in the
149
+ * range; a missing key leaves it untouched. `color.themeColor` follows ECMA-376
150
+ * theme color values (e.g. `'accent1'`, `'text1'`) and resolves at render time.
151
+ */
152
+ interface CharacterFormatting {
153
+ bold?: boolean;
154
+ italic?: boolean;
155
+ underline?: boolean | {
156
+ style?: string;
157
+ };
158
+ strike?: boolean;
159
+ color?: {
160
+ rgb?: string;
161
+ themeColor?: string;
162
+ };
163
+ highlight?: string;
164
+ fontSize?: number;
165
+ fontFamily?: {
166
+ ascii?: string;
167
+ hAnsi?: string;
168
+ };
169
+ }
170
+ /**
171
+ * Apply character formatting to a range. `paraId` is required; if `search`
172
+ * is provided, the formatting only applies to that phrase within the
173
+ * paragraph (must match exactly once). Otherwise it applies to the whole
174
+ * paragraph's text.
175
+ */
176
+ interface ApplyFormattingOptions {
177
+ paraId: string;
178
+ search?: string;
179
+ marks: CharacterFormatting;
180
+ }
181
+ /**
182
+ * Apply a paragraph style by `styleId` (e.g. `'Heading1'`, `'Title'`,
183
+ * `'Quote'`). The styleId must exist in the document's style definitions
184
+ * — unknown ids are no-ops.
185
+ */
186
+ interface SetParagraphStyleOptions {
187
+ paraId: string;
188
+ styleId: string;
189
+ }
190
+ /** A single paragraph anchored on a page (returned by `getPage` / `getPages`). */
191
+ interface PageParagraph {
192
+ paraId: string;
193
+ text: string;
194
+ /** True for headings, list items, and other styled blocks. */
195
+ styleId?: string;
196
+ }
197
+ /** What the agent sees when reading one or more pages. */
198
+ interface PageContent {
199
+ /** 1-indexed page number. */
200
+ pageNumber: number;
201
+ /** Plain text of the page, formatted as `[paraId] text` lines. */
202
+ text: string;
203
+ /** Paragraphs on the page, in document order. */
204
+ paragraphs: PageParagraph[];
205
+ }
206
+ /**
207
+ * Snapshot of what the user is looking at — pass this to your agent's system
208
+ * prompt so it knows the current selection / page without an extra
209
+ * `read_selection` round-trip.
210
+ *
211
+ * @public
212
+ */
213
+ interface AgentContextSnapshot {
214
+ /** User's current selection or cursor (null if editor isn't focused). */
215
+ selection: SelectionInfo | null;
216
+ /** 1-indexed page the cursor / selection is on. 0 if unknown. */
217
+ currentPage: number;
218
+ /** Total number of pages currently rendered. */
219
+ totalPages: number;
220
+ }
221
+ interface BatchReviewOptions {
222
+ accept?: number[];
223
+ reject?: number[];
224
+ comments?: AddCommentOptions[];
225
+ replies?: (ReplyOptions & {
226
+ commentId: number;
227
+ })[];
228
+ proposals?: ProposeReplacementOptions[];
229
+ }
230
+ interface BatchError {
231
+ operation: string;
232
+ id?: number;
233
+ search?: string;
234
+ error: string;
235
+ }
236
+ interface BatchResult {
237
+ accepted: number;
238
+ rejected: number;
239
+ commentsAdded: number;
240
+ repliesAdded: number;
241
+ proposalsAdded: number;
242
+ errors: BatchError[];
243
+ }
244
+
245
+ /**
246
+ * Headless DOCX reviewer — parse a file, read/comment/track changes
247
+ * against the document model, write the modified DOCX back out. No DOM,
248
+ * no editor instance. Pair with `createReviewerBridge()` to drive the
249
+ * built-in agent tools against a file on disk.
250
+ *
251
+ * @example
252
+ * ```ts
253
+ * const reviewer = await DocxReviewer.fromBuffer(buffer, 'AI Reviewer');
254
+ * reviewer.addComment(5, 'Fix this paragraph.');
255
+ * reviewer.replace(5, '$50k', '$500k');
256
+ * const output = await reviewer.toBuffer();
257
+ * ```
258
+ *
259
+ * @public
260
+ */
261
+ declare class DocxReviewer {
262
+ private doc;
263
+ /** Default author for comments and tracked changes. Set once, used everywhere. */
264
+ readonly author: string;
265
+ /**
266
+ * Create a reviewer from a parsed Document.
267
+ * @param document - Parsed Document from the core package
268
+ * @param author - Default author name for comments and changes. (default: 'AI')
269
+ * @param originalBuffer - Original DOCX buffer, needed for toBuffer()
270
+ */
271
+ constructor(document: Document, author?: string, originalBuffer?: ArrayBuffer);
272
+ /**
273
+ * Create a reviewer from a DOCX file buffer.
274
+ * @param buffer - ArrayBuffer of the DOCX file
275
+ * @param author - Default author name for comments and changes. (default: 'AI')
276
+ */
277
+ static fromBuffer(buffer: ArrayBuffer, author?: string): Promise<DocxReviewer>;
278
+ private get body();
279
+ private resolveAuthor;
280
+ /** Get document content as structured blocks (headings, paragraphs, tables, lists). */
281
+ getContent(options?: GetContentOptions): ContentBlock[];
282
+ /**
283
+ * Get document content as plain text for LLM prompts.
284
+ * Each paragraph is prefixed with its index: `[0] text`, `[1] text`, etc.
285
+ * Table cells include position: `[5] (table, row 1, col 2) cell text`.
286
+ * Avoids JSON quote-escaping issues — LLMs can copy text verbatim.
287
+ */
288
+ getContentAsText(options?: GetContentOptions): string;
289
+ /** Get all tracked changes in the document. */
290
+ getChanges(filter?: ChangeFilter): ReviewChange[];
291
+ /** Get all comments with their replies. */
292
+ getComments(filter?: CommentFilter): ReviewComment[];
293
+ /**
294
+ * Add a comment on a paragraph.
295
+ * @param paragraphIndex - Index of the paragraph to comment on
296
+ * @param text - Comment text
297
+ * @returns The new comment ID
298
+ */
299
+ addComment(paragraphIndex: number, text: string): number;
300
+ /**
301
+ * Add a comment with full options (custom author, anchored to specific text).
302
+ * @param options - Comment options
303
+ * @returns The new comment ID
304
+ */
305
+ addComment(options: AddCommentOptions): number;
306
+ /**
307
+ * Reply to an existing comment.
308
+ * @param commentId - ID of the comment to reply to
309
+ * @param text - Reply text
310
+ * @returns The new reply comment ID
311
+ */
312
+ replyTo(commentId: number, text: string): number;
313
+ /** Reply to an existing comment with full options. */
314
+ replyTo(commentId: number, options: ReplyOptions): number;
315
+ /**
316
+ * Remove a comment by ID. Removing a top-level comment also removes its
317
+ * replies and the anchored range markers. Removing a reply only removes
318
+ * that reply.
319
+ * @param commentId - ID of the comment to remove
320
+ */
321
+ removeComment(commentId: number): void;
322
+ /**
323
+ * Replace text in a paragraph. Creates a tracked change (deletion + insertion).
324
+ * @param paragraphIndex - Index of the paragraph
325
+ * @param search - Short phrase to find within the paragraph
326
+ * @param replaceWith - Replacement text
327
+ */
328
+ replace(paragraphIndex: number, search: string, replaceWith: string): void;
329
+ /** Replace text with full options. */
330
+ replace(options: ProposeReplacementOptions): void;
331
+ /** @deprecated Use replace() instead. */
332
+ proposeReplacement(options: ProposeReplacementOptions): void;
333
+ /** Insert text as a tracked change. */
334
+ proposeInsertion(options: ProposeInsertionOptions): void;
335
+ /** Delete text as a tracked change. */
336
+ proposeDeletion(options: ProposeDeletionOptions): void;
337
+ /** Accept a tracked change by its revision ID. */
338
+ acceptChange(id: number): void;
339
+ /** Reject a tracked change by its revision ID. */
340
+ rejectChange(id: number): void;
341
+ /** Accept all tracked changes. Returns count accepted. */
342
+ acceptAll(): number;
343
+ /** Reject all tracked changes. Returns count rejected. */
344
+ rejectAll(): number;
345
+ /**
346
+ * Apply multiple review operations in one call.
347
+ * Uses the reviewer's default author. Individual failures are collected, not thrown.
348
+ */
349
+ applyReview(ops: BatchReviewOptions): BatchResult;
350
+ /** Get the modified Document model. */
351
+ toDocument(): Document;
352
+ /** Serialize back to a DOCX buffer. Requires the original buffer. */
353
+ toBuffer(): Promise<ArrayBuffer>;
354
+ }
355
+
356
+ /**
357
+ * Reviewer bridge — wraps a `DocxReviewer` (static document) in the same
358
+ * `EditorBridge` interface the live editor exposes. Lets the same MCP server
359
+ * / agent tools operate on a parsed-from-disk DOCX without a running editor.
360
+ *
361
+ * Trade-offs vs. the live bridge:
362
+ * - `getSelection()` always returns `null` (no user, no selection).
363
+ * - `scrollTo()` is a no-op that returns `true` (the doc isn't being viewed).
364
+ * - `onSelectionChange` listeners never fire (returned unsubscribers are no-ops).
365
+ * - `onContentChange` fires after every successful mutation through this bridge,
366
+ * so MCP clients still get notifications when the agent is the only writer.
367
+ * - paraId resolution maps to `paragraphIndex` by walking the document body
368
+ * once. None of the reviewer's mutators (`addComment`, `proposeChange`,
369
+ * `replyTo`, `resolveComment`) shift top-level indices, so the map is
370
+ * cached for the bridge's lifetime.
371
+ *
372
+ * After the agent finishes mutating, call `reviewer.toBuffer()` to serialize
373
+ * back to DOCX. The bridge does NOT do that automatically — the host decides
374
+ * when to flush.
375
+ */
376
+
377
+ /**
378
+ * Create an EditorBridge backed by a DocxReviewer. The agent (or MCP client)
379
+ * can read, comment, propose changes, etc., against a parsed DOCX file on
380
+ * disk. Call `reviewer.toBuffer()` afterwards to get the modified DOCX.
381
+ *
382
+ * @param reviewer - A DocxReviewer instance. The bridge mutates it in place.
383
+ *
384
+ * @public
385
+ */
386
+ declare function createReviewerBridge(reviewer: DocxReviewer): EditorBridge;
387
+
388
+ /**
389
+ * Agent-bridge contract every editor adapter (React, Vue, future) MUST satisfy.
390
+ * Versioning: additions are coordinated minor bumps across the fixed group;
391
+ * signature changes / removals are major. See
392
+ * `openspec/changes/vue-editor-robust-implementation/design.md` Decision 18.
393
+ */
394
+ interface EditorRefLike {
395
+ getDocument(): unknown | null;
396
+ getEditorRef(): {
397
+ getDocument(): unknown | null;
398
+ } | null;
399
+ addComment(options: {
400
+ paraId: string;
401
+ text: string;
402
+ author: string;
403
+ search?: string;
404
+ }): number | null;
405
+ replyToComment(commentId: number, text: string, author: string): number | null;
406
+ resolveComment(commentId: number): void;
407
+ proposeChange(options: {
408
+ paraId: string;
409
+ search: string;
410
+ replaceWith: string;
411
+ author: string;
412
+ }): boolean;
413
+ scrollToParaId(paraId: string): boolean;
414
+ findInDocument(query: string, options?: {
415
+ caseSensitive?: boolean;
416
+ limit?: number;
417
+ }): FoundMatch[];
418
+ getSelectionInfo(): SelectionInfo | null;
419
+ getComments(): Array<{
420
+ id: number;
421
+ author: string;
422
+ date?: string;
423
+ parentId?: number;
424
+ content: unknown[];
425
+ done?: boolean;
426
+ }>;
427
+ /** Apply character formatting to a paragraph or sub-range. Returns false on missing paraId / ambiguous search. */
428
+ applyFormatting(options: {
429
+ paraId: string;
430
+ search?: string;
431
+ marks: CharacterFormatting;
432
+ }): boolean;
433
+ /** Apply a paragraph style by styleId. Returns false if paraId is unknown. */
434
+ setParagraphStyle(options: {
435
+ paraId: string;
436
+ styleId: string;
437
+ }): boolean;
438
+ /** Read a single page's paragraphs (1-indexed). Returns null if the page does not exist. */
439
+ getPageContent(pageNumber: number): PageContent | null;
440
+ /** Total number of pages currently rendered. */
441
+ getTotalPages(): number;
442
+ /** 1-indexed page the user's cursor / selection is on. 0 if unknown. */
443
+ getCurrentPage(): number;
444
+ onContentChange(listener: (doc: unknown) => void): () => void;
445
+ onSelectionChange(listener: (selection: unknown) => void): () => void;
446
+ }
447
+ /**
448
+ * High-level agent surface over a live editor (or a headless reviewer).
449
+ * Every built-in tool calls into this contract — implement it once and
450
+ * the agent toolkit works against your editor.
451
+ *
452
+ * @public
453
+ */
454
+ interface EditorBridge {
455
+ /** Get document content as paraId-tagged text lines for LLM prompts. */
456
+ getContentAsText(options?: GetContentOptions): string;
457
+ /** Get document content as structured blocks (each paragraph carries its `paraId`). */
458
+ getContent(options?: GetContentOptions): ContentBlock[];
459
+ /** Get all comments in the document. */
460
+ getComments(filter?: CommentFilter): ReviewComment[];
461
+ /** Get all tracked changes in the document. */
462
+ getChanges(filter?: ChangeFilter): ReviewChange[];
463
+ /** Locate text in the document. Returns one handle per matching paragraph. */
464
+ findText(query: string, options?: {
465
+ caseSensitive?: boolean;
466
+ limit?: number;
467
+ }): FoundMatch[];
468
+ /** Read the user's current cursor / selection. */
469
+ getSelection(): SelectionInfo | null;
470
+ /** Add a comment, anchored to a paragraph by paraId. */
471
+ addComment(options: AddCommentByParaIdOptions): number | null;
472
+ /** Reply to an existing comment. Returns the reply ID or null. */
473
+ replyTo(commentId: number, options: ReplyOptions): number | null;
474
+ /** Resolve a comment (mark as done). */
475
+ resolveComment(commentId: number): void;
476
+ /** Suggest a tracked change. `replaceWith=''` deletes; `search=''` inserts at paragraph end. */
477
+ proposeChange(options: ProposeChangeOptions): boolean;
478
+ /**
479
+ * Apply character formatting (bold / italic / color / size / font / etc.)
480
+ * to a paragraph, or to a unique phrase within it. This is a direct edit —
481
+ * not a tracked change.
482
+ */
483
+ applyFormatting(options: ApplyFormattingOptions): boolean;
484
+ /**
485
+ * Apply a paragraph style by styleId (e.g. `'Heading1'`, `'Quote'`).
486
+ * Direct edit, not a tracked change.
487
+ */
488
+ setParagraphStyle(options: SetParagraphStyleOptions): boolean;
489
+ /** Read a single page (1-indexed). Returns null if the page does not exist. */
490
+ getPage(pageNumber: number): PageContent | null;
491
+ /** Read a range of pages (1-indexed, inclusive). Out-of-range pages are skipped. */
492
+ getPages(options: {
493
+ from: number;
494
+ to: number;
495
+ }): PageContent[];
496
+ /** Total number of pages currently rendered in the editor. */
497
+ getTotalPages(): number;
498
+ /** 1-indexed page the user's cursor / selection is on. 0 if unknown. */
499
+ getCurrentPage(): number;
500
+ /** Scroll the editor to a paragraph by paraId. */
501
+ scrollTo(paraId: string): boolean;
502
+ /** Subscribe to document content changes. Returns an unsubscribe function. */
503
+ onContentChange(listener: (event: ContentChangeEvent) => void): () => void;
504
+ /** Subscribe to selection changes (cursor moves / selection changes). Returns an unsubscribe function. */
505
+ onSelectionChange(listener: (event: SelectionChangeEvent) => void): () => void;
506
+ }
507
+ /** Event payload for `onContentChange`. */
508
+ interface ContentChangeEvent {
509
+ /** Total comments in the document after the change. */
510
+ commentCount: number;
511
+ /** Total tracked changes after the change. */
512
+ changeCount: number;
513
+ /** Snapshot of all current comments. */
514
+ comments: ReviewComment[];
515
+ /** Snapshot of all current tracked changes. */
516
+ changes: ReviewChange[];
517
+ }
518
+ /** Event payload for `onSelectionChange`. */
519
+ type SelectionChangeEvent = SelectionInfo | null;
520
+ /**
521
+ * Create an EditorBridge from a DocxEditorRef.
522
+ *
523
+ * @param editorRef - A DocxEditorRef (or anything matching EditorRefLike)
524
+ * @param author - Default author name for comments and changes. (default: 'AI')
525
+ */
526
+ declare function createEditorBridge(editorRef: EditorRefLike, author?: string): EditorBridge;
527
+
528
+ /**
529
+ * Agent tool type definitions.
530
+ */
531
+
532
+ /**
533
+ * Definition of an agent tool — name, JSON-schema input, handler.
534
+ * Use this to build custom tools alongside the built-in `agentTools`.
535
+ *
536
+ * @public
537
+ */
538
+ interface AgentToolDefinition<TInput = Record<string, unknown>> {
539
+ /** Tool name (used in tool_use blocks) */
540
+ name: string;
541
+ /**
542
+ * Friendly UI label for the tool. Shown in the agent panel's timeline
543
+ * (e.g. "Reading document"). Falls back to a sentence-case version of
544
+ * `name` if omitted, so consumer-defined tools render readably without
545
+ * specifying this.
546
+ */
547
+ displayName?: string;
548
+ /** Human-readable description for the LLM */
549
+ description: string;
550
+ /** JSON Schema for the input parameters */
551
+ inputSchema: Record<string, unknown>;
552
+ /** Handler — receives parsed input + bridge, returns result */
553
+ handler: (input: TInput, bridge: EditorBridge) => AgentToolResult;
554
+ }
555
+ /**
556
+ * Result returned by a tool handler. `success: false` carries an `error`
557
+ * message; `success: true` may carry tool-specific `data`.
558
+ *
559
+ * @public
560
+ */
561
+ interface AgentToolResult {
562
+ success: boolean;
563
+ data?: unknown;
564
+ error?: string;
565
+ }
566
+
567
+ /**
568
+ * Agent tool definitions and execution.
569
+ *
570
+ * Tools use OpenAI function-calling format. The pattern mirrors Word's JS API:
571
+ * locate first (`read_document` / `find_text` / `read_selection` return paraId
572
+ * handles), then mutate (`comment` / `suggest_change` / `reply_comment` /
573
+ * `resolve_comment` / `scroll`). paraId anchors are stable across edits.
574
+ */
575
+
576
+ /**
577
+ * All built-in agent tools — read/write document content, comments, and
578
+ * tracked changes. Use `getToolSchemas()` to feed them to an LLM and
579
+ * `executeToolCall()` to run the handlers against an `EditorBridge`.
580
+ *
581
+ * @public
582
+ */
583
+ declare const agentTools: AgentToolDefinition<any>[];
584
+ /**
585
+ * Execute a tool call against an EditorBridge.
586
+ * Returns the result (never throws).
587
+ *
588
+ * @public
589
+ */
590
+ declare function executeToolCall(toolName: string, input: Record<string, unknown>, bridge: EditorBridge): AgentToolResult;
591
+ /**
592
+ * Friendly UI label for a tool — sourced from the registry's `displayName`,
593
+ * falling back to a sentence-case version of the snake_case name. Used by
594
+ * `<AgentTimeline>` and any other UI that lists running / completed tools.
595
+ *
596
+ * @example getToolDisplayName('add_comment') // → 'Adding comment'
597
+ * @example getToolDisplayName('fetch_clause_template') // → 'Fetch clause template'
598
+ *
599
+ * @public
600
+ */
601
+ declare function getToolDisplayName(name: string): string;
602
+ /**
603
+ * Get tool schemas in OpenAI function-calling format. Works directly
604
+ * with the OpenAI SDK and Anthropic's tools API. For Vercel AI SDK,
605
+ * LangChain, or other agent runtimes, transform this output to that
606
+ * runtime's required shape — see `examples/agent-chat-demo/` for a
607
+ * Vercel AI SDK example. The package stays runtime-agnostic.
608
+ *
609
+ * @public
610
+ */
611
+ declare function getToolSchemas(): {
612
+ type: "function";
613
+ function: {
614
+ name: string;
615
+ description: string;
616
+ parameters: Record<string, unknown>;
617
+ };
618
+ }[];
619
+
620
+ export { type AddCommentByParaIdOptions as A, type BatchError as B, type ContentBlock as C, DocxReviewer as D, type EditorBridge as E, type FoundMatch as F, type GetContentOptions as G, type ProposeChangeOptions as P, type ReviewComment as R, type SelectionInfo as S, type CommentFilter as a, type ChangeFilter as b, type ReviewChange as c, type ReplyOptions as d, type ApplyFormattingOptions as e, type SetParagraphStyleOptions as f, type PageContent as g, type ContentChangeEvent as h, type SelectionChangeEvent as i, type AgentToolDefinition as j, type AgentToolResult as k, type BatchResult as l, type BatchReviewOptions as m, agentTools as n, createReviewerBridge as o, executeToolCall as p, getToolSchemas as q, type EditorRefLike as r, type AgentContextSnapshot as s, getToolDisplayName as t, createEditorBridge as u };
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @zeke-02/docx-editor-agents/server
3
+ *
4
+ * Server entry for API routes, Node.js, serverless functions, and Workers.
5
+ *
6
+ * Import the toolkit here without pulling in React peer deps. Use this from
7
+ * Next.js routes, a FastAPI bridge, a Cloudflare Worker, or any other
8
+ * backend that streams an LLM call with tool definitions.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { getToolSchemas } from '@zeke-02/docx-editor-agents/server';
13
+ * import { streamText, jsonSchema, convertToModelMessages } from 'ai';
14
+ *
15
+ * // `getToolSchemas()` returns OpenAI function-calling format. For Vercel
16
+ * // AI SDK v5, adapt to `{ [name]: { description, inputSchema } }` once.
17
+ * const tools = Object.fromEntries(
18
+ * getToolSchemas().map((s) => [
19
+ * s.function.name,
20
+ * { description: s.function.description, inputSchema: jsonSchema(s.function.parameters as never) },
21
+ * ])
22
+ * );
23
+ *
24
+ * export async function POST(req: Request) {
25
+ * const { messages } = await req.json();
26
+ * const result = streamText({ model: 'openai/gpt-4o', messages: convertToModelMessages(messages), tools });
27
+ * return result.toUIMessageStreamResponse();
28
+ * }
29
+ * ```
30
+ *
31
+ * @packageDocumentation
32
+ * @public
33
+ */
34
+ export { s as AgentContextSnapshot, j as AgentToolDefinition, k as AgentToolResult, D as DocxReviewer, E as EditorBridge, S as SelectionInfo, o as createReviewerBridge, n as docxAgentTools, p as executeToolCall, t as getToolDisplayName, q as getToolSchemas } from './server-uWvnaIh-.mjs';
35
+ import '@zeke-02/docx-editor-core/headless';
@@ -0,0 +1,35 @@
1
+ /**
2
+ * @zeke-02/docx-editor-agents/server
3
+ *
4
+ * Server entry for API routes, Node.js, serverless functions, and Workers.
5
+ *
6
+ * Import the toolkit here without pulling in React peer deps. Use this from
7
+ * Next.js routes, a FastAPI bridge, a Cloudflare Worker, or any other
8
+ * backend that streams an LLM call with tool definitions.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { getToolSchemas } from '@zeke-02/docx-editor-agents/server';
13
+ * import { streamText, jsonSchema, convertToModelMessages } from 'ai';
14
+ *
15
+ * // `getToolSchemas()` returns OpenAI function-calling format. For Vercel
16
+ * // AI SDK v5, adapt to `{ [name]: { description, inputSchema } }` once.
17
+ * const tools = Object.fromEntries(
18
+ * getToolSchemas().map((s) => [
19
+ * s.function.name,
20
+ * { description: s.function.description, inputSchema: jsonSchema(s.function.parameters as never) },
21
+ * ])
22
+ * );
23
+ *
24
+ * export async function POST(req: Request) {
25
+ * const { messages } = await req.json();
26
+ * const result = streamText({ model: 'openai/gpt-4o', messages: convertToModelMessages(messages), tools });
27
+ * return result.toUIMessageStreamResponse();
28
+ * }
29
+ * ```
30
+ *
31
+ * @packageDocumentation
32
+ * @public
33
+ */
34
+ export { s as AgentContextSnapshot, j as AgentToolDefinition, k as AgentToolResult, D as DocxReviewer, E as EditorBridge, S as SelectionInfo, o as createReviewerBridge, n as docxAgentTools, p as executeToolCall, t as getToolDisplayName, q as getToolSchemas } from './server-uWvnaIh-.js';
35
+ import '@zeke-02/docx-editor-core/headless';
package/dist/server.js ADDED
@@ -0,0 +1 @@
1
+ 'use strict';var chunkVXAJD6QK_js=require('./chunk-VXAJD6QK.js'),chunk2RGRAPLW_js=require('./chunk-2RGRAPLW.js'),chunkRI5S75JY_js=require('./chunk-RI5S75JY.js');Object.defineProperty(exports,"DocxReviewer",{enumerable:true,get:function(){return chunkVXAJD6QK_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunk2RGRAPLW_js.m}});Object.defineProperty(exports,"docxAgentTools",{enumerable:true,get:function(){return chunkRI5S75JY_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkRI5S75JY_js.b}});Object.defineProperty(exports,"getToolDisplayName",{enumerable:true,get:function(){return chunkRI5S75JY_js.c}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkRI5S75JY_js.d}});
@@ -0,0 +1 @@
1
+ export{a as DocxReviewer}from'./chunk-UNUH3LRU.mjs';export{m as createReviewerBridge}from'./chunk-AU3KR5IN.mjs';export{a as docxAgentTools,b as executeToolCall,c as getToolDisplayName,d as getToolSchemas}from'./chunk-24MVJKCP.mjs';