@eigenpal/docx-editor-agents 1.5.0 → 1.6.1

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 (53) hide show
  1. package/README.md +1 -1
  2. package/dist/ai-sdk/server.js +1 -1
  3. package/dist/ai-sdk/server.mjs +1 -1
  4. package/dist/bridge.d.mts +1 -1
  5. package/dist/bridge.d.ts +1 -1
  6. package/dist/bridge.js +1 -1
  7. package/dist/bridge.mjs +1 -1
  8. package/dist/chunk-3RLSV2EA.mjs +2 -0
  9. package/dist/chunk-5THPDZLF.mjs +5 -0
  10. package/dist/{chunk-XDZHYYU6.mjs → chunk-6RMDMHUK.mjs} +1 -1
  11. package/dist/{chunk-RI5S75JY.js → chunk-AO5SO6ZS.js} +4 -4
  12. package/dist/chunk-EX4NO3JP.js +5 -0
  13. package/dist/{chunk-RYT33AHF.js → chunk-JMEIIPEL.js} +1 -1
  14. package/dist/{chunk-EPRXZTIE.js → chunk-MMJQ47Q7.js} +1 -1
  15. package/dist/{chunk-24MVJKCP.mjs → chunk-MSKW7E36.mjs} +4 -4
  16. package/dist/chunk-RTU2ZS7R.js +75 -0
  17. package/dist/chunk-X5FXVERG.mjs +75 -0
  18. package/dist/{chunk-BFGKTTP7.mjs → chunk-YAKNDLQA.mjs} +1 -1
  19. package/dist/chunk-YIZV6SSD.js +2 -0
  20. package/dist/executor-3N3ESB3N.mjs +1 -0
  21. package/dist/executor-KLVHM2GK.js +1 -0
  22. package/dist/headless-6GD55ATM.js +1 -0
  23. package/dist/{headless-6HFY6GHX.mjs → headless-ESEZ6OHS.mjs} +1 -1
  24. package/dist/index.d.mts +3 -2
  25. package/dist/index.d.ts +3 -2
  26. package/dist/index.js +1 -1
  27. package/dist/index.mjs +1 -1
  28. package/dist/mcp.d.mts +1 -1
  29. package/dist/mcp.d.ts +1 -1
  30. package/dist/mcp.js +3 -3
  31. package/dist/mcp.mjs +3 -3
  32. package/dist/react.d.mts +8 -8
  33. package/dist/react.d.ts +8 -8
  34. package/dist/react.js +2 -2
  35. package/dist/react.mjs +1 -1
  36. package/dist/{server-D1vJRNf0.d.mts → server-DP8QoY84.d.mts} +22 -0
  37. package/dist/{server-D1vJRNf0.d.ts → server-DP8QoY84.d.ts} +22 -0
  38. package/dist/server.d.mts +1 -1
  39. package/dist/server.d.ts +1 -1
  40. package/dist/server.js +1 -1
  41. package/dist/server.mjs +1 -1
  42. package/dist/vue.js +6 -6
  43. package/dist/vue.mjs +226 -179
  44. package/package.json +1 -1
  45. package/dist/chunk-3XKOKAHP.mjs +0 -75
  46. package/dist/chunk-4I6U7BWX.mjs +0 -2
  47. package/dist/chunk-HSVOT6AW.mjs +0 -5
  48. package/dist/chunk-HTMMNA3I.js +0 -75
  49. package/dist/chunk-UTMAYI7M.js +0 -2
  50. package/dist/chunk-VPUAYS3Y.js +0 -5
  51. package/dist/executor-SBR6X4JZ.mjs +0 -1
  52. package/dist/executor-ZTSOZMKE.js +0 -1
  53. package/dist/headless-HVIRJIN4.js +0 -1
package/README.md CHANGED
@@ -86,7 +86,7 @@ app.post('/api/mcp', requireAuth, async (req, res) => {
86
86
  });
87
87
  ```
88
88
 
89
- Ten built-in agent tools (`read_document`, `find_text`, `add_comment`, `suggest_change`, `read_comments`, `read_changes`, `reply_comment`, `resolve_comment`, `read_selection`, `scroll`) are exposed automatically via MCP `tools/list` and `tools/call`. MCP spec version: `2025-06-18`.
89
+ The built-in agent tools (`read_document`, `read_selection`, `read_page`, `read_pages`, `find_text`, `read_comments`, `read_changes`, `add_comment`, `suggest_change`, `apply_formatting`, `set_paragraph_style`, `insert_break`, `reply_comment`, `resolve_comment`, `scroll`) are exposed automatically via MCP `tools/list` and `tools/call`. MCP spec version: `2025-06-18`.
90
90
 
91
91
  > A local stdio MCP bin is one-document-per-config (Claude Desktop loads its list at startup), which doesn't fit a multi-doc product. Host the server yourself with your own auth and storage.
92
92
 
@@ -1 +1 @@
1
- 'use strict';var chunkRI5S75JY_js=require('../chunk-RI5S75JY.js'),ai=require('ai');function n(){return Object.fromEntries(chunkRI5S75JY_js.a.map(o=>[o.name,{description:o.description,inputSchema:ai.jsonSchema(o.inputSchema)}]))}exports.getAiSdkTools=n;
1
+ 'use strict';var chunkAO5SO6ZS_js=require('../chunk-AO5SO6ZS.js'),ai=require('ai');function n(){return Object.fromEntries(chunkAO5SO6ZS_js.a.map(o=>[o.name,{description:o.description,inputSchema:ai.jsonSchema(o.inputSchema)}]))}exports.getAiSdkTools=n;
@@ -1 +1 @@
1
- import {a}from'../chunk-24MVJKCP.mjs';import {jsonSchema}from'ai';function n(){return Object.fromEntries(a.map(o=>[o.name,{description:o.description,inputSchema:jsonSchema(o.inputSchema)}]))}export{n as getAiSdkTools};
1
+ import {a}from'../chunk-MSKW7E36.mjs';import {jsonSchema}from'ai';function n(){return Object.fromEntries(a.map(o=>[o.name,{description:o.description,inputSchema:jsonSchema(o.inputSchema)}]))}export{n as getAiSdkTools};
package/dist/bridge.d.mts CHANGED
@@ -15,4 +15,4 @@
15
15
  * @packageDocumentation
16
16
  * @public
17
17
  */
18
- export { j as AgentToolDefinition, k as AgentToolResult, h as ContentChangeEvent, E as EditorBridge, r as EditorRefLike, i as SelectionChangeEvent, n as agentTools, u as createEditorBridge, o as createReviewerBridge, p as executeToolCall, q as getToolSchemas } from './server-D1vJRNf0.mjs';
18
+ export { j as AgentToolDefinition, k as AgentToolResult, h as ContentChangeEvent, E as EditorBridge, r as EditorRefLike, i as SelectionChangeEvent, n as agentTools, u as createEditorBridge, o as createReviewerBridge, p as executeToolCall, q as getToolSchemas } from './server-DP8QoY84.mjs';
package/dist/bridge.d.ts CHANGED
@@ -15,4 +15,4 @@
15
15
  * @packageDocumentation
16
16
  * @public
17
17
  */
18
- export { j as AgentToolDefinition, k as AgentToolResult, h as ContentChangeEvent, E as EditorBridge, r as EditorRefLike, i as SelectionChangeEvent, n as agentTools, u as createEditorBridge, o as createReviewerBridge, p as executeToolCall, q as getToolSchemas } from './server-D1vJRNf0.js';
18
+ export { j as AgentToolDefinition, k as AgentToolResult, h as ContentChangeEvent, E as EditorBridge, r as EditorRefLike, i as SelectionChangeEvent, n as agentTools, u as createEditorBridge, o as createReviewerBridge, p as executeToolCall, q as getToolSchemas } from './server-DP8QoY84.js';
package/dist/bridge.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkUTMAYI7M_js=require('./chunk-UTMAYI7M.js'),chunkVPUAYS3Y_js=require('./chunk-VPUAYS3Y.js'),chunkRI5S75JY_js=require('./chunk-RI5S75JY.js');Object.defineProperty(exports,"createEditorBridge",{enumerable:true,get:function(){return chunkUTMAYI7M_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunkVPUAYS3Y_js.n}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkRI5S75JY_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkRI5S75JY_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkRI5S75JY_js.d}});
1
+ 'use strict';var chunkYIZV6SSD_js=require('./chunk-YIZV6SSD.js'),chunkEX4NO3JP_js=require('./chunk-EX4NO3JP.js'),chunkAO5SO6ZS_js=require('./chunk-AO5SO6ZS.js');Object.defineProperty(exports,"createEditorBridge",{enumerable:true,get:function(){return chunkYIZV6SSD_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunkEX4NO3JP_js.n}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkAO5SO6ZS_js.d}});
package/dist/bridge.mjs CHANGED
@@ -1 +1 @@
1
- export{a as createEditorBridge}from'./chunk-4I6U7BWX.mjs';export{n as createReviewerBridge}from'./chunk-HSVOT6AW.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-24MVJKCP.mjs';
1
+ export{a as createEditorBridge}from'./chunk-3RLSV2EA.mjs';export{n as createReviewerBridge}from'./chunk-5THPDZLF.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-MSKW7E36.mjs';
@@ -0,0 +1,2 @@
1
+ import {m,l,e,f}from'./chunk-5THPDZLF.mjs';function y(n){return !n||n.length===0?"":n.map(l=>{let s=l;return s?.content?s.content.map(e=>e.content?.map(t=>t.text||"").join("")||"").join(""):""}).join(`
2
+ `)}function u(n){let l=n.getEditorRef();if(l){let e=l.getDocument();if(e?.package?.document)return e.package.document}return n.getDocument()?.package?.document??null}function k(n,l$1="AI"){function s(e){return e??l$1}return {getContentAsText(e$1){let t=u(n);return t?f(e(t,e$1)):""},getContent(e$1){let t=u(n);return t?e(t,e$1):[]},getComments(e){let t=u(n);if(!t)return [];let r=m(t,e);if(r.length>0)return r;let i=n.getComments();if(i.length===0)return [];let a=new Map,g=[];for(let o of i)if(o.parentId){let p=a.get(o.parentId);p?p.push(o):a.set(o.parentId,[o]);}else g.push(o);let m$1=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let p=a.get(o.id)??[];m$1.push({id:o.id,author:o.author,date:o.date??null,text:y(o.content),anchoredText:"",paragraphIndex:-1,replies:p.map(c=>({id:c.id,author:c.author,date:c.date??null,text:y(c.content)})),done:o.done??false});}return m$1},getChanges(e){let t=u(n);return t?l(t,e):[]},findText(e,t){return n.findInDocument(e,t)},getSelection(){return n.getSelectionInfo()},addComment(e){return n.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,t){return n.replyToComment(e,t.text,s(t.author))},resolveComment(e){n.resolveComment(e);},proposeChange(e){return n.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return n.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return n.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},insertBreak(e){return n.insertBreak({paraId:e.paraId,type:e.type})},getPage(e){return n.getPageContent(e)},getPages(e){let t=n.getTotalPages(),r=Math.max(1,Math.min(e.from,t)),i=Math.max(r,Math.min(e.to,t)),a=[];for(let g=r;g<=i;g++){let m=n.getPageContent(g);m&&a.push(m);}return a},getTotalPages(){return n.getTotalPages()},getCurrentPage(){return n.getCurrentPage()},scrollTo(e){return n.scrollToParaId(e)},onContentChange(e){return n.onContentChange(()=>{let t=u(n),r=t?m(t):[],i=t?l(t):[];try{e({commentCount:r.length,changeCount:i.length,comments:r,changes:i});}catch(a){console.error("onContentChange listener threw:",a);}})},onSelectionChange(e){return n.onSelectionChange(()=>{try{e(n.getSelectionInfo());}catch(t){console.error("onSelectionChange listener threw:",t);}})}}}export{k as a};
@@ -0,0 +1,5 @@
1
+ import {U as U$1,V as V$1,H as H$1,I as I$1,va}from'./chunk-X5FXVERG.mjs';import {m as m$1}from'./chunk-6RMDMHUK.mjs';function h(o){return o.type==="insertion"||o.type==="deletion"||o.type==="moveFrom"||o.type==="moveTo"}function C(o){let t=[];for(let r of o)r.type==="run"?t.push(H$1(r)):r.type==="hyperlink"&&t.push(I$1(r));return t.join("")}function R(o,t){let r=0;for(let n of o.content)if(n.type==="paragraph"){if(r===t)return n;r++;}else if(n.type==="table"){for(let a of n.rows)for(let e of a.cells)for(let i of e.content)if(i.type==="paragraph"){if(r===t)return i;r++;}}else r++;throw new Error(`Paragraph index ${t} out of bounds (max: ${r-1})`)}function A(o,t,r){let n=0;for(let a of o)if(a.type==="paragraph"){if(r(a,n)===false)return;n++;}else if(a.type==="table"){for(let e of a.rows)for(let i of e.cells)for(let s of i.content)if(s.type==="paragraph"){if(r(s,n)===false)return;n++;}}else t&&n++;}function m(o,t){A(o.content,true,t);}function k(o,t){A(o.content,false,t);}function fe(o,t={}){let{fromIndex:r,toIndex:n,includeTrackedChanges:a=true,includeCommentAnchors:e=true}=t,i=[],s=0;for(let u of o.content)if(u.type==="paragraph")L(s,r,n)&&i.push(Q(u,s,a,e)),s++;else if(u.type==="table"){L(s,r,n)&&i.push(V(u,s,a,e));for(let l of u.rows)for(let c of l.cells)for(let f of c.content)f.type==="paragraph"&&s++;}else s++;return i}function L(o,t,r){return (t===void 0||o>=t)&&(r===void 0||o<=r)}function Q(o,t,r,n){let a=j(o,r,n),e=o.formatting?.styleId,i=o.paraId;return U$1(e)?{type:"heading",index:t,paraId:i,level:V$1(e)??1,text:a}:o.listRendering?{type:"list-item",index:t,paraId:i,text:a,listLevel:o.listRendering.level??0,listType:o.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:t,paraId:i,text:a}}function V(o,t,r,n){let a=[],e=[];for(let i of o.rows){let s=[],u=[];for(let l of i.cells){let c=[],f;for(let d of l.content)d.type==="paragraph"&&(f===void 0&&(f=d.paraId),c.push(j(d,r,n)));s.push(c.join(`
2
+ `)),u.push(f);}a.push(s),e.push(u);}return {type:"table",index:t,rows:a,cellParaIds:e}}function pe(o){let t=[],r=n=>n.paraId?n.paraId:String(n.index);for(let n of o)switch(n.type){case "heading":t.push(`[${r(n)}] (h${n.level}) ${n.text}`);break;case "paragraph":t.push(`[${r(n)}] ${n.text}`);break;case "list-item":{let a=" ".repeat(n.listLevel),e=n.listType==="bullet"?"\u2022":"-";t.push(`[${r(n)}] ${a}${e} ${n.text}`);break}case "table":{let a=n.index;for(let e=0;e<n.rows.length;e++)for(let i=0;i<n.rows[e].length;i++){let u=n.rows[e][i].split(`
3
+ `),l=n.cellParaIds?.[e]?.[i];for(let c=0;c<u.length;c++){let f=c===0&&l?l:String(a);t.push(`[${f}] (table, row ${e+1}, col ${i+1}) ${u[c]}`),a++;}}break}}return t.join(`
4
+ `)}function j(o,t,r){let n=[],a=new Set;for(let e of o.content){if(e.type==="commentRangeStart"&&r){a.add(e.id),n.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&r){a.has(e.id)&&(a.delete(e.id),n.push("[/comment]"));continue}if(e.type==="run")n.push(H$1(e));else if(e.type==="hyperlink")n.push(I$1(e));else if(h(e)){let i=C(e.content);e.type==="insertion"||e.type==="moveTo"?t&&n.push(`[+${i}+]{by:${e.info.author}}`):t?n.push(`[-${i}-]{by:${e.info.author}}`):n.push(i);}}return n.join("")}var T=class extends Error{constructor(t,r){let n=r!==void 0?` in paragraph ${r}`:" in document";super(`Text not found${n}: "${t}"`),this.name="TextNotFoundError";}},H=class extends Error{constructor(t){super(`Tracked change not found: id=${t}`),this.name="ChangeNotFoundError";}},I=class extends Error{constructor(t){super(`Comment not found: id=${t}`),this.name="CommentNotFoundError";}};function U(o){let t=[],r=0;for(let n=0;n<o.content.length;n++){let a=o.content[n];if(a.type==="run"){let e=H$1(a);t.push({contentIndex:n,run:a,text:e,startPos:r}),r+=e.length;}else if(a.type==="hyperlink")for(let e=0;e<a.children.length;e++){let i=a.children[e];if(i.type==="run"){let s=H$1(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}}else if(h(a)){if(a.type==="insertion"||a.type==="moveTo")continue;for(let e=0;e<a.content.length;e++){let i=a.content[e];if(i.type==="run"){let s=H$1(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}else if(i.type==="hyperlink"){for(let s of i.children)if(s.type==="run"){let u=H$1(s);t.push({contentIndex:n,run:s,text:u,startPos:r}),r+=u.length;}}}}}return t}function w(o){return U(o).map(t=>t.text).join("")}function Y(o,t,r){let n=U(o),a=n.map(c=>c.text).join(""),e=Z(a,t);if(!e)throw new T(t,r);let i=-1,s=0;for(let c=0;c<n.length;c++)if(e.start<n[c].startPos+n[c].text.length){i=c,s=e.start-n[c].startPos;break}let u=-1,l=0;for(let c=n.length-1;c>=0;c--)if(e.end>n[c].startPos){u=c,l=e.end-n[c].startPos;break}if(i===-1||u===-1)throw new T(t,r);return {startRunIndex:n[i].contentIndex,startOffset:s,endRunIndex:n[u].contentIndex,endOffset:l}}function xe(o,t,r){let n=Y(o,t,r),{startRunIndex:a,endRunIndex:e}=n,{startOffset:i,endOffset:s}=n,u=o.content[e];if(u.type==="run"){let c=H$1(u);if(s<c.length){let f=N(c.slice(s),u);z(u,c.slice(0,s)),o.content.splice(e+1,0,f);}}let l=o.content[a];if(l.type==="run"&&i>0){let c=H$1(l),f=N(c.slice(0,i),l);z(l,c.slice(i)),o.content.splice(a,0,f),a++,e++;}return {startIndex:a,endIndex:e}}function N(o,t){return {type:"run",content:[{type:"text",text:o}],formatting:t.formatting?{...t.formatting}:void 0}}function z(o,t){let r=o.content.find(n=>n.type==="text");r&&(r.text=t);}function W(o){let t=[],r=[],n=true;for(let a=0;a<o.length;a++){let e=o[a];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(e)){if("\u201C\u201D\u201E\u201F".includes(e)&&(e='"'),"\u2018\u2019\u201A\u201B".includes(e)&&(e="'"),"\u2013\u2014\u2012\u2015".includes(e)&&(e="-"),e==="\u2026"){t.push(".",".","."),r.push(a,a,a),n=false;continue}if(/\s/.test(e)||e==="\xA0"){n||(t.push(" "),r.push(a),n=true);continue}t.push(e.toLowerCase()),r.push(a),n=false;}}return t.length>0&&t[t.length-1]===" "&&(t.pop(),r.pop()),{text:t.join(""),posMap:r}}function G(o,t,r,n){let a=o.posMap[t],e=o.posMap[t+r-1]+1;for(;e<n.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(n[e]);)e++;return {start:a,end:e}}function Z(o,t){if(!t||!o)return null;let r=o.indexOf(t);if(r!==-1)return {start:r,end:r+t.length};let n=W(o),a=W(t);if(!a.text)return null;let e=n.text.indexOf(a.text);if(e!==-1)return G(n,e,a.text.length,o);let i=a.text.split(" ");if(i.length>=3)for(let s=1;s<=Math.min(2,i.length-2);s++){let u=i.slice(0,-s).join(" "),l=n.text.indexOf(u);if(l!==-1)return G(n,l,u.length,o)}return null}function Te(o,t,r){let n=new Map,a=(i,s,u)=>{let l=null;for(let c of i.content)if(h(c)){l===null&&(l=w(i));let f=C(c.content),d=c.info.id,x=`${u.noteType??"body"}:${u.noteId??""}:${d}`,y=n.get(x);y&&y.paragraphIndex===s?y.text+=f:n.set(x,{id:d,type:c.type,author:c.info.author,date:c.info.date??null,text:f,context:l,paragraphIndex:s,...u.noteId!==void 0?{noteId:u.noteId}:{},...u.noteType!==void 0?{noteType:u.noteType}:{}});}};if(m(o,(i,s)=>a(i,s,{})),t?.includeFootnotes&&r?.footnotes)for(let i of r.footnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"footnote"}));if(t?.includeEndnotes&&r?.endnotes)for(let i of r.endnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"endnote"}));return Array.from(n.values()).filter(i=>!(t?.author&&i.author!==t.author||t?.type&&i.type!==t.type))}function Pe(o,t){let r=o.comments??[];if(r.length===0)return [];let n=_(o),a=[],e=new Map;for(let s of r)if(s.parentId!==void 0){let u=e.get(s.parentId)??[];u.push(s),e.set(s.parentId,u);}else a.push(s);return a.map(s=>{let u=n.get(s.id),l=(e.get(s.id)??[]).map(c=>({id:c.id,author:c.author,date:c.date??null,text:X(c)}));return {id:s.id,author:s.author,date:s.date??null,text:X(s),anchoredText:u?.text??"",paragraphIndex:u?.paragraphIndex??-1,replies:l,done:s.done??false}}).filter(s=>!(t?.author&&s.author!==t.author||t?.done!==void 0&&s.done!==t.done))}function X(o){return o.content.map(t=>w(t)).join(`
5
+ `)}function _(o){let t=new Map,r=new Map;return m(o,(n,a)=>{for(let e of n.content)if(e.type==="commentRangeStart")r.set(e.id,{paragraphIndex:a,parts:[]});else if(e.type==="commentRangeEnd"){let i=r.get(e.id);i&&(t.set(e.id,{text:i.parts.join(""),paragraphIndex:i.paragraphIndex}),r.delete(e.id));}else if(e.type==="run"){let i=H$1(e);for(let s of r.values())s.parts.push(i);}else if(e.type==="hyperlink"){let i=e.children.filter(s=>s.type==="run").map(H$1).join("");for(let s of r.values())s.parts.push(i);}else if(h(e)){if(e.type==="insertion"||e.type==="moveTo")continue;let i=C(e.content);for(let s of r.values())s.parts.push(i);}}),t}function q(o){let t=o.toDocument().package?.document;if(!t)return new Map;let r=new Map;return m(t,(n,a)=>{r.set(n.paraId??String(a),a),r.set(String(a),a);}),r}function ee(o){let t=[],r=n=>{for(let a of n.content)a.type==="text"&&t.push(a.text??"");};for(let n of o.content)if(n.type==="run")r(n);else if(n.type==="hyperlink")for(let a of n.children)a.type==="run"&&r(a);else if(n.type==="deletion"||n.type==="moveFrom"){for(let a of n.content)if(a.type==="run")r(a);else if(a.type==="hyperlink")for(let e of a.children)e.type==="run"&&r(e);}return t.join("")}function B(o,t){let n={type:"run",content:[{type:"text",text:t,preserveSpace:/^\s|\s$/.test(t)}]};return o.formatting&&(n.formatting={...o.formatting}),o.propertyChanges&&(n.propertyChanges=[...o.propertyChanges]),n}function te(o){return o.content.map(t=>t.type==="text"?t.text:"").join("")}function M(o,t,r,n,a){let e=te(o);if(!e)return;let i=a.value,s=i+e.length;n.push({run:o,parent:t,index:r,text:e,start:i,end:s}),a.value=s;}function J(o,t,r){o.children.forEach((n,a)=>{n.type==="run"&&M(n,o.children,a,t,r);});}function D(o,t){let r=[],n={value:0};return o.content.forEach((a,e)=>{a.type==="run"?M(a,o.content,e,r,n):a.type==="hyperlink"?J(a,r,n):(a.type==="deletion"||a.type==="moveFrom"||t&&(a.type==="insertion"||a.type==="moveTo"))&&a.content.forEach((i,s)=>{i.type==="run"?M(i,a.content,s,r,n):i.type==="hyperlink"&&J(i,r,n);});}),r}function ne(o,t){let r={...o??{}};t.bold!==void 0&&(r.bold=t.bold||void 0),t.italic!==void 0&&(r.italic=t.italic||void 0),t.underline!==void 0&&(t.underline?r.underline={style:typeof t.underline=="object"&&t.underline.style?t.underline.style:"single"}:delete r.underline),t.strike!==void 0&&(r.strike=t.strike||void 0),t.color!==void 0&&(t.color&&(t.color.rgb||t.color.themeColor)?r.color={rgb:t.color.rgb,themeColor:t.color.themeColor}:delete r.color),t.highlight!==void 0&&(t.highlight?r.highlight=va(t.highlight)||t.highlight:delete r.highlight),t.fontSize!==void 0&&(t.fontSize>0?r.fontSize=m$1(t.fontSize):delete r.fontSize),t.fontFamily!==void 0&&(t.fontFamily&&(t.fontFamily.ascii||t.fontFamily.hAnsi)?r.fontFamily={ascii:t.fontFamily.ascii,hAnsi:t.fontFamily.hAnsi??t.fontFamily.ascii}:delete r.fontFamily);for(let n of Object.keys(r))r[n]===void 0&&delete r[n];return Object.keys(r).length>0?r:void 0}function S(o,t){o.formatting=ne(o.formatting,t);}function oe(o,t,r,n){let a=o.run.content.every(s=>s.type==="text");if(t<=0&&r>=o.text.length||!a){S(o.run,n);return}let e=[];t>0&&e.push(B(o.run,o.text.slice(0,t)));let i=B(o.run,o.text.slice(t,r));S(i,n),e.push(i),r<o.text.length&&e.push(B(o.run,o.text.slice(r))),o.parent.splice(o.index,1,...e);}function re(o,t,r,n){let e=D(o,false).filter(i=>i.start<r&&i.end>t);if(e.length===0)return true;for(let i=e.length-1;i>=0;i--){let s=e[i];oe(s,Math.max(0,t-s.start),Math.min(s.text.length,r-s.start),n);}return true}function ae(o,t){let r=D(o,true);for(let n of r)S(n.run,t);return true}function ie(o,t){if(!t)return null;let n=D(o,false).map(e=>e.text).join(""),a=n.indexOf(t);return a===-1||n.indexOf(t,a+1)!==-1?null:{from:a,to:a+t.length}}function se(o,t){return o?!!o.styles?.some(r=>r.styleId===t&&r.type==="paragraph"):true}function ke(o){let t=new Set,r=null;function n(){return r===null&&(r=q(o)),r}function a(){if(t.size===0)return;let e=o.getComments(),i=o.getChanges(),s={commentCount:e.length,changeCount:i.length,comments:e,changes:i};for(let u of t)try{u(s);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return o.getContentAsText(e)},getContent(e){return o.getContent(e)},getComments(e){return o.getComments(e)},getChanges(e){return o.getChanges(e)},findText(e,i){if(!e)return [];let s=i?.caseSensitive??false,u=i?.limit??20,l=s?e:e.toLowerCase(),c=o.toDocument().package?.document;if(!c)return [];let f=[],d=40;return m(c,(x,y)=>{let b=ee(x),E=s?b:b.toLowerCase(),g=E.indexOf(l);if(g===-1||E.indexOf(l,g+1)!==-1)return;let K=b.slice(g,g+e.length);if(f.push({paraId:x.paraId??String(y),match:K,before:b.slice(Math.max(0,g-d),g),after:b.slice(g+e.length,g+e.length+d)}),f.length>=u)return false}),f},getSelection(){return null},addComment(e){let i=n().get(e.paraId);if(i===void 0)return null;try{let s=o.addComment({paragraphIndex:i,text:e.text,author:e.author,search:e.search});return a(),s}catch{return null}},replyTo(e,i){try{let s=o.replyTo(e,i);return a(),s}catch{return null}},resolveComment(e){let s=o.toDocument().package?.document?.comments?.find(u=>u.id===e);if(!s)throw new I(e);s.done=true,a();},proposeChange(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=e.search==="",u=e.replaceWith==="";if(s&&u)return false;try{return s?o.proposeInsertion({paragraphIndex:i,insertText:e.replaceWith,author:e.author}):u?o.proposeDeletion({paragraphIndex:i,search:e.search,author:e.author}):o.replace({paragraphIndex:i,search:e.search,replaceWith:e.replaceWith,author:e.author}),a(),true}catch{return false}},scrollTo(e){return n().has(e)},applyFormatting(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=s?R(s,i):null;if(!u)return false;if(e.search){let l=ie(u,e.search);if(!l)return false;re(u,l.from,l.to,e.marks);}else ae(u,e.marks);return a(),true}catch{return false}},setParagraphStyle(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument(),u=s.package?.document;if(!u||!se(s.package?.styles,e.styleId))return false;try{let l=R(u,i);return l.formatting={...l.formatting??{},styleId:e.styleId},a(),true}catch{return false}},insertBreak(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=R(s,i);if(!u)return false;if(e.type==="sectionNextPage"||e.type==="sectionContinuous"){let f=e.type==="sectionNextPage"?"nextPage":"continuous";return u.sectionProperties={...u.sectionProperties??{},sectionStart:f},a(),true}let l=s.content.indexOf(u);if(l===-1)return false;let c={type:"paragraph",content:[{type:"run",content:[{type:"break",breakType:"page"}]}]};return s.content.splice(l+1,0,c),r=null,a(),true}catch{return false}},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return t.add(e),()=>{t.delete(e);}},onSelectionChange(){return ()=>{}}}}export{h as a,R as b,m as c,k as d,fe as e,pe as f,T as g,H as h,I as i,Y as j,xe as k,Te as l,Pe as m,ke as n};
@@ -1 +1 @@
1
- var D=class{constructor(){this.plugins=new Map;this.commandHandlers=new Map;this.eventListeners=new Set;this.initialized=new Set;}register(e,o){let n=[];if(!e.id)return {success:false,error:"Plugin must have an id"};if(this.plugins.has(e.id))return {success:false,error:`Plugin '${e.id}' is already registered`};if(e.dependencies){for(let t of e.dependencies)if(!this.plugins.has(t))return {success:false,error:`Plugin '${e.id}' requires '${t}' which is not registered`}}if(e.commandHandlers)for(let[t,s]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(t)){let i=this.commandHandlers.get(t);n.push(`Command '${t}' from '${e.id}' overrides handler from '${i.pluginId}'`);}this.commandHandlers.set(t,{pluginId:e.id,handler:s});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let t=e.initialize();t instanceof Promise?t.then(()=>{this.initialized.add(e.id);}).catch(s=>{this.emit({type:"error",pluginId:e.id,error:s});}):this.initialized.add(e.id);}catch(t){this.emit({type:"error",pluginId:e.id,error:t});}return o?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:n.length>0?n:void 0}}unregister(e){let o=this.plugins.get(e);if(!o)return false;for(let[n,t]of this.plugins)if(t.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${n}' depends on it`),false;for(let[n,{pluginId:t}]of this.commandHandlers)t===e&&this.commandHandlers.delete(n);if(o.destroy)try{let n=o.destroy();n instanceof Promise&&n.catch(t=>{this.emit({type:"error",pluginId:e,error:t});});}catch(n){this.emit({type:"error",pluginId:e,error:n});}return this.plugins.delete(e),this.initialized.delete(e),this.emit({type:"unregistered",pluginId:e}),true}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get size(){return this.plugins.size}getCommandHandler(e){return this.commandHandlers.get(e)?.handler}getCommandTypes(){return Array.from(this.commandHandlers.keys())}hasCommandHandler(e){return this.commandHandlers.has(e)}getMcpTools(){let e=[];for(let o of this.plugins.values())o.mcpTools&&e.push(...o.mcpTools);return e}getMcpToolsForPlugin(e){return this.plugins.get(e)?.mcpTools||[]}getMcpTool(e){for(let o of this.plugins.values())if(o.mcpTools){let n=o.mcpTools.find(t=>t.name===e);if(n)return n}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let o of this.eventListeners)try{o(e);}catch(n){console.error("[PluginRegistry] Event listener error:",n);}}clear(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy();}catch{}this.plugins.clear(),this.commandHandlers.clear(),this.initialized.clear();}getDebugInfo(){return {plugins:Array.from(this.plugins.keys()),commandTypes:Array.from(this.commandHandlers.keys()),mcpTools:this.getMcpTools().map(e=>e.name),initialized:Array.from(this.initialized)}}},C=new D;function U(r,e){return r.map(o=>C.register(o,e))}function W(r){return e=>C.register(e,r)}function h(r){return JSON.parse(JSON.stringify(r))}function g(r,e){let o=0;for(let n=0;n<r.content.length;n++)if(r.content[n].type==="paragraph"){if(o===e)return n;o++;}return -1}function y(r){let e="";for(let o of r.content)if(o.type==="run")for(let n of o.content)n.type==="text"&&(e+=n.text);else if(o.type==="hyperlink"){for(let n of o.children)if(n.type==="run")for(let t of n.content)t.type==="text"&&(e+=t.text);}return e}function T(r,e){return {type:"run",formatting:e,content:[{type:"text",text:r}]}}function I(r,e,o,n){let t=[],s=0,i=false;for(let a of r.content)if(a.type==="run"){let p=a.content.filter(l=>l.type==="text").map(l=>l.text).join(""),c=s,u=s+p.length;if(!i&&e>=c&&e<=u){let l=e-c;l>0&&t.push({...a,content:[{type:"text",text:p.slice(0,l)}]}),t.push(T(o,n||a.formatting)),l<p.length&&t.push({...a,content:[{type:"text",text:p.slice(l)}]}),i=true;}else t.push(a);s=u;}else t.push(a);return i||t.push(T(o,n)),t}function d(r,e,o){let n=[],t=0;for(let s of r.content)if(s.type==="run"){let i=s.content.filter(c=>c.type==="text").map(c=>c.text).join(""),a=t,p=t+i.length;if(p<=e||a>=o)n.push(s);else {let c="";a<e&&(c+=i.slice(0,e-a)),p>o&&(c+=i.slice(o-a)),c.length>0&&n.push({...s,content:[{type:"text",text:c}]});}t=p;}else n.push(s);return n}function w(r,e,o,n){let t=[],s=0;for(let i of r.content)if(i.type==="run"){let a=i.content.filter(u=>u.type==="text").map(u=>u.text).join(""),p=s,c=s+a.length;if(c<=e||p>=o)t.push(i);else if(p>=e&&c<=o)t.push({...i,formatting:{...i.formatting,...n}});else {let u=Math.max(e,p),l=Math.min(o,c);p<u&&t.push({...i,content:[{type:"text",text:a.slice(0,u-p)}]}),t.push({...i,formatting:{...i.formatting,...n},content:[{type:"text",text:a.slice(u-p,l-p)}]}),c>l&&t.push({...i,content:[{type:"text",text:a.slice(l-p)}]});}s=c;}else t.push(i);return t}function R(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t];return s.content=I(s,e.position.offset,e.text,e.formatting),o}function _(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset),a.content=I(a,t.offset,e.text,e.formatting);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length),a.content=I(a,t.offset,e.text,e.formatting);let c=[];for(let u=t.paragraphIndex+1;u<=s.paragraphIndex;u++)c.push(g(n,u));for(let u=c.length-1;u>=0;u--)c[u]!==-1&&n.content.splice(c[u],1);}return o}function v(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length);let c=g(n,s.paragraphIndex),u=n.content[c];u.content=d(u,0,s.offset),a.content.push(...u.content);let l=[];for(let f=t.paragraphIndex+1;f<=s.paragraphIndex;f++)l.push(g(n,f));for(let f=l.length-1;f>=0;f--)l[f]!==-1&&n.content.splice(l[f],1);}return o}function S(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=w(a,t.offset,s.offset,e.formatting);}else for(let i=t.paragraphIndex;i<=s.paragraphIndex;i++){let a=g(n,i);if(a===-1)continue;let p=n.content[a],c=y(p),u=0,l=c.length;i===t.paragraphIndex&&(u=t.offset),i===s.paragraphIndex&&(l=s.offset),p.content=w(p,u,l,e.formatting);}return o}function N(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];if(s.formatting={...s.formatting,...e.formatting},"numPr"in e.formatting){let i=e.formatting.numPr;if(i&&i.numId!==void 0&&i.numId!==0){let a=i.ilvl??0,p=i.numId===1,c=p?"\u2022":"1.";if(o.package.numbering){let u=o.package.numbering.nums.find(l=>l.numId===i.numId);if(u){let l=o.package.numbering.abstractNums.find(f=>f.abstractNumId===u.abstractNumId);if(l){let f=l.levels.find(m=>m.ilvl===a);f&&(c=f.lvlText||c);}}}s.listRendering={level:a,numId:i.numId,marker:c,isBullet:p};}else delete s.listRendering;}return o}function A(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];return s.formatting={...s.formatting,styleId:e.styleId},o}function Q(r){return r/1440*96}function Y(r){return r/96*1440}function Z(r){return r==null||isNaN(r)?0:Math.round(r*96/914400)}function E(r){return Math.round(r/96*914400)}function ee(r){return Math.round(r/914400*1440)}function te(r){return Math.round(r/1440*914400)}function ne(r){return r/72*96}function re(r){return r/144*96}function oe(r){return r*2}function X(r,e=2){let o=Math.pow(10,e);return Math.round(r*o)/o}function ae(r){return `${X(r)}px`}function M(r,e){let o=h(r),n=o.package.document,t=[];for(let a=0;a<e.rows;a++){let p=[];for(let c=0;c<e.columns;c++){let u=e.data?.[a]?.[c]||"";p.push({type:"tableCell",content:[{type:"paragraph",content:u?[T(u)]:[]}]});}t.push({type:"tableRow",formatting:a===0&&e.hasHeader?{header:true}:void 0,cells:p});}let s={type:"table",rows:t},i=g(n,e.position.paragraphIndex);return i===-1?n.content.push(s):n.content.splice(i+1,0,s),o}function $(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],a={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:e.src,alt:e.alt,size:{width:E(e.width||100),height:E(e.height||100)},wrap:{type:"inline"}}}]},p=I(s,e.position.offset,"",void 0),c=false,u=0;for(let l=0;l<p.length;l++){let f=p[l];if(f.type==="run"){let m=f.content.filter(x=>x.type==="text").map(x=>x.text).join("");if(u+=m.length,!c&&u>=e.position.offset){p.splice(l+1,0,a),c=true;break}}}return c||p.push(a),s.content=p,o}function B(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex!==s.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i],p=y(a),c=e.displayText||p.slice(t.offset,s.offset);a.content=d(a,t.offset,s.offset);let u={type:"hyperlink",href:e.url,tooltip:e.tooltip,children:[T(c)]},l=false,f=0,m=[];for(let x of a.content)if(x.type==="run"){let b=x.content.filter(P=>P.type==="text").map(P=>P.text).join(""),H=f+b.length;if(!l&&f<=t.offset&&t.offset<=H){let P=t.offset-f;P>0&&m.push({...x,content:[{type:"text",text:b.slice(0,P)}]}),m.push(u),P<b.length&&m.push({...x,content:[{type:"text",text:b.slice(P)}]}),l=true;}else m.push(x);f=H;}else m.push(x);return l||m.push(u),a.content=m,o}function F(r,e){let o=h(r),n=o.package.document,{start:t}=e.range,s=g(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let i=n.content[s],a=[];for(let p of i.content)if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&a.push(c);else a.push(p);return i.content=a,o}function k(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],i=y(s),a=d({content:[...s.content]},e.position.offset,i.length),p=d({content:[...s.content]},0,e.position.offset);s.content=a;let c={type:"paragraph",formatting:s.formatting,content:p};return n.content.splice(t+1,0,c),o}function L(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t],i=[];for(let a=1;a<=e.count;a++){let p=g(n,e.paragraphIndex+a);if(p!==-1){let c=n.content[p];s.content.push(...c.content),i.push(p);}}for(let a=i.length-1;a>=0;a--)n.content.splice(i[a],1);return o}function V(r,e){return k(r,{position:e.position})}function z(r,e){let o=h(r);return o.templateVariables||(o.templateVariables=[]),o.templateVariables.includes(e.name)||o.templateVariables.push(e.name),o}function O(r,e){let o=h(r),n=o.package.document;function t(a){for(let p of a.content)if(p.type==="text")for(let[c,u]of Object.entries(e.values)){let l=new RegExp(`\\{${c}\\}`,"g");p.text=p.text.replace(l,u);}}function s(a){for(let p of a.content)if(p.type==="run")t(p);else if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&t(c);}function i(a){if(a.type==="paragraph")s(a);else if(a.type==="table")for(let p of a.rows)for(let c of p.cells)for(let u of c.content)i(u);}for(let a of n.content)i(a);return o}function j(r,e){let o=C.getCommandHandler(e.type);if(o)return o(r,e);switch(e.type){case "insertText":return R(r,e);case "replaceText":return _(r,e);case "deleteText":return v(r,e);case "formatText":return S(r,e);case "formatParagraph":return N(r,e);case "applyStyle":return A(r,e);case "insertTable":return M(r,e);case "insertImage":return $(r,e);case "insertHyperlink":return B(r,e);case "removeHyperlink":return F(r,e);case "insertParagraphBreak":return k(r,e);case "mergeParagraphs":return L(r,e);case "splitParagraph":return V(r,e);case "setVariable":return z(r,e);case "applyVariables":return O(r,e);default:{let n=e;throw new Error(`Unknown command type: ${n.type}`)}}}function ye(r,e){return e.reduce((o,n)=>j(o,n),r)}export{D as a,C as b,U as c,W as d,Q as e,Y as f,Z as g,E as h,ee as i,te as j,ne as k,re as l,oe as m,ae as n,j as o,ye as p};
1
+ var D=class{constructor(){this.plugins=new Map;this.commandHandlers=new Map;this.eventListeners=new Set;this.initialized=new Set;}register(e,o){let n=[];if(!e.id)return {success:false,error:"Plugin must have an id"};if(this.plugins.has(e.id))return {success:false,error:`Plugin '${e.id}' is already registered`};if(e.dependencies){for(let t of e.dependencies)if(!this.plugins.has(t))return {success:false,error:`Plugin '${e.id}' requires '${t}' which is not registered`}}if(e.commandHandlers)for(let[t,s]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(t)){let i=this.commandHandlers.get(t);n.push(`Command '${t}' from '${e.id}' overrides handler from '${i.pluginId}'`);}this.commandHandlers.set(t,{pluginId:e.id,handler:s});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let t=e.initialize();t instanceof Promise?t.then(()=>{this.initialized.add(e.id);}).catch(s=>{this.emit({type:"error",pluginId:e.id,error:s});}):this.initialized.add(e.id);}catch(t){this.emit({type:"error",pluginId:e.id,error:t});}return o?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:n.length>0?n:void 0}}unregister(e){let o=this.plugins.get(e);if(!o)return false;for(let[n,t]of this.plugins)if(t.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${n}' depends on it`),false;for(let[n,{pluginId:t}]of this.commandHandlers)t===e&&this.commandHandlers.delete(n);if(o.destroy)try{let n=o.destroy();n instanceof Promise&&n.catch(t=>{this.emit({type:"error",pluginId:e,error:t});});}catch(n){this.emit({type:"error",pluginId:e,error:n});}return this.plugins.delete(e),this.initialized.delete(e),this.emit({type:"unregistered",pluginId:e}),true}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get size(){return this.plugins.size}getCommandHandler(e){return this.commandHandlers.get(e)?.handler}getCommandTypes(){return Array.from(this.commandHandlers.keys())}hasCommandHandler(e){return this.commandHandlers.has(e)}getMcpTools(){let e=[];for(let o of this.plugins.values())o.mcpTools&&e.push(...o.mcpTools);return e}getMcpToolsForPlugin(e){return this.plugins.get(e)?.mcpTools||[]}getMcpTool(e){for(let o of this.plugins.values())if(o.mcpTools){let n=o.mcpTools.find(t=>t.name===e);if(n)return n}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let o of this.eventListeners)try{o(e);}catch(n){console.error("[PluginRegistry] Event listener error:",n);}}clear(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy();}catch{}this.plugins.clear(),this.commandHandlers.clear(),this.initialized.clear();}getDebugInfo(){return {plugins:Array.from(this.plugins.keys()),commandTypes:Array.from(this.commandHandlers.keys()),mcpTools:this.getMcpTools().map(e=>e.name),initialized:Array.from(this.initialized)}}},C=new D;function U(r,e){return r.map(o=>C.register(o,e))}function W(r){return e=>C.register(e,r)}function h(r){return JSON.parse(JSON.stringify(r))}function g(r,e){let o=0;for(let n=0;n<r.content.length;n++)if(r.content[n].type==="paragraph"){if(o===e)return n;o++;}return -1}function y(r){let e="";for(let o of r.content)if(o.type==="run")for(let n of o.content)n.type==="text"&&(e+=n.text);else if(o.type==="hyperlink"){for(let n of o.children)if(n.type==="run")for(let t of n.content)t.type==="text"&&(e+=t.text);}return e}function T(r,e){return {type:"run",formatting:e,content:[{type:"text",text:r}]}}function I(r,e,o,n){let t=[],s=0,i=false;for(let a of r.content)if(a.type==="run"){let p=a.content.filter(l=>l.type==="text").map(l=>l.text).join(""),c=s,u=s+p.length;if(!i&&e>=c&&e<=u){let l=e-c;l>0&&t.push({...a,content:[{type:"text",text:p.slice(0,l)}]}),t.push(T(o,n||a.formatting)),l<p.length&&t.push({...a,content:[{type:"text",text:p.slice(l)}]}),i=true;}else t.push(a);s=u;}else t.push(a);return i||t.push(T(o,n)),t}function d(r,e,o){let n=[],t=0;for(let s of r.content)if(s.type==="run"){let i=s.content.filter(c=>c.type==="text").map(c=>c.text).join(""),a=t,p=t+i.length;if(p<=e||a>=o)n.push(s);else {let c="";a<e&&(c+=i.slice(0,e-a)),p>o&&(c+=i.slice(o-a)),c.length>0&&n.push({...s,content:[{type:"text",text:c}]});}t=p;}else n.push(s);return n}function w(r,e,o,n){let t=[],s=0;for(let i of r.content)if(i.type==="run"){let a=i.content.filter(u=>u.type==="text").map(u=>u.text).join(""),p=s,c=s+a.length;if(c<=e||p>=o)t.push(i);else if(p>=e&&c<=o)t.push({...i,formatting:{...i.formatting,...n}});else {let u=Math.max(e,p),l=Math.min(o,c);p<u&&t.push({...i,content:[{type:"text",text:a.slice(0,u-p)}]}),t.push({...i,formatting:{...i.formatting,...n},content:[{type:"text",text:a.slice(u-p,l-p)}]}),c>l&&t.push({...i,content:[{type:"text",text:a.slice(l-p)}]});}s=c;}else t.push(i);return t}function R(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t];return s.content=I(s,e.position.offset,e.text,e.formatting),o}function _(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset),a.content=I(a,t.offset,e.text,e.formatting);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length),a.content=I(a,t.offset,e.text,e.formatting);let c=[];for(let u=t.paragraphIndex+1;u<=s.paragraphIndex;u++)c.push(g(n,u));for(let u=c.length-1;u>=0;u--)c[u]!==-1&&n.content.splice(c[u],1);}return o}function v(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length);let c=g(n,s.paragraphIndex),u=n.content[c];u.content=d(u,0,s.offset),a.content.push(...u.content);let l=[];for(let f=t.paragraphIndex+1;f<=s.paragraphIndex;f++)l.push(g(n,f));for(let f=l.length-1;f>=0;f--)l[f]!==-1&&n.content.splice(l[f],1);}return o}function S(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=w(a,t.offset,s.offset,e.formatting);}else for(let i=t.paragraphIndex;i<=s.paragraphIndex;i++){let a=g(n,i);if(a===-1)continue;let p=n.content[a],c=y(p),u=0,l=c.length;i===t.paragraphIndex&&(u=t.offset),i===s.paragraphIndex&&(l=s.offset),p.content=w(p,u,l,e.formatting);}return o}function N(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];if(s.formatting={...s.formatting,...e.formatting},"numPr"in e.formatting){let i=e.formatting.numPr;if(i&&i.numId!==void 0&&i.numId!==0){let a=i.ilvl??0,p=i.numId===1,c=p?"\u2022":"1.";if(o.package.numbering){let u=o.package.numbering.nums.find(l=>l.numId===i.numId);if(u){let l=o.package.numbering.abstractNums.find(f=>f.abstractNumId===u.abstractNumId);if(l){let f=l.levels.find(m=>m.ilvl===a);f&&(c=f.lvlText||c);}}}s.listRendering={level:a,numId:i.numId,marker:c,isBullet:p};}else delete s.listRendering;}return o}function A(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];return s.formatting={...s.formatting,styleId:e.styleId},o}function Q(r){return r/1440*96}function Y(r){return r/96*1440}function Z(r){return r==null||isNaN(r)?0:Math.round(r*96/914400)}function E(r){return Math.round(r/96*914400)}function ee(r){return Math.round(r/914400*1440)}function te(r){return Math.round(r/1440*914400)}function ne(r){return r/72*96}function re(r){return r/144*96}function oe(r){return r*2}function X(r,e=2){let o=Math.pow(10,e);return Math.round(r*o)/o}function ae(r){return `${X(r)}px`}function M(r,e){let o=h(r),n=o.package.document,t=[];for(let a=0;a<e.rows;a++){let p=[];for(let c=0;c<e.columns;c++){let u=e.data?.[a]?.[c]||"";p.push({type:"tableCell",content:[{type:"paragraph",content:u?[T(u)]:[]}]});}t.push({type:"tableRow",formatting:a===0&&e.hasHeader?{header:true}:void 0,cells:p});}let s={type:"table",rows:t},i=g(n,e.position.paragraphIndex);return i===-1?n.content.push(s):n.content.splice(i+1,0,s),o}function $(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],a={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:e.src,alt:e.alt,size:{width:E(e.width||100),height:E(e.height||100)},wrap:{type:"inline"}}}]},p=I(s,e.position.offset,"",void 0),c=false,u=0;for(let l=0;l<p.length;l++){let f=p[l];if(f.type==="run"){let m=f.content.filter(x=>x.type==="text").map(x=>x.text).join("");if(u+=m.length,!c&&u>=e.position.offset){p.splice(l+1,0,a),c=true;break}}}return c||p.push(a),s.content=p,o}function B(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex!==s.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i],p=y(a),c=e.displayText||p.slice(t.offset,s.offset);a.content=d(a,t.offset,s.offset);let u={type:"hyperlink",href:e.url,tooltip:e.tooltip,children:[T(c)]},l=false,f=0,m=[];for(let x of a.content)if(x.type==="run"){let b=x.content.filter(P=>P.type==="text").map(P=>P.text).join(""),H=f+b.length;if(!l&&f<=t.offset&&t.offset<=H){let P=t.offset-f;P>0&&m.push({...x,content:[{type:"text",text:b.slice(0,P)}]}),m.push(u),P<b.length&&m.push({...x,content:[{type:"text",text:b.slice(P)}]}),l=true;}else m.push(x);f=H;}else m.push(x);return l||m.push(u),a.content=m,o}function F(r,e){let o=h(r),n=o.package.document,{start:t}=e.range,s=g(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let i=n.content[s],a=[];for(let p of i.content)if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&a.push(c);else a.push(p);return i.content=a,o}function k(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],i=y(s),a=d({content:[...s.content]},e.position.offset,i.length),p=d({content:[...s.content]},0,e.position.offset);s.content=a;let c={type:"paragraph",formatting:s.formatting,content:p};return n.content.splice(t+1,0,c),o}function L(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t],i=[];for(let a=1;a<=e.count;a++){let p=g(n,e.paragraphIndex+a);if(p!==-1){let c=n.content[p];s.content.push(...c.content),i.push(p);}}for(let a=i.length-1;a>=0;a--)n.content.splice(i[a],1);return o}function V(r,e){return k(r,{position:e.position})}function O(r,e){let o=h(r);return o.templateVariables||(o.templateVariables=[]),o.templateVariables.includes(e.name)||o.templateVariables.push(e.name),o}function z(r,e){let o=h(r),n=o.package.document;function t(a){for(let p of a.content)if(p.type==="text")for(let[c,u]of Object.entries(e.values)){let l=new RegExp(`\\{${c}\\}`,"g");p.text=p.text.replace(l,u);}}function s(a){for(let p of a.content)if(p.type==="run")t(p);else if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&t(c);}function i(a){if(a.type==="paragraph")s(a);else if(a.type==="table")for(let p of a.rows)for(let c of p.cells)for(let u of c.content)i(u);}for(let a of n.content)i(a);return o}function j(r,e){let o=C.getCommandHandler(e.type);if(o)return o(r,e);switch(e.type){case "insertText":return R(r,e);case "replaceText":return _(r,e);case "deleteText":return v(r,e);case "formatText":return S(r,e);case "formatParagraph":return N(r,e);case "applyStyle":return A(r,e);case "insertTable":return M(r,e);case "insertImage":return $(r,e);case "insertHyperlink":return B(r,e);case "removeHyperlink":return F(r,e);case "insertParagraphBreak":return k(r,e);case "mergeParagraphs":return L(r,e);case "splitParagraph":return V(r,e);case "setVariable":return O(r,e);case "applyVariables":return z(r,e);default:{let n=e;throw new Error(`Unknown command type: ${n.type}`)}}}function ye(r,e){return e.reduce((o,n)=>j(o,n),r)}export{D as a,C as b,U as c,W as d,Q as e,Y as f,Z as g,E as h,ee as i,te as j,ne as k,re as l,oe as m,ae as n,j as o,ye as p};
@@ -1,8 +1,8 @@
1
- 'use strict';var d=["single","words","double","thick","dotted","dottedHeavy","dash","dashedHeavy","dashLong","dashLongHeavy","dotDash","dashDotHeavy","dotDotDash","dashDotDotHeavy","wave","wavyHeavy","wavyDouble","none"],o=["black","blue","cyan","darkBlue","darkCyan","darkGray","darkGreen","darkMagenta","darkRed","darkYellow","green","lightGray","magenta","red","white","yellow","none"],c={name:"apply_formatting",displayName:"Applying formatting",description:'Apply character formatting (bold, italic, underline, strike, color, highlight, font size, font family) to a paragraph or to a unique phrase within it. Pass `search` to scope the change to part of the paragraph; omit it to format the whole paragraph. Direct edit \u2014 does not create a tracked change. Pass `false` to clear a mark; omit a key to leave it untouched. Color uses `{rgb: "FF0000"}` (no hash) or `{themeColor: "accent1"}`. Font size is in points. Font family takes `{ascii, hAnsi}`.',inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Optional: format only this exact phrase within the paragraph (must be unique)."},marks:{type:"object",description:"Marks to set or clear. Omit a key to leave it untouched.",properties:{bold:{type:"boolean"},italic:{type:"boolean"},underline:{description:'true \u2192 single underline; false \u2192 clear; or { style: "single"|"double"|"thick"|"dotted"|"dottedHeavy"|"dash"|"dashedHeavy"|"dashLong"|"dashLongHeavy"|"dotDash"|"dashDotHeavy"|"dotDotDash"|"dashDotDotHeavy"|"wave"|"wavyHeavy"|"wavyDouble"|"words"|"none" }. Other values are rejected.'},strike:{type:"boolean"},color:{type:"object",description:'Either {rgb: "RRGGBB"} (no hash) or {themeColor: "accent1"|"text1"|...}.',properties:{rgb:{type:"string"},themeColor:{type:"string"}}},highlight:{type:"string",enum:[...o],description:"Highlight color \u2014 must be one of the Word-supported names: "+o.join(", ")+'. Pass "none" to clear. Hex values are rejected (Word does not accept hex for <w:highlight>).'},fontSize:{type:"number",description:"Size in points (e.g. 12, 14, 24)."},fontFamily:{type:"object",properties:{ascii:{type:"string"},hAnsi:{type:"string"}}}}}},required:["paraId","marks"]},handler:(e,r)=>{if(!e.marks||Object.keys(e.marks).length===0)return {success:false,error:"No marks provided. Specify at least one of bold/italic/etc."};let t=typeof e.marks.underline=="object"&&e.marks.underline!==null?e.marks.underline.style:void 0;if(t&&!d.includes(t))return {success:false,error:`Invalid underline.style "${t}". Must be one of: ${d.join(", ")}.`};let n=typeof e.marks.highlight=="string"?e.marks.highlight:void 0;if(n&&!o.includes(n))return {success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`};let a=n==="none"?{...e.marks,highlight:""}:e.marks;return r.applyFormatting({paraId:e.paraId,search:e.search,marks:a})?{success:true,data:`Formatting applied to ${e.search?`"${e.search}" in ${e.paraId}`:e.paraId}.`}:{success:false,error:"Could not apply formatting. The paraId may not exist, or `search` is missing / ambiguous."}}},p={name:"set_paragraph_style",displayName:"Setting paragraph style",description:`Apply a paragraph style by id (e.g. "Heading1", "Heading2", "Title", "Quote", "Normal"). The styleId must exist in the document's style definitions \u2014 unknown ids are no-ops. Direct edit, not a tracked change.`,inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},styleId:{type:"string",description:'Style id (e.g. "Heading1", "Title", "Quote", "Normal").'}},required:["paraId","styleId"]},handler:(e,r)=>r.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})?{success:true,data:`Style "${e.styleId}" applied to ${e.paraId}.`}:{success:false,error:`Could not set style. paraId "${e.paraId}" not found, or styleId "${e.styleId}" is not defined.`}};var l={name:"read_page",displayName:"Reading page",description:`Read the contents of one rendered page (1-indexed). Returns paragraphs on the page, each tagged with its stable paraId. Use this when the user asks "summarize page 3" or "comment on what's on this page".`,inputSchema:{type:"object",properties:{pageNumber:{type:"number",description:"1-indexed page number."}},required:["pageNumber"]},handler:(e,r)=>{let t=r.getPage(e.pageNumber);if(!t){let n=r.getTotalPages();return n===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`Page ${e.pageNumber} does not exist (document has ${n} page${n===1?"":"s"}).`}}return {success:true,data:t.text||"(empty page)"}}},m={name:"read_pages",displayName:"Reading pages",description:"Read a contiguous range of rendered pages (1-indexed, inclusive). Returns paragraphs across the range, each tagged with paraId. Cheaper than calling read_page repeatedly \u2014 single round-trip.",inputSchema:{type:"object",properties:{from:{type:"number",description:"1-indexed start page (inclusive)."},to:{type:"number",description:"1-indexed end page (inclusive)."}},required:["from","to"]},handler:(e,r)=>{let t=r.getPages({from:e.from,to:e.to});if(t.length===0){let a=r.getTotalPages();return a===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`No pages in range ${e.from}\u2013${e.to} (document has ${a} page${a===1?"":"s"}).`}}return {success:true,data:t.map(a=>`--- Page ${a.pageNumber} ---
1
+ 'use strict';var c=["single","words","double","thick","dotted","dottedHeavy","dash","dashedHeavy","dashLong","dashLongHeavy","dotDash","dashDotHeavy","dotDotDash","dashDotDotHeavy","wave","wavyHeavy","wavyDouble","none"],o=["black","blue","cyan","darkBlue","darkCyan","darkGray","darkGreen","darkMagenta","darkRed","darkYellow","green","lightGray","magenta","red","white","yellow","none"],p={name:"apply_formatting",displayName:"Applying formatting",description:'Apply character formatting (bold, italic, underline, strike, color, highlight, font size, font family) to a paragraph or to a unique phrase within it. Pass `search` to scope the change to part of the paragraph; omit it to format the whole paragraph. Direct edit \u2014 does not create a tracked change. Pass `false` to clear a mark; omit a key to leave it untouched. Color uses `{rgb: "FF0000"}` (no hash) or `{themeColor: "accent1"}`. Font size is in points. Font family takes `{ascii, hAnsi}`.',inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Optional: format only this exact phrase within the paragraph (must be unique)."},marks:{type:"object",description:"Marks to set or clear. Omit a key to leave it untouched.",properties:{bold:{type:"boolean"},italic:{type:"boolean"},underline:{description:'true \u2192 single underline; false \u2192 clear; or { style: "single"|"double"|"thick"|"dotted"|"dottedHeavy"|"dash"|"dashedHeavy"|"dashLong"|"dashLongHeavy"|"dotDash"|"dashDotHeavy"|"dotDotDash"|"dashDotDotHeavy"|"wave"|"wavyHeavy"|"wavyDouble"|"words"|"none" }. Other values are rejected.'},strike:{type:"boolean"},color:{type:"object",description:'Either {rgb: "RRGGBB"} (no hash) or {themeColor: "accent1"|"text1"|...}.',properties:{rgb:{type:"string"},themeColor:{type:"string"}}},highlight:{type:"string",enum:[...o],description:"Highlight color \u2014 must be one of the Word-supported names: "+o.join(", ")+'. Pass "none" to clear. Hex values are rejected (Word does not accept hex for <w:highlight>).'},fontSize:{type:"number",description:"Size in points (e.g. 12, 14, 24)."},fontFamily:{type:"object",properties:{ascii:{type:"string"},hAnsi:{type:"string"}}}}}},required:["paraId","marks"]},handler:(e,r)=>{if(!e.marks||Object.keys(e.marks).length===0)return {success:false,error:"No marks provided. Specify at least one of bold/italic/etc."};let t=typeof e.marks.underline=="object"&&e.marks.underline!==null?e.marks.underline.style:void 0;if(t&&!c.includes(t))return {success:false,error:`Invalid underline.style "${t}". Must be one of: ${c.join(", ")}.`};let n=typeof e.marks.highlight=="string"?e.marks.highlight:void 0;if(n&&!o.includes(n))return {success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`};let a=n==="none"?{...e.marks,highlight:""}:e.marks;return r.applyFormatting({paraId:e.paraId,search:e.search,marks:a})?{success:true,data:`Formatting applied to ${e.search?`"${e.search}" in ${e.paraId}`:e.paraId}.`}:{success:false,error:"Could not apply formatting. The paraId may not exist, or `search` is missing / ambiguous."}}},m={name:"set_paragraph_style",displayName:"Setting paragraph style",description:`Apply a paragraph style by id (e.g. "Heading1", "Heading2", "Title", "Quote", "Normal"). The styleId must exist in the document's style definitions \u2014 unknown ids are no-ops. Direct edit, not a tracked change.`,inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},styleId:{type:"string",description:'Style id (e.g. "Heading1", "Title", "Quote", "Normal").'}},required:["paraId","styleId"]},handler:(e,r)=>r.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})?{success:true,data:`Style "${e.styleId}" applied to ${e.paraId}.`}:{success:false,error:`Could not set style. paraId "${e.paraId}" not found, or styleId "${e.styleId}" is not defined.`}};var i=["page","sectionNextPage","sectionContinuous"],u={page:"Page break",sectionNextPage:"Section break (next page)",sectionContinuous:"Section break (continuous)"},l={name:"insert_break",displayName:"Inserting break",description:'Insert a break after a paragraph (located by paraId). `type: "page"` adds a page break so following content starts on a new page. `type: "sectionNextPage"` starts a new document section on a new page. `type: "sectionContinuous"` starts a new section on the same page (use this to change column layout or margins from that point onward). The target paragraph becomes the end of its page/section and the next paragraph begins the new one. Direct edit \u2014 not a tracked change.',inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text. The break is inserted after this paragraph."},type:{type:"string",enum:[...i],description:'Break kind: "page" (page break), "sectionNextPage" (new section, new page), or "sectionContinuous" (new section, same page).'}},required:["paraId","type"]},handler:(e,r)=>i.includes(e.type)?r.insertBreak({paraId:e.paraId,type:e.type})?{success:true,data:`${u[e.type]} inserted after ${e.paraId}.`}:{success:false,error:`Could not insert break. paraId "${e.paraId}" not found.`}:{success:false,error:`Invalid break type "${e.type}". Must be one of: ${i.join(", ")}.`}};var g={name:"read_page",displayName:"Reading page",description:`Read the contents of one rendered page (1-indexed). Returns paragraphs on the page, each tagged with its stable paraId. Use this when the user asks "summarize page 3" or "comment on what's on this page".`,inputSchema:{type:"object",properties:{pageNumber:{type:"number",description:"1-indexed page number."}},required:["pageNumber"]},handler:(e,r)=>{let t=r.getPage(e.pageNumber);if(!t){let n=r.getTotalPages();return n===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`Page ${e.pageNumber} does not exist (document has ${n} page${n===1?"":"s"}).`}}return {success:true,data:t.text||"(empty page)"}}},h={name:"read_pages",displayName:"Reading pages",description:"Read a contiguous range of rendered pages (1-indexed, inclusive). Returns paragraphs across the range, each tagged with paraId. Cheaper than calling read_page repeatedly \u2014 single round-trip.",inputSchema:{type:"object",properties:{from:{type:"number",description:"1-indexed start page (inclusive)."},to:{type:"number",description:"1-indexed end page (inclusive)."}},required:["from","to"]},handler:(e,r)=>{let t=r.getPages({from:e.from,to:e.to});if(t.length===0){let a=r.getTotalPages();return a===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`No pages in range ${e.from}\u2013${e.to} (document has ${a} page${a===1?"":"s"}).`}}return {success:true,data:t.map(a=>`--- Page ${a.pageNumber} ---
2
2
  ${a.text||"(empty page)"}`).join(`
3
3
 
4
- `)}}};var h={name:"read_document",displayName:"Reading document",description:'Read the document content. Returns lines tagged with a stable paragraph id, e.g. "[2A1F3B] First paragraph". Use the bracketed id as `paraId` when commenting or suggesting changes \u2014 it survives edits, unlike ordinal indices. Returns the vanilla document (the doc as it exists right now, before any tracked suggestions are accepted): pending insertions are HIDDEN, pending deletions are shown as plain text (still part of the document until accepted), and comment markers are stripped. Use read_changes / read_comments to inspect what is pending.',inputSchema:{type:"object",properties:{fromIndex:{type:"number",description:"Start ordinal index (inclusive). Optional."},toIndex:{type:"number",description:"End ordinal index (inclusive). Optional."}}},handler:(e,r)=>({success:true,data:r.getContentAsText({fromIndex:e.fromIndex,toIndex:e.toIndex,includeTrackedChanges:false,includeCommentAnchors:false})})},g={name:"read_selection",displayName:"Reading selection",description:'Read the user\'s current cursor or selection. Returns the selected text, the paragraph it lives in, and that paragraph\'s `paraId`. Use this when the user asks "fix this" or "review what I have selected".',inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getSelection();return t?{success:true,data:t}:{success:false,error:"No selection (editor not focused)."}}},u={name:"find_text",displayName:"Finding text",description:"Locate paragraphs containing `query`. Returns up to `limit` handles, each with `paraId`, the matched substring, and surrounding context. Pass any returned `paraId` (and the `match` as `search`) to add_comment / suggest_change.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Text to find (substring match)."},caseSensitive:{type:"boolean",description:"Default: false."},limit:{type:"number",description:"Max paragraphs to return. Default: 20."}},required:["query"]},handler:(e,r)=>{let t=r.findText(e.query,{caseSensitive:e.caseSensitive,limit:e.limit});return t.length===0?{success:true,data:"No matches."}:{success:true,data:t}}},y={name:"read_comments",displayName:"Reading comments",description:"List all comments in the document with their paragraph anchors.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getComments();return t.length===0?{success:true,data:"No comments."}:{success:true,data:t.map(a=>`[Comment #${a.id}] ${a.author}: "${a.text}"`+(a.anchoredText?` (anchored to: "${a.anchoredText}")`:"")+(a.replies.length>0?`
4
+ `)}}};var y={name:"read_document",displayName:"Reading document",description:'Read the document content. Returns lines tagged with a stable paragraph id, e.g. "[2A1F3B] First paragraph". Use the bracketed id as `paraId` when commenting or suggesting changes \u2014 it survives edits, unlike ordinal indices. Returns the vanilla document (the doc as it exists right now, before any tracked suggestions are accepted): pending insertions are HIDDEN, pending deletions are shown as plain text (still part of the document until accepted), and comment markers are stripped. Use read_changes / read_comments to inspect what is pending.',inputSchema:{type:"object",properties:{fromIndex:{type:"number",description:"Start ordinal index (inclusive). Optional."},toIndex:{type:"number",description:"End ordinal index (inclusive). Optional."}}},handler:(e,r)=>({success:true,data:r.getContentAsText({fromIndex:e.fromIndex,toIndex:e.toIndex,includeTrackedChanges:false,includeCommentAnchors:false})})},f={name:"read_selection",displayName:"Reading selection",description:'Read the user\'s current cursor or selection. Returns the selected text, the paragraph it lives in, and that paragraph\'s `paraId`. Use this when the user asks "fix this" or "review what I have selected".',inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getSelection();return t?{success:true,data:t}:{success:false,error:"No selection (editor not focused)."}}},b={name:"find_text",displayName:"Finding text",description:"Locate paragraphs containing `query`. Returns up to `limit` handles, each with `paraId`, the matched substring, and surrounding context. Pass any returned `paraId` (and the `match` as `search`) to add_comment / suggest_change.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Text to find (substring match)."},caseSensitive:{type:"boolean",description:"Default: false."},limit:{type:"number",description:"Max paragraphs to return. Default: 20."}},required:["query"]},handler:(e,r)=>{let t=r.findText(e.query,{caseSensitive:e.caseSensitive,limit:e.limit});return t.length===0?{success:true,data:"No matches."}:{success:true,data:t}}},I={name:"read_comments",displayName:"Reading comments",description:"List all comments in the document with their paragraph anchors.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getComments();return t.length===0?{success:true,data:"No comments."}:{success:true,data:t.map(a=>`[Comment #${a.id}] ${a.author}: "${a.text}"`+(a.anchoredText?` (anchored to: "${a.anchoredText}")`:"")+(a.replies.length>0?`
5
5
  `+a.replies.map(s=>` Reply by ${s.author}: "${s.text}"`).join(`
6
6
  `):"")).join(`
7
- `)}}},f={name:"read_changes",displayName:"Reading changes",description:"List tracked changes (insertions / deletions) currently in the document.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getChanges();return t.length===0?{success:true,data:"No tracked changes."}:{success:true,data:t.map(a=>`[Change #${a.id}] ${a.type} by ${a.author}: "${a.text}"`).join(`
8
- `)}}},b={name:"add_comment",displayName:"Adding comment",description:"Attach a comment to a paragraph, optionally anchored to a unique phrase within it. The user sees it instantly in the comments sidebar.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},text:{type:"string",description:"Comment body."},search:{type:"string",description:"Optional: anchor to this exact phrase within the paragraph. Must be unique."}},required:["paraId","text"]},handler:(e,r)=>{let t=r.addComment({paraId:e.paraId,text:e.text,search:e.search});return t===null?{success:false,error:"Could not add comment. The paraId may not exist, or `search` is missing / ambiguous."}:{success:true,data:`Comment ${t} added on ${e.paraId}.`}}},I={name:"suggest_change",displayName:"Suggesting change",description:"Suggest a tracked change. Three modes: (1) replacement \u2014 `search` non-empty, `replaceWith` non-empty; (2) deletion \u2014 `search` non-empty, `replaceWith` empty; (3) insertion at paragraph end \u2014 `search` empty, `replaceWith` non-empty. The user can accept or reject in the editor UI.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Phrase to find (must be unique). Empty string = insert at paragraph end."},replaceWith:{type:"string",description:"Replacement text. Empty string = delete the matched phrase."}},required:["paraId","search","replaceWith"]},handler:(e,r)=>r.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith})?e.search?e.replaceWith?{success:true,data:`Replacement proposed: "${e.search}" \u2192 "${e.replaceWith}" on ${e.paraId}.`}:{success:true,data:`Deletion proposed: "${e.search}" on ${e.paraId}.`}:{success:true,data:`Insertion proposed on ${e.paraId}.`}:{success:false,error:"Could not propose change. Possible causes: paraId not found; search missing or ambiguous; or the target overlaps an existing tracked change."}},x={name:"reply_comment",displayName:"Replying to comment",description:"Reply to an existing comment by id. Threaded under the original.",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."},text:{type:"string",description:"Reply body."}},required:["commentId","text"]},handler:(e,r)=>{let t=r.replyTo(e.commentId,{text:e.text});return t===null?{success:false,error:`Comment #${e.commentId} not found.`}:{success:true,data:`Reply ${t} added to comment ${e.commentId}.`}}},k={name:"resolve_comment",displayName:"Resolving comment",description:"Mark a comment as resolved (done).",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."}},required:["commentId"]},handler:(e,r)=>(r.resolveComment(e.commentId),{success:true,data:`Comment ${e.commentId} resolved.`})},v={name:"scroll",displayName:"Scrolling",description:"Scroll the editor to a paragraph by paraId. Does not move the user's cursor.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."}},required:["paraId"]},handler:(e,r)=>r.scrollTo(e.paraId)?{success:true,data:`Scrolled to ${e.paraId}.`}:{success:false,error:`paraId ${e.paraId} not found.`}},i=[h,g,l,m,u,y,f,b,I,c,p,x,k,v];function _(e,r,t){let n=i.find(a=>a.name===e);if(!n)return {success:false,error:`Unknown tool: ${e}`};try{return n.handler(r,t)}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}function N(e){let r=i.find(n=>n.name===e);if(r?.displayName)return r.displayName;let t=e.replace(/_/g," ");return t.charAt(0).toUpperCase()+t.slice(1)}function w(){return i.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}exports.a=i;exports.b=_;exports.c=N;exports.d=w;
7
+ `)}}},x={name:"read_changes",displayName:"Reading changes",description:"List tracked changes (insertions / deletions) currently in the document.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getChanges();return t.length===0?{success:true,data:"No tracked changes."}:{success:true,data:t.map(a=>`[Change #${a.id}] ${a.type} by ${a.author}: "${a.text}"`).join(`
8
+ `)}}},k={name:"add_comment",displayName:"Adding comment",description:"Attach a comment to a paragraph, optionally anchored to a unique phrase within it. The user sees it instantly in the comments sidebar.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},text:{type:"string",description:"Comment body."},search:{type:"string",description:"Optional: anchor to this exact phrase within the paragraph. Must be unique."}},required:["paraId","text"]},handler:(e,r)=>{let t=r.addComment({paraId:e.paraId,text:e.text,search:e.search});return t===null?{success:false,error:"Could not add comment. The paraId may not exist, or `search` is missing / ambiguous."}:{success:true,data:`Comment ${t} added on ${e.paraId}.`}}},T={name:"suggest_change",displayName:"Suggesting change",description:"Suggest a tracked change. Three modes: (1) replacement \u2014 `search` non-empty, `replaceWith` non-empty; (2) deletion \u2014 `search` non-empty, `replaceWith` empty; (3) insertion at paragraph end \u2014 `search` empty, `replaceWith` non-empty. The user can accept or reject in the editor UI.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Phrase to find (must be unique). Empty string = insert at paragraph end."},replaceWith:{type:"string",description:"Replacement text. Empty string = delete the matched phrase."}},required:["paraId","search","replaceWith"]},handler:(e,r)=>r.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith})?e.search?e.replaceWith?{success:true,data:`Replacement proposed: "${e.search}" \u2192 "${e.replaceWith}" on ${e.paraId}.`}:{success:true,data:`Deletion proposed: "${e.search}" on ${e.paraId}.`}:{success:true,data:`Insertion proposed on ${e.paraId}.`}:{success:false,error:"Could not propose change. Possible causes: paraId not found; search missing or ambiguous; or the target overlaps an existing tracked change."}},v={name:"reply_comment",displayName:"Replying to comment",description:"Reply to an existing comment by id. Threaded under the original.",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."},text:{type:"string",description:"Reply body."}},required:["commentId","text"]},handler:(e,r)=>{let t=r.replyTo(e.commentId,{text:e.text});return t===null?{success:false,error:`Comment #${e.commentId} not found.`}:{success:true,data:`Reply ${t} added to comment ${e.commentId}.`}}},$={name:"resolve_comment",displayName:"Resolving comment",description:"Mark a comment as resolved (done).",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."}},required:["commentId"]},handler:(e,r)=>(r.resolveComment(e.commentId),{success:true,data:`Comment ${e.commentId} resolved.`})},D={name:"scroll",displayName:"Scrolling",description:"Scroll the editor to a paragraph by paraId. Does not move the user's cursor.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."}},required:["paraId"]},handler:(e,r)=>r.scrollTo(e.paraId)?{success:true,data:`Scrolled to ${e.paraId}.`}:{success:false,error:`paraId ${e.paraId} not found.`}},d=[y,f,g,h,b,I,x,k,T,p,m,l,v,$,D];function j(e,r,t){let n=d.find(a=>a.name===e);if(!n)return {success:false,error:`Unknown tool: ${e}`};try{return n.handler(r,t)}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}function P(e){let r=d.find(n=>n.name===e);if(r?.displayName)return r.displayName;let t=e.replace(/_/g," ");return t.charAt(0).toUpperCase()+t.slice(1)}function H(){return d.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}exports.a=d;exports.b=j;exports.c=P;exports.d=H;
@@ -0,0 +1,5 @@
1
+ 'use strict';var chunkRTU2ZS7R_js=require('./chunk-RTU2ZS7R.js'),chunkMMJQ47Q7_js=require('./chunk-MMJQ47Q7.js');function h(o){return o.type==="insertion"||o.type==="deletion"||o.type==="moveFrom"||o.type==="moveTo"}function C(o){let t=[];for(let r of o)r.type==="run"?t.push(chunkRTU2ZS7R_js.H(r)):r.type==="hyperlink"&&t.push(chunkRTU2ZS7R_js.I(r));return t.join("")}function R(o,t){let r=0;for(let n of o.content)if(n.type==="paragraph"){if(r===t)return n;r++;}else if(n.type==="table"){for(let a of n.rows)for(let e of a.cells)for(let i of e.content)if(i.type==="paragraph"){if(r===t)return i;r++;}}else r++;throw new Error(`Paragraph index ${t} out of bounds (max: ${r-1})`)}function A(o,t,r){let n=0;for(let a of o)if(a.type==="paragraph"){if(r(a,n)===false)return;n++;}else if(a.type==="table"){for(let e of a.rows)for(let i of e.cells)for(let s of i.content)if(s.type==="paragraph"){if(r(s,n)===false)return;n++;}}else t&&n++;}function m(o,t){A(o.content,true,t);}function k(o,t){A(o.content,false,t);}function fe(o,t={}){let{fromIndex:r,toIndex:n,includeTrackedChanges:a=true,includeCommentAnchors:e=true}=t,i=[],s=0;for(let u of o.content)if(u.type==="paragraph")L(s,r,n)&&i.push(Q(u,s,a,e)),s++;else if(u.type==="table"){L(s,r,n)&&i.push(V(u,s,a,e));for(let l of u.rows)for(let c of l.cells)for(let f of c.content)f.type==="paragraph"&&s++;}else s++;return i}function L(o,t,r){return (t===void 0||o>=t)&&(r===void 0||o<=r)}function Q(o,t,r,n){let a=j(o,r,n),e=o.formatting?.styleId,i=o.paraId;return chunkRTU2ZS7R_js.U(e)?{type:"heading",index:t,paraId:i,level:chunkRTU2ZS7R_js.V(e)??1,text:a}:o.listRendering?{type:"list-item",index:t,paraId:i,text:a,listLevel:o.listRendering.level??0,listType:o.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:t,paraId:i,text:a}}function V(o,t,r,n){let a=[],e=[];for(let i of o.rows){let s=[],u=[];for(let l of i.cells){let c=[],f;for(let d of l.content)d.type==="paragraph"&&(f===void 0&&(f=d.paraId),c.push(j(d,r,n)));s.push(c.join(`
2
+ `)),u.push(f);}a.push(s),e.push(u);}return {type:"table",index:t,rows:a,cellParaIds:e}}function pe(o){let t=[],r=n=>n.paraId?n.paraId:String(n.index);for(let n of o)switch(n.type){case "heading":t.push(`[${r(n)}] (h${n.level}) ${n.text}`);break;case "paragraph":t.push(`[${r(n)}] ${n.text}`);break;case "list-item":{let a=" ".repeat(n.listLevel),e=n.listType==="bullet"?"\u2022":"-";t.push(`[${r(n)}] ${a}${e} ${n.text}`);break}case "table":{let a=n.index;for(let e=0;e<n.rows.length;e++)for(let i=0;i<n.rows[e].length;i++){let u=n.rows[e][i].split(`
3
+ `),l=n.cellParaIds?.[e]?.[i];for(let c=0;c<u.length;c++){let f=c===0&&l?l:String(a);t.push(`[${f}] (table, row ${e+1}, col ${i+1}) ${u[c]}`),a++;}}break}}return t.join(`
4
+ `)}function j(o,t,r){let n=[],a=new Set;for(let e of o.content){if(e.type==="commentRangeStart"&&r){a.add(e.id),n.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&r){a.has(e.id)&&(a.delete(e.id),n.push("[/comment]"));continue}if(e.type==="run")n.push(chunkRTU2ZS7R_js.H(e));else if(e.type==="hyperlink")n.push(chunkRTU2ZS7R_js.I(e));else if(h(e)){let i=C(e.content);e.type==="insertion"||e.type==="moveTo"?t&&n.push(`[+${i}+]{by:${e.info.author}}`):t?n.push(`[-${i}-]{by:${e.info.author}}`):n.push(i);}}return n.join("")}var T=class extends Error{constructor(t,r){let n=r!==void 0?` in paragraph ${r}`:" in document";super(`Text not found${n}: "${t}"`),this.name="TextNotFoundError";}},H=class extends Error{constructor(t){super(`Tracked change not found: id=${t}`),this.name="ChangeNotFoundError";}},I=class extends Error{constructor(t){super(`Comment not found: id=${t}`),this.name="CommentNotFoundError";}};function U(o){let t=[],r=0;for(let n=0;n<o.content.length;n++){let a=o.content[n];if(a.type==="run"){let e=chunkRTU2ZS7R_js.H(a);t.push({contentIndex:n,run:a,text:e,startPos:r}),r+=e.length;}else if(a.type==="hyperlink")for(let e=0;e<a.children.length;e++){let i=a.children[e];if(i.type==="run"){let s=chunkRTU2ZS7R_js.H(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}}else if(h(a)){if(a.type==="insertion"||a.type==="moveTo")continue;for(let e=0;e<a.content.length;e++){let i=a.content[e];if(i.type==="run"){let s=chunkRTU2ZS7R_js.H(i);t.push({contentIndex:n,run:i,text:s,startPos:r}),r+=s.length;}else if(i.type==="hyperlink"){for(let s of i.children)if(s.type==="run"){let u=chunkRTU2ZS7R_js.H(s);t.push({contentIndex:n,run:s,text:u,startPos:r}),r+=u.length;}}}}}return t}function w(o){return U(o).map(t=>t.text).join("")}function Y(o,t,r){let n=U(o),a=n.map(c=>c.text).join(""),e=Z(a,t);if(!e)throw new T(t,r);let i=-1,s=0;for(let c=0;c<n.length;c++)if(e.start<n[c].startPos+n[c].text.length){i=c,s=e.start-n[c].startPos;break}let u=-1,l=0;for(let c=n.length-1;c>=0;c--)if(e.end>n[c].startPos){u=c,l=e.end-n[c].startPos;break}if(i===-1||u===-1)throw new T(t,r);return {startRunIndex:n[i].contentIndex,startOffset:s,endRunIndex:n[u].contentIndex,endOffset:l}}function xe(o,t,r){let n=Y(o,t,r),{startRunIndex:a,endRunIndex:e}=n,{startOffset:i,endOffset:s}=n,u=o.content[e];if(u.type==="run"){let c=chunkRTU2ZS7R_js.H(u);if(s<c.length){let f=N(c.slice(s),u);z(u,c.slice(0,s)),o.content.splice(e+1,0,f);}}let l=o.content[a];if(l.type==="run"&&i>0){let c=chunkRTU2ZS7R_js.H(l),f=N(c.slice(0,i),l);z(l,c.slice(i)),o.content.splice(a,0,f),a++,e++;}return {startIndex:a,endIndex:e}}function N(o,t){return {type:"run",content:[{type:"text",text:o}],formatting:t.formatting?{...t.formatting}:void 0}}function z(o,t){let r=o.content.find(n=>n.type==="text");r&&(r.text=t);}function W(o){let t=[],r=[],n=true;for(let a=0;a<o.length;a++){let e=o[a];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(e)){if("\u201C\u201D\u201E\u201F".includes(e)&&(e='"'),"\u2018\u2019\u201A\u201B".includes(e)&&(e="'"),"\u2013\u2014\u2012\u2015".includes(e)&&(e="-"),e==="\u2026"){t.push(".",".","."),r.push(a,a,a),n=false;continue}if(/\s/.test(e)||e==="\xA0"){n||(t.push(" "),r.push(a),n=true);continue}t.push(e.toLowerCase()),r.push(a),n=false;}}return t.length>0&&t[t.length-1]===" "&&(t.pop(),r.pop()),{text:t.join(""),posMap:r}}function G(o,t,r,n){let a=o.posMap[t],e=o.posMap[t+r-1]+1;for(;e<n.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(n[e]);)e++;return {start:a,end:e}}function Z(o,t){if(!t||!o)return null;let r=o.indexOf(t);if(r!==-1)return {start:r,end:r+t.length};let n=W(o),a=W(t);if(!a.text)return null;let e=n.text.indexOf(a.text);if(e!==-1)return G(n,e,a.text.length,o);let i=a.text.split(" ");if(i.length>=3)for(let s=1;s<=Math.min(2,i.length-2);s++){let u=i.slice(0,-s).join(" "),l=n.text.indexOf(u);if(l!==-1)return G(n,l,u.length,o)}return null}function Te(o,t,r){let n=new Map,a=(i,s,u)=>{let l=null;for(let c of i.content)if(h(c)){l===null&&(l=w(i));let f=C(c.content),d=c.info.id,x=`${u.noteType??"body"}:${u.noteId??""}:${d}`,y=n.get(x);y&&y.paragraphIndex===s?y.text+=f:n.set(x,{id:d,type:c.type,author:c.info.author,date:c.info.date??null,text:f,context:l,paragraphIndex:s,...u.noteId!==void 0?{noteId:u.noteId}:{},...u.noteType!==void 0?{noteType:u.noteType}:{}});}};if(m(o,(i,s)=>a(i,s,{})),t?.includeFootnotes&&r?.footnotes)for(let i of r.footnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"footnote"}));if(t?.includeEndnotes&&r?.endnotes)for(let i of r.endnotes)k(i,(s,u)=>a(s,u,{noteId:i.id,noteType:"endnote"}));return Array.from(n.values()).filter(i=>!(t?.author&&i.author!==t.author||t?.type&&i.type!==t.type))}function Pe(o,t){let r=o.comments??[];if(r.length===0)return [];let n=_(o),a=[],e=new Map;for(let s of r)if(s.parentId!==void 0){let u=e.get(s.parentId)??[];u.push(s),e.set(s.parentId,u);}else a.push(s);return a.map(s=>{let u=n.get(s.id),l=(e.get(s.id)??[]).map(c=>({id:c.id,author:c.author,date:c.date??null,text:X(c)}));return {id:s.id,author:s.author,date:s.date??null,text:X(s),anchoredText:u?.text??"",paragraphIndex:u?.paragraphIndex??-1,replies:l,done:s.done??false}}).filter(s=>!(t?.author&&s.author!==t.author||t?.done!==void 0&&s.done!==t.done))}function X(o){return o.content.map(t=>w(t)).join(`
5
+ `)}function _(o){let t=new Map,r=new Map;return m(o,(n,a)=>{for(let e of n.content)if(e.type==="commentRangeStart")r.set(e.id,{paragraphIndex:a,parts:[]});else if(e.type==="commentRangeEnd"){let i=r.get(e.id);i&&(t.set(e.id,{text:i.parts.join(""),paragraphIndex:i.paragraphIndex}),r.delete(e.id));}else if(e.type==="run"){let i=chunkRTU2ZS7R_js.H(e);for(let s of r.values())s.parts.push(i);}else if(e.type==="hyperlink"){let i=e.children.filter(s=>s.type==="run").map(chunkRTU2ZS7R_js.H).join("");for(let s of r.values())s.parts.push(i);}else if(h(e)){if(e.type==="insertion"||e.type==="moveTo")continue;let i=C(e.content);for(let s of r.values())s.parts.push(i);}}),t}function q(o){let t=o.toDocument().package?.document;if(!t)return new Map;let r=new Map;return m(t,(n,a)=>{r.set(n.paraId??String(a),a),r.set(String(a),a);}),r}function ee(o){let t=[],r=n=>{for(let a of n.content)a.type==="text"&&t.push(a.text??"");};for(let n of o.content)if(n.type==="run")r(n);else if(n.type==="hyperlink")for(let a of n.children)a.type==="run"&&r(a);else if(n.type==="deletion"||n.type==="moveFrom"){for(let a of n.content)if(a.type==="run")r(a);else if(a.type==="hyperlink")for(let e of a.children)e.type==="run"&&r(e);}return t.join("")}function B(o,t){let n={type:"run",content:[{type:"text",text:t,preserveSpace:/^\s|\s$/.test(t)}]};return o.formatting&&(n.formatting={...o.formatting}),o.propertyChanges&&(n.propertyChanges=[...o.propertyChanges]),n}function te(o){return o.content.map(t=>t.type==="text"?t.text:"").join("")}function M(o,t,r,n,a){let e=te(o);if(!e)return;let i=a.value,s=i+e.length;n.push({run:o,parent:t,index:r,text:e,start:i,end:s}),a.value=s;}function J(o,t,r){o.children.forEach((n,a)=>{n.type==="run"&&M(n,o.children,a,t,r);});}function D(o,t){let r=[],n={value:0};return o.content.forEach((a,e)=>{a.type==="run"?M(a,o.content,e,r,n):a.type==="hyperlink"?J(a,r,n):(a.type==="deletion"||a.type==="moveFrom"||t&&(a.type==="insertion"||a.type==="moveTo"))&&a.content.forEach((i,s)=>{i.type==="run"?M(i,a.content,s,r,n):i.type==="hyperlink"&&J(i,r,n);});}),r}function ne(o,t){let r={...o??{}};t.bold!==void 0&&(r.bold=t.bold||void 0),t.italic!==void 0&&(r.italic=t.italic||void 0),t.underline!==void 0&&(t.underline?r.underline={style:typeof t.underline=="object"&&t.underline.style?t.underline.style:"single"}:delete r.underline),t.strike!==void 0&&(r.strike=t.strike||void 0),t.color!==void 0&&(t.color&&(t.color.rgb||t.color.themeColor)?r.color={rgb:t.color.rgb,themeColor:t.color.themeColor}:delete r.color),t.highlight!==void 0&&(t.highlight?r.highlight=chunkRTU2ZS7R_js.va(t.highlight)||t.highlight:delete r.highlight),t.fontSize!==void 0&&(t.fontSize>0?r.fontSize=chunkMMJQ47Q7_js.m(t.fontSize):delete r.fontSize),t.fontFamily!==void 0&&(t.fontFamily&&(t.fontFamily.ascii||t.fontFamily.hAnsi)?r.fontFamily={ascii:t.fontFamily.ascii,hAnsi:t.fontFamily.hAnsi??t.fontFamily.ascii}:delete r.fontFamily);for(let n of Object.keys(r))r[n]===void 0&&delete r[n];return Object.keys(r).length>0?r:void 0}function S(o,t){o.formatting=ne(o.formatting,t);}function oe(o,t,r,n){let a=o.run.content.every(s=>s.type==="text");if(t<=0&&r>=o.text.length||!a){S(o.run,n);return}let e=[];t>0&&e.push(B(o.run,o.text.slice(0,t)));let i=B(o.run,o.text.slice(t,r));S(i,n),e.push(i),r<o.text.length&&e.push(B(o.run,o.text.slice(r))),o.parent.splice(o.index,1,...e);}function re(o,t,r,n){let e=D(o,false).filter(i=>i.start<r&&i.end>t);if(e.length===0)return true;for(let i=e.length-1;i>=0;i--){let s=e[i];oe(s,Math.max(0,t-s.start),Math.min(s.text.length,r-s.start),n);}return true}function ae(o,t){let r=D(o,true);for(let n of r)S(n.run,t);return true}function ie(o,t){if(!t)return null;let n=D(o,false).map(e=>e.text).join(""),a=n.indexOf(t);return a===-1||n.indexOf(t,a+1)!==-1?null:{from:a,to:a+t.length}}function se(o,t){return o?!!o.styles?.some(r=>r.styleId===t&&r.type==="paragraph"):true}function ke(o){let t=new Set,r=null;function n(){return r===null&&(r=q(o)),r}function a(){if(t.size===0)return;let e=o.getComments(),i=o.getChanges(),s={commentCount:e.length,changeCount:i.length,comments:e,changes:i};for(let u of t)try{u(s);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return o.getContentAsText(e)},getContent(e){return o.getContent(e)},getComments(e){return o.getComments(e)},getChanges(e){return o.getChanges(e)},findText(e,i){if(!e)return [];let s=i?.caseSensitive??false,u=i?.limit??20,l=s?e:e.toLowerCase(),c=o.toDocument().package?.document;if(!c)return [];let f=[],d=40;return m(c,(x,y)=>{let b=ee(x),E=s?b:b.toLowerCase(),g=E.indexOf(l);if(g===-1||E.indexOf(l,g+1)!==-1)return;let K=b.slice(g,g+e.length);if(f.push({paraId:x.paraId??String(y),match:K,before:b.slice(Math.max(0,g-d),g),after:b.slice(g+e.length,g+e.length+d)}),f.length>=u)return false}),f},getSelection(){return null},addComment(e){let i=n().get(e.paraId);if(i===void 0)return null;try{let s=o.addComment({paragraphIndex:i,text:e.text,author:e.author,search:e.search});return a(),s}catch{return null}},replyTo(e,i){try{let s=o.replyTo(e,i);return a(),s}catch{return null}},resolveComment(e){let s=o.toDocument().package?.document?.comments?.find(u=>u.id===e);if(!s)throw new I(e);s.done=true,a();},proposeChange(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=e.search==="",u=e.replaceWith==="";if(s&&u)return false;try{return s?o.proposeInsertion({paragraphIndex:i,insertText:e.replaceWith,author:e.author}):u?o.proposeDeletion({paragraphIndex:i,search:e.search,author:e.author}):o.replace({paragraphIndex:i,search:e.search,replaceWith:e.replaceWith,author:e.author}),a(),true}catch{return false}},scrollTo(e){return n().has(e)},applyFormatting(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=s?R(s,i):null;if(!u)return false;if(e.search){let l=ie(u,e.search);if(!l)return false;re(u,l.from,l.to,e.marks);}else ae(u,e.marks);return a(),true}catch{return false}},setParagraphStyle(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument(),u=s.package?.document;if(!u||!se(s.package?.styles,e.styleId))return false;try{let l=R(u,i);return l.formatting={...l.formatting??{},styleId:e.styleId},a(),true}catch{return false}},insertBreak(e){let i=n().get(e.paraId);if(i===void 0)return false;let s=o.toDocument().package?.document;if(!s)return false;try{let u=R(s,i);if(!u)return false;if(e.type==="sectionNextPage"||e.type==="sectionContinuous"){let f=e.type==="sectionNextPage"?"nextPage":"continuous";return u.sectionProperties={...u.sectionProperties??{},sectionStart:f},a(),true}let l=s.content.indexOf(u);if(l===-1)return false;let c={type:"paragraph",content:[{type:"run",content:[{type:"break",breakType:"page"}]}]};return s.content.splice(l+1,0,c),r=null,a(),true}catch{return false}},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return t.add(e),()=>{t.delete(e);}},onSelectionChange(){return ()=>{}}}}exports.a=h;exports.b=R;exports.c=m;exports.d=k;exports.e=fe;exports.f=pe;exports.g=T;exports.h=H;exports.i=I;exports.j=Y;exports.k=xe;exports.l=Te;exports.m=Pe;exports.n=ke;
@@ -1 +1 @@
1
- 'use strict';var chunkVPUAYS3Y_js=require('./chunk-VPUAYS3Y.js'),chunkHTMMNA3I_js=require('./chunk-HTMMNA3I.js');function y(n,e){let{paragraphIndex:t,author:o="AI",text:s,search:a}=e,r=chunkVPUAYS3Y_js.b(n,t),c=(n.comments??[]).map(m=>m.id),p=c.length>0?Math.max(...c)+1:1,i={id:p,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(n.comments||(n.comments=[]),n.comments.push(i),a){let m=chunkVPUAYS3Y_js.j(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:p}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:p});}else r.content.unshift({type:"commentRangeStart",id:p}),r.content.push({type:"commentRangeEnd",id:p});return p}function C(n,e,t){let o=n.comments??[];if(!o.find(p=>p.id===e))throw new chunkVPUAYS3Y_js.i(e);let a=o.map(p=>p.id),r=Math.max(...a)+1,c={id:r,author:t.author??"AI",date:new Date().toISOString(),parentId:e,content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:t.text}]}],formatting:{}}]};return o.push(c),r}function N(n,e){let t=n.comments??[],o=t.find(r=>r.id===e);if(!o)throw new chunkVPUAYS3Y_js.i(e);let s=o.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);n.comments=t.filter(r=>!a.has(r.id)),!s&&chunkVPUAYS3Y_js.c(n,r=>{for(let c=r.content.length-1;c>=0;c--){let p=r.content[c];(p.type==="commentRangeStart"||p.type==="commentRangeEnd")&&p.id===e&&r.content.splice(c,1);}});}function I(n,e,t){if(!W(n,e,"accept",t))throw new chunkVPUAYS3Y_js.h(typeof e=="number"?e:e.id)}function R(n,e,t){if(!W(n,e,"reject",t))throw new chunkVPUAYS3Y_js.h(typeof e=="number"?e:e.id)}function F(n,e,t){return G(n,"accept",e,t)}function M(n,e,t){return G(n,"reject",e,t)}function l(n,e,t){let o=0;for(let s=n.content.length-1;s>=0;s--){let a=n.content[s];chunkVPUAYS3Y_js.a(a)&&t(a)&&(J(n,s,a,e),o++);}return o}function W(n,e,t,o){if(typeof e!="number"&&e.noteType){let a=e.noteType==="footnote"?o?.footnotes:o?.endnotes,r=e.noteId!==void 0?a?.find(c=>c.id===e.noteId):void 0;return r?z(r,e.id,t):false}let s=typeof e=="number"?e:e.id;return q(n,s,t)}function G(n,e,t,o){let s=0;if(chunkVPUAYS3Y_js.c(n,a=>{s+=l(a,e,()=>true);}),t?.includeFootnotes&&o?.footnotes)for(let a of o.footnotes)chunkVPUAYS3Y_js.d(a,r=>{s+=l(r,e,()=>true);});if(t?.includeEndnotes&&o?.endnotes)for(let a of o.endnotes)chunkVPUAYS3Y_js.d(a,r=>{s+=l(r,e,()=>true);});return s}function q(n,e,t){let o=false;return chunkVPUAYS3Y_js.c(n,s=>{if(l(s,t,a=>a.info.id===e)>0&&(o=true),o)return false}),o}function z(n,e,t){let o=false;return chunkVPUAYS3Y_js.d(n,s=>{l(s,t,a=>a.info.id===e)>0&&(o=true);}),o}function J(n,e,t,o){if(t.type==="insertion"&&o==="accept"||t.type==="deletion"&&o==="reject"||t.type==="moveTo"&&o==="accept"||t.type==="moveFrom"&&o==="reject"){let a=t.content;n.content.splice(e,1,...a);}else n.content.splice(e,1);}function x(n,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:a}=e,r=chunkVPUAYS3Y_js.b(n,t),{startIndex:c,endIndex:p}=chunkVPUAYS3Y_js.k(r,o,t),i=new Date().toISOString(),m=P(n),d=r.content.slice(c,p+1),v={type:"deletion",info:{id:m,author:s,date:i},content:d},b={type:"insertion",info:{id:m+1,author:s,date:i},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(c,p-c+1,v,b);}function H(n,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:a="after",search:r}=e,c=chunkVPUAYS3Y_js.b(n,t),p=new Date().toISOString(),m={type:"insertion",info:{id:P(n),author:o,date:p},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:v}=chunkVPUAYS3Y_js.k(c,r,t),b=a==="after"?v+1:d;c.content.splice(b,0,m);}else a==="before"?c.content.unshift(m):c.content.push(m);}function L(n,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,a=chunkVPUAYS3Y_js.b(n,t),{startIndex:r,endIndex:c}=chunkVPUAYS3Y_js.k(a,o,t),p=new Date().toISOString(),i=P(n),m=a.content.slice(r,c+1),d={type:"deletion",info:{id:i,author:s,date:p},content:m};a.content.splice(r,c-r+1,d);}var S=new WeakMap;function P(n){let e=S.get(n);e===void 0&&(e=0,chunkVPUAYS3Y_js.c(n,o=>{for(let s of o.content)chunkVPUAYS3Y_js.a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(n,t+1),t}function U(n,e,t="AI"){let o=[],s=0,a=0,r=0,c=0,p=0;for(let i of e.accept??[])try{I(n,i),s++;}catch(m){o.push({operation:"accept",id:i,error:m.message});}for(let i of e.reject??[])try{R(n,i),a++;}catch(m){o.push({operation:"reject",id:i,error:m.message});}for(let i of e.comments??[])try{y(n,{...i,author:i.author??t}),r++;}catch(m){o.push({operation:"comment",search:i.search,error:m.message});}for(let i of e.replies??[])try{C(n,i.commentId,{author:i.author??t,text:i.text}),c++;}catch(m){o.push({operation:"reply",id:i.commentId,error:m.message});}for(let i of e.proposals??[])try{x(n,{...i,author:i.author??t}),p++;}catch(m){o.push({operation:"proposal",search:i.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:c,proposalsAdded:p,errors:o}}var X=class n{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:a,...r}=e;this.doc=structuredClone(r),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await chunkHTMMNA3I_js.w(e,{preloadFonts:false});return new n(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return chunkVPUAYS3Y_js.e(this.body,e)}getContentAsText(e){return chunkVPUAYS3Y_js.f(chunkVPUAYS3Y_js.e(this.body,e))}getChanges(e){return chunkVPUAYS3Y_js.l(this.body,e,{footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes})}getComments(e){return chunkVPUAYS3Y_js.m(this.body,e)}addComment(e,t){let o=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return y(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return C(this.body,e,o)}removeComment(e){N(this.body,e);}replace(e,t,o){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:o,author:this.author}:{...e,author:this.resolveAuthor(e.author)};x(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){H(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){L(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){I(this.body,e,this.changeNotes());}rejectChange(e){R(this.body,e,this.changeNotes());}acceptAll(e){return F(this.body,e,this.changeNotes())}rejectAll(e){return M(this.body,e,this.changeNotes())}changeNotes(){return {footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes}}applyReview(e){return U(this.body,e,this.author)}toDocument(){return this.doc}async toBuffer(){if(!this.doc.originalBuffer)throw new Error("Cannot create buffer: no original DOCX buffer was provided. Use DocxReviewer.fromBuffer() or pass originalBuffer to the constructor.");let{repackDocx:e}=await import('./headless-HVIRJIN4.js');return e(this.doc)}};exports.a=X;
1
+ 'use strict';var chunkEX4NO3JP_js=require('./chunk-EX4NO3JP.js'),chunkRTU2ZS7R_js=require('./chunk-RTU2ZS7R.js');function y(n,e){let{paragraphIndex:t,author:o="AI",text:s,search:a}=e,r=chunkEX4NO3JP_js.b(n,t),c=(n.comments??[]).map(m=>m.id),p=c.length>0?Math.max(...c)+1:1,i={id:p,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(n.comments||(n.comments=[]),n.comments.push(i),a){let m=chunkEX4NO3JP_js.j(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:p}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:p});}else r.content.unshift({type:"commentRangeStart",id:p}),r.content.push({type:"commentRangeEnd",id:p});return p}function C(n,e,t){let o=n.comments??[];if(!o.find(p=>p.id===e))throw new chunkEX4NO3JP_js.i(e);let a=o.map(p=>p.id),r=Math.max(...a)+1,c={id:r,author:t.author??"AI",date:new Date().toISOString(),parentId:e,content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:t.text}]}],formatting:{}}]};return o.push(c),r}function N(n,e){let t=n.comments??[],o=t.find(r=>r.id===e);if(!o)throw new chunkEX4NO3JP_js.i(e);let s=o.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);n.comments=t.filter(r=>!a.has(r.id)),!s&&chunkEX4NO3JP_js.c(n,r=>{for(let c=r.content.length-1;c>=0;c--){let p=r.content[c];(p.type==="commentRangeStart"||p.type==="commentRangeEnd")&&p.id===e&&r.content.splice(c,1);}});}function I(n,e,t){if(!W(n,e,"accept",t))throw new chunkEX4NO3JP_js.h(typeof e=="number"?e:e.id)}function R(n,e,t){if(!W(n,e,"reject",t))throw new chunkEX4NO3JP_js.h(typeof e=="number"?e:e.id)}function F(n,e,t){return G(n,"accept",e,t)}function M(n,e,t){return G(n,"reject",e,t)}function l(n,e,t){let o=0;for(let s=n.content.length-1;s>=0;s--){let a=n.content[s];chunkEX4NO3JP_js.a(a)&&t(a)&&(J(n,s,a,e),o++);}return o}function W(n,e,t,o){if(typeof e!="number"&&e.noteType){let a=e.noteType==="footnote"?o?.footnotes:o?.endnotes,r=e.noteId!==void 0?a?.find(c=>c.id===e.noteId):void 0;return r?z(r,e.id,t):false}let s=typeof e=="number"?e:e.id;return q(n,s,t)}function G(n,e,t,o){let s=0;if(chunkEX4NO3JP_js.c(n,a=>{s+=l(a,e,()=>true);}),t?.includeFootnotes&&o?.footnotes)for(let a of o.footnotes)chunkEX4NO3JP_js.d(a,r=>{s+=l(r,e,()=>true);});if(t?.includeEndnotes&&o?.endnotes)for(let a of o.endnotes)chunkEX4NO3JP_js.d(a,r=>{s+=l(r,e,()=>true);});return s}function q(n,e,t){let o=false;return chunkEX4NO3JP_js.c(n,s=>{if(l(s,t,a=>a.info.id===e)>0&&(o=true),o)return false}),o}function z(n,e,t){let o=false;return chunkEX4NO3JP_js.d(n,s=>{l(s,t,a=>a.info.id===e)>0&&(o=true);}),o}function J(n,e,t,o){if(t.type==="insertion"&&o==="accept"||t.type==="deletion"&&o==="reject"||t.type==="moveTo"&&o==="accept"||t.type==="moveFrom"&&o==="reject"){let a=t.content;n.content.splice(e,1,...a);}else n.content.splice(e,1);}function x(n,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:a}=e,r=chunkEX4NO3JP_js.b(n,t),{startIndex:c,endIndex:p}=chunkEX4NO3JP_js.k(r,o,t),i=new Date().toISOString(),m=P(n),d=r.content.slice(c,p+1),v={type:"deletion",info:{id:m,author:s,date:i},content:d},b={type:"insertion",info:{id:m+1,author:s,date:i},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(c,p-c+1,v,b);}function H(n,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:a="after",search:r}=e,c=chunkEX4NO3JP_js.b(n,t),p=new Date().toISOString(),m={type:"insertion",info:{id:P(n),author:o,date:p},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:v}=chunkEX4NO3JP_js.k(c,r,t),b=a==="after"?v+1:d;c.content.splice(b,0,m);}else a==="before"?c.content.unshift(m):c.content.push(m);}function L(n,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,a=chunkEX4NO3JP_js.b(n,t),{startIndex:r,endIndex:c}=chunkEX4NO3JP_js.k(a,o,t),p=new Date().toISOString(),i=P(n),m=a.content.slice(r,c+1),d={type:"deletion",info:{id:i,author:s,date:p},content:m};a.content.splice(r,c-r+1,d);}var S=new WeakMap;function P(n){let e=S.get(n);e===void 0&&(e=0,chunkEX4NO3JP_js.c(n,o=>{for(let s of o.content)chunkEX4NO3JP_js.a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(n,t+1),t}function U(n,e,t="AI"){let o=[],s=0,a=0,r=0,c=0,p=0;for(let i of e.accept??[])try{I(n,i),s++;}catch(m){o.push({operation:"accept",id:i,error:m.message});}for(let i of e.reject??[])try{R(n,i),a++;}catch(m){o.push({operation:"reject",id:i,error:m.message});}for(let i of e.comments??[])try{y(n,{...i,author:i.author??t}),r++;}catch(m){o.push({operation:"comment",search:i.search,error:m.message});}for(let i of e.replies??[])try{C(n,i.commentId,{author:i.author??t,text:i.text}),c++;}catch(m){o.push({operation:"reply",id:i.commentId,error:m.message});}for(let i of e.proposals??[])try{x(n,{...i,author:i.author??t}),p++;}catch(m){o.push({operation:"proposal",search:i.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:c,proposalsAdded:p,errors:o}}var X=class n{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:a,...r}=e;this.doc=structuredClone(r),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await chunkRTU2ZS7R_js.w(e,{preloadFonts:false});return new n(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return chunkEX4NO3JP_js.e(this.body,e)}getContentAsText(e){return chunkEX4NO3JP_js.f(chunkEX4NO3JP_js.e(this.body,e))}getChanges(e){return chunkEX4NO3JP_js.l(this.body,e,{footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes})}getComments(e){return chunkEX4NO3JP_js.m(this.body,e)}addComment(e,t){let o=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return y(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return C(this.body,e,o)}removeComment(e){N(this.body,e);}replace(e,t,o){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:o,author:this.author}:{...e,author:this.resolveAuthor(e.author)};x(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){H(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){L(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){I(this.body,e,this.changeNotes());}rejectChange(e){R(this.body,e,this.changeNotes());}acceptAll(e){return F(this.body,e,this.changeNotes())}rejectAll(e){return M(this.body,e,this.changeNotes())}changeNotes(){return {footnotes:this.doc.package.footnotes,endnotes:this.doc.package.endnotes}}applyReview(e){return U(this.body,e,this.author)}toDocument(){return this.doc}async toBuffer(){if(!this.doc.originalBuffer)throw new Error("Cannot create buffer: no original DOCX buffer was provided. Use DocxReviewer.fromBuffer() or pass originalBuffer to the constructor.");let{repackDocx:e}=await import('./headless-6GD55ATM.js');return e(this.doc)}};exports.a=X;
@@ -1 +1 @@
1
- 'use strict';var D=class{constructor(){this.plugins=new Map;this.commandHandlers=new Map;this.eventListeners=new Set;this.initialized=new Set;}register(e,o){let n=[];if(!e.id)return {success:false,error:"Plugin must have an id"};if(this.plugins.has(e.id))return {success:false,error:`Plugin '${e.id}' is already registered`};if(e.dependencies){for(let t of e.dependencies)if(!this.plugins.has(t))return {success:false,error:`Plugin '${e.id}' requires '${t}' which is not registered`}}if(e.commandHandlers)for(let[t,s]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(t)){let i=this.commandHandlers.get(t);n.push(`Command '${t}' from '${e.id}' overrides handler from '${i.pluginId}'`);}this.commandHandlers.set(t,{pluginId:e.id,handler:s});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let t=e.initialize();t instanceof Promise?t.then(()=>{this.initialized.add(e.id);}).catch(s=>{this.emit({type:"error",pluginId:e.id,error:s});}):this.initialized.add(e.id);}catch(t){this.emit({type:"error",pluginId:e.id,error:t});}return o?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:n.length>0?n:void 0}}unregister(e){let o=this.plugins.get(e);if(!o)return false;for(let[n,t]of this.plugins)if(t.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${n}' depends on it`),false;for(let[n,{pluginId:t}]of this.commandHandlers)t===e&&this.commandHandlers.delete(n);if(o.destroy)try{let n=o.destroy();n instanceof Promise&&n.catch(t=>{this.emit({type:"error",pluginId:e,error:t});});}catch(n){this.emit({type:"error",pluginId:e,error:n});}return this.plugins.delete(e),this.initialized.delete(e),this.emit({type:"unregistered",pluginId:e}),true}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get size(){return this.plugins.size}getCommandHandler(e){return this.commandHandlers.get(e)?.handler}getCommandTypes(){return Array.from(this.commandHandlers.keys())}hasCommandHandler(e){return this.commandHandlers.has(e)}getMcpTools(){let e=[];for(let o of this.plugins.values())o.mcpTools&&e.push(...o.mcpTools);return e}getMcpToolsForPlugin(e){return this.plugins.get(e)?.mcpTools||[]}getMcpTool(e){for(let o of this.plugins.values())if(o.mcpTools){let n=o.mcpTools.find(t=>t.name===e);if(n)return n}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let o of this.eventListeners)try{o(e);}catch(n){console.error("[PluginRegistry] Event listener error:",n);}}clear(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy();}catch{}this.plugins.clear(),this.commandHandlers.clear(),this.initialized.clear();}getDebugInfo(){return {plugins:Array.from(this.plugins.keys()),commandTypes:Array.from(this.commandHandlers.keys()),mcpTools:this.getMcpTools().map(e=>e.name),initialized:Array.from(this.initialized)}}},C=new D;function U(r,e){return r.map(o=>C.register(o,e))}function W(r){return e=>C.register(e,r)}function h(r){return JSON.parse(JSON.stringify(r))}function g(r,e){let o=0;for(let n=0;n<r.content.length;n++)if(r.content[n].type==="paragraph"){if(o===e)return n;o++;}return -1}function y(r){let e="";for(let o of r.content)if(o.type==="run")for(let n of o.content)n.type==="text"&&(e+=n.text);else if(o.type==="hyperlink"){for(let n of o.children)if(n.type==="run")for(let t of n.content)t.type==="text"&&(e+=t.text);}return e}function T(r,e){return {type:"run",formatting:e,content:[{type:"text",text:r}]}}function I(r,e,o,n){let t=[],s=0,i=false;for(let a of r.content)if(a.type==="run"){let p=a.content.filter(l=>l.type==="text").map(l=>l.text).join(""),c=s,u=s+p.length;if(!i&&e>=c&&e<=u){let l=e-c;l>0&&t.push({...a,content:[{type:"text",text:p.slice(0,l)}]}),t.push(T(o,n||a.formatting)),l<p.length&&t.push({...a,content:[{type:"text",text:p.slice(l)}]}),i=true;}else t.push(a);s=u;}else t.push(a);return i||t.push(T(o,n)),t}function d(r,e,o){let n=[],t=0;for(let s of r.content)if(s.type==="run"){let i=s.content.filter(c=>c.type==="text").map(c=>c.text).join(""),a=t,p=t+i.length;if(p<=e||a>=o)n.push(s);else {let c="";a<e&&(c+=i.slice(0,e-a)),p>o&&(c+=i.slice(o-a)),c.length>0&&n.push({...s,content:[{type:"text",text:c}]});}t=p;}else n.push(s);return n}function w(r,e,o,n){let t=[],s=0;for(let i of r.content)if(i.type==="run"){let a=i.content.filter(u=>u.type==="text").map(u=>u.text).join(""),p=s,c=s+a.length;if(c<=e||p>=o)t.push(i);else if(p>=e&&c<=o)t.push({...i,formatting:{...i.formatting,...n}});else {let u=Math.max(e,p),l=Math.min(o,c);p<u&&t.push({...i,content:[{type:"text",text:a.slice(0,u-p)}]}),t.push({...i,formatting:{...i.formatting,...n},content:[{type:"text",text:a.slice(u-p,l-p)}]}),c>l&&t.push({...i,content:[{type:"text",text:a.slice(l-p)}]});}s=c;}else t.push(i);return t}function R(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t];return s.content=I(s,e.position.offset,e.text,e.formatting),o}function _(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset),a.content=I(a,t.offset,e.text,e.formatting);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length),a.content=I(a,t.offset,e.text,e.formatting);let c=[];for(let u=t.paragraphIndex+1;u<=s.paragraphIndex;u++)c.push(g(n,u));for(let u=c.length-1;u>=0;u--)c[u]!==-1&&n.content.splice(c[u],1);}return o}function v(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length);let c=g(n,s.paragraphIndex),u=n.content[c];u.content=d(u,0,s.offset),a.content.push(...u.content);let l=[];for(let f=t.paragraphIndex+1;f<=s.paragraphIndex;f++)l.push(g(n,f));for(let f=l.length-1;f>=0;f--)l[f]!==-1&&n.content.splice(l[f],1);}return o}function S(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=w(a,t.offset,s.offset,e.formatting);}else for(let i=t.paragraphIndex;i<=s.paragraphIndex;i++){let a=g(n,i);if(a===-1)continue;let p=n.content[a],c=y(p),u=0,l=c.length;i===t.paragraphIndex&&(u=t.offset),i===s.paragraphIndex&&(l=s.offset),p.content=w(p,u,l,e.formatting);}return o}function N(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];if(s.formatting={...s.formatting,...e.formatting},"numPr"in e.formatting){let i=e.formatting.numPr;if(i&&i.numId!==void 0&&i.numId!==0){let a=i.ilvl??0,p=i.numId===1,c=p?"\u2022":"1.";if(o.package.numbering){let u=o.package.numbering.nums.find(l=>l.numId===i.numId);if(u){let l=o.package.numbering.abstractNums.find(f=>f.abstractNumId===u.abstractNumId);if(l){let f=l.levels.find(m=>m.ilvl===a);f&&(c=f.lvlText||c);}}}s.listRendering={level:a,numId:i.numId,marker:c,isBullet:p};}else delete s.listRendering;}return o}function A(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];return s.formatting={...s.formatting,styleId:e.styleId},o}function Q(r){return r/1440*96}function Y(r){return r/96*1440}function Z(r){return r==null||isNaN(r)?0:Math.round(r*96/914400)}function E(r){return Math.round(r/96*914400)}function ee(r){return Math.round(r/914400*1440)}function te(r){return Math.round(r/1440*914400)}function ne(r){return r/72*96}function re(r){return r/144*96}function oe(r){return r*2}function X(r,e=2){let o=Math.pow(10,e);return Math.round(r*o)/o}function ae(r){return `${X(r)}px`}function M(r,e){let o=h(r),n=o.package.document,t=[];for(let a=0;a<e.rows;a++){let p=[];for(let c=0;c<e.columns;c++){let u=e.data?.[a]?.[c]||"";p.push({type:"tableCell",content:[{type:"paragraph",content:u?[T(u)]:[]}]});}t.push({type:"tableRow",formatting:a===0&&e.hasHeader?{header:true}:void 0,cells:p});}let s={type:"table",rows:t},i=g(n,e.position.paragraphIndex);return i===-1?n.content.push(s):n.content.splice(i+1,0,s),o}function $(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],a={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:e.src,alt:e.alt,size:{width:E(e.width||100),height:E(e.height||100)},wrap:{type:"inline"}}}]},p=I(s,e.position.offset,"",void 0),c=false,u=0;for(let l=0;l<p.length;l++){let f=p[l];if(f.type==="run"){let m=f.content.filter(x=>x.type==="text").map(x=>x.text).join("");if(u+=m.length,!c&&u>=e.position.offset){p.splice(l+1,0,a),c=true;break}}}return c||p.push(a),s.content=p,o}function B(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex!==s.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i],p=y(a),c=e.displayText||p.slice(t.offset,s.offset);a.content=d(a,t.offset,s.offset);let u={type:"hyperlink",href:e.url,tooltip:e.tooltip,children:[T(c)]},l=false,f=0,m=[];for(let x of a.content)if(x.type==="run"){let b=x.content.filter(P=>P.type==="text").map(P=>P.text).join(""),H=f+b.length;if(!l&&f<=t.offset&&t.offset<=H){let P=t.offset-f;P>0&&m.push({...x,content:[{type:"text",text:b.slice(0,P)}]}),m.push(u),P<b.length&&m.push({...x,content:[{type:"text",text:b.slice(P)}]}),l=true;}else m.push(x);f=H;}else m.push(x);return l||m.push(u),a.content=m,o}function F(r,e){let o=h(r),n=o.package.document,{start:t}=e.range,s=g(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let i=n.content[s],a=[];for(let p of i.content)if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&a.push(c);else a.push(p);return i.content=a,o}function k(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],i=y(s),a=d({content:[...s.content]},e.position.offset,i.length),p=d({content:[...s.content]},0,e.position.offset);s.content=a;let c={type:"paragraph",formatting:s.formatting,content:p};return n.content.splice(t+1,0,c),o}function L(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t],i=[];for(let a=1;a<=e.count;a++){let p=g(n,e.paragraphIndex+a);if(p!==-1){let c=n.content[p];s.content.push(...c.content),i.push(p);}}for(let a=i.length-1;a>=0;a--)n.content.splice(i[a],1);return o}function V(r,e){return k(r,{position:e.position})}function z(r,e){let o=h(r);return o.templateVariables||(o.templateVariables=[]),o.templateVariables.includes(e.name)||o.templateVariables.push(e.name),o}function O(r,e){let o=h(r),n=o.package.document;function t(a){for(let p of a.content)if(p.type==="text")for(let[c,u]of Object.entries(e.values)){let l=new RegExp(`\\{${c}\\}`,"g");p.text=p.text.replace(l,u);}}function s(a){for(let p of a.content)if(p.type==="run")t(p);else if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&t(c);}function i(a){if(a.type==="paragraph")s(a);else if(a.type==="table")for(let p of a.rows)for(let c of p.cells)for(let u of c.content)i(u);}for(let a of n.content)i(a);return o}function j(r,e){let o=C.getCommandHandler(e.type);if(o)return o(r,e);switch(e.type){case "insertText":return R(r,e);case "replaceText":return _(r,e);case "deleteText":return v(r,e);case "formatText":return S(r,e);case "formatParagraph":return N(r,e);case "applyStyle":return A(r,e);case "insertTable":return M(r,e);case "insertImage":return $(r,e);case "insertHyperlink":return B(r,e);case "removeHyperlink":return F(r,e);case "insertParagraphBreak":return k(r,e);case "mergeParagraphs":return L(r,e);case "splitParagraph":return V(r,e);case "setVariable":return z(r,e);case "applyVariables":return O(r,e);default:{let n=e;throw new Error(`Unknown command type: ${n.type}`)}}}function ye(r,e){return e.reduce((o,n)=>j(o,n),r)}exports.a=D;exports.b=C;exports.c=U;exports.d=W;exports.e=Q;exports.f=Y;exports.g=Z;exports.h=E;exports.i=ee;exports.j=te;exports.k=ne;exports.l=re;exports.m=oe;exports.n=ae;exports.o=j;exports.p=ye;
1
+ 'use strict';var D=class{constructor(){this.plugins=new Map;this.commandHandlers=new Map;this.eventListeners=new Set;this.initialized=new Set;}register(e,o){let n=[];if(!e.id)return {success:false,error:"Plugin must have an id"};if(this.plugins.has(e.id))return {success:false,error:`Plugin '${e.id}' is already registered`};if(e.dependencies){for(let t of e.dependencies)if(!this.plugins.has(t))return {success:false,error:`Plugin '${e.id}' requires '${t}' which is not registered`}}if(e.commandHandlers)for(let[t,s]of Object.entries(e.commandHandlers)){if(this.commandHandlers.has(t)){let i=this.commandHandlers.get(t);n.push(`Command '${t}' from '${e.id}' overrides handler from '${i.pluginId}'`);}this.commandHandlers.set(t,{pluginId:e.id,handler:s});}if(this.plugins.set(e.id,e),e.initialize&&!this.initialized.has(e.id))try{let t=e.initialize();t instanceof Promise?t.then(()=>{this.initialized.add(e.id);}).catch(s=>{this.emit({type:"error",pluginId:e.id,error:s});}):this.initialized.add(e.id);}catch(t){this.emit({type:"error",pluginId:e.id,error:t});}return o?.debug&&console.log(`[PluginRegistry] Registered plugin: ${e.id}`),this.emit({type:"registered",plugin:e}),{success:true,plugin:e,warnings:n.length>0?n:void 0}}unregister(e){let o=this.plugins.get(e);if(!o)return false;for(let[n,t]of this.plugins)if(t.dependencies?.includes(e))return console.warn(`Cannot unregister '${e}': '${n}' depends on it`),false;for(let[n,{pluginId:t}]of this.commandHandlers)t===e&&this.commandHandlers.delete(n);if(o.destroy)try{let n=o.destroy();n instanceof Promise&&n.catch(t=>{this.emit({type:"error",pluginId:e,error:t});});}catch(n){this.emit({type:"error",pluginId:e,error:n});}return this.plugins.delete(e),this.initialized.delete(e),this.emit({type:"unregistered",pluginId:e}),true}get(e){return this.plugins.get(e)}getAll(){return Array.from(this.plugins.values())}has(e){return this.plugins.has(e)}get size(){return this.plugins.size}getCommandHandler(e){return this.commandHandlers.get(e)?.handler}getCommandTypes(){return Array.from(this.commandHandlers.keys())}hasCommandHandler(e){return this.commandHandlers.has(e)}getMcpTools(){let e=[];for(let o of this.plugins.values())o.mcpTools&&e.push(...o.mcpTools);return e}getMcpToolsForPlugin(e){return this.plugins.get(e)?.mcpTools||[]}getMcpTool(e){for(let o of this.plugins.values())if(o.mcpTools){let n=o.mcpTools.find(t=>t.name===e);if(n)return n}}addEventListener(e){this.eventListeners.add(e);}removeEventListener(e){this.eventListeners.delete(e);}emit(e){for(let o of this.eventListeners)try{o(e);}catch(n){console.error("[PluginRegistry] Event listener error:",n);}}clear(){for(let e of this.plugins.values())if(e.destroy)try{e.destroy();}catch{}this.plugins.clear(),this.commandHandlers.clear(),this.initialized.clear();}getDebugInfo(){return {plugins:Array.from(this.plugins.keys()),commandTypes:Array.from(this.commandHandlers.keys()),mcpTools:this.getMcpTools().map(e=>e.name),initialized:Array.from(this.initialized)}}},C=new D;function U(r,e){return r.map(o=>C.register(o,e))}function W(r){return e=>C.register(e,r)}function h(r){return JSON.parse(JSON.stringify(r))}function g(r,e){let o=0;for(let n=0;n<r.content.length;n++)if(r.content[n].type==="paragraph"){if(o===e)return n;o++;}return -1}function y(r){let e="";for(let o of r.content)if(o.type==="run")for(let n of o.content)n.type==="text"&&(e+=n.text);else if(o.type==="hyperlink"){for(let n of o.children)if(n.type==="run")for(let t of n.content)t.type==="text"&&(e+=t.text);}return e}function T(r,e){return {type:"run",formatting:e,content:[{type:"text",text:r}]}}function I(r,e,o,n){let t=[],s=0,i=false;for(let a of r.content)if(a.type==="run"){let p=a.content.filter(l=>l.type==="text").map(l=>l.text).join(""),c=s,u=s+p.length;if(!i&&e>=c&&e<=u){let l=e-c;l>0&&t.push({...a,content:[{type:"text",text:p.slice(0,l)}]}),t.push(T(o,n||a.formatting)),l<p.length&&t.push({...a,content:[{type:"text",text:p.slice(l)}]}),i=true;}else t.push(a);s=u;}else t.push(a);return i||t.push(T(o,n)),t}function d(r,e,o){let n=[],t=0;for(let s of r.content)if(s.type==="run"){let i=s.content.filter(c=>c.type==="text").map(c=>c.text).join(""),a=t,p=t+i.length;if(p<=e||a>=o)n.push(s);else {let c="";a<e&&(c+=i.slice(0,e-a)),p>o&&(c+=i.slice(o-a)),c.length>0&&n.push({...s,content:[{type:"text",text:c}]});}t=p;}else n.push(s);return n}function w(r,e,o,n){let t=[],s=0;for(let i of r.content)if(i.type==="run"){let a=i.content.filter(u=>u.type==="text").map(u=>u.text).join(""),p=s,c=s+a.length;if(c<=e||p>=o)t.push(i);else if(p>=e&&c<=o)t.push({...i,formatting:{...i.formatting,...n}});else {let u=Math.max(e,p),l=Math.min(o,c);p<u&&t.push({...i,content:[{type:"text",text:a.slice(0,u-p)}]}),t.push({...i,formatting:{...i.formatting,...n},content:[{type:"text",text:a.slice(u-p,l-p)}]}),c>l&&t.push({...i,content:[{type:"text",text:a.slice(l-p)}]});}s=c;}else t.push(i);return t}function R(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t];return s.content=I(s,e.position.offset,e.text,e.formatting),o}function _(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset),a.content=I(a,t.offset,e.text,e.formatting);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length),a.content=I(a,t.offset,e.text,e.formatting);let c=[];for(let u=t.paragraphIndex+1;u<=s.paragraphIndex;u++)c.push(g(n,u));for(let u=c.length-1;u>=0;u--)c[u]!==-1&&n.content.splice(c[u],1);}return o}function v(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=d(a,t.offset,s.offset);}else {let i=g(n,t.paragraphIndex),a=n.content[i],p=y(a);a.content=d(a,t.offset,p.length);let c=g(n,s.paragraphIndex),u=n.content[c];u.content=d(u,0,s.offset),a.content.push(...u.content);let l=[];for(let f=t.paragraphIndex+1;f<=s.paragraphIndex;f++)l.push(g(n,f));for(let f=l.length-1;f>=0;f--)l[f]!==-1&&n.content.splice(l[f],1);}return o}function S(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex===s.paragraphIndex){let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i];a.content=w(a,t.offset,s.offset,e.formatting);}else for(let i=t.paragraphIndex;i<=s.paragraphIndex;i++){let a=g(n,i);if(a===-1)continue;let p=n.content[a],c=y(p),u=0,l=c.length;i===t.paragraphIndex&&(u=t.offset),i===s.paragraphIndex&&(l=s.offset),p.content=w(p,u,l,e.formatting);}return o}function N(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];if(s.formatting={...s.formatting,...e.formatting},"numPr"in e.formatting){let i=e.formatting.numPr;if(i&&i.numId!==void 0&&i.numId!==0){let a=i.ilvl??0,p=i.numId===1,c=p?"\u2022":"1.";if(o.package.numbering){let u=o.package.numbering.nums.find(l=>l.numId===i.numId);if(u){let l=o.package.numbering.abstractNums.find(f=>f.abstractNumId===u.abstractNumId);if(l){let f=l.levels.find(m=>m.ilvl===a);f&&(c=f.lvlText||c);}}}s.listRendering={level:a,numId:i.numId,marker:c,isBullet:p};}else delete s.listRendering;}return o}function A(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t];return s.formatting={...s.formatting,styleId:e.styleId},o}function Q(r){return r/1440*96}function Y(r){return r/96*1440}function Z(r){return r==null||isNaN(r)?0:Math.round(r*96/914400)}function E(r){return Math.round(r/96*914400)}function ee(r){return Math.round(r/914400*1440)}function te(r){return Math.round(r/1440*914400)}function ne(r){return r/72*96}function re(r){return r/144*96}function oe(r){return r*2}function X(r,e=2){let o=Math.pow(10,e);return Math.round(r*o)/o}function ae(r){return `${X(r)}px`}function M(r,e){let o=h(r),n=o.package.document,t=[];for(let a=0;a<e.rows;a++){let p=[];for(let c=0;c<e.columns;c++){let u=e.data?.[a]?.[c]||"";p.push({type:"tableCell",content:[{type:"paragraph",content:u?[T(u)]:[]}]});}t.push({type:"tableRow",formatting:a===0&&e.hasHeader?{header:true}:void 0,cells:p});}let s={type:"table",rows:t},i=g(n,e.position.paragraphIndex);return i===-1?n.content.push(s):n.content.splice(i+1,0,s),o}function $(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],a={type:"run",content:[{type:"drawing",image:{type:"image",rId:`rId_img_${Date.now()}`,src:e.src,alt:e.alt,size:{width:E(e.width||100),height:E(e.height||100)},wrap:{type:"inline"}}}]},p=I(s,e.position.offset,"",void 0),c=false,u=0;for(let l=0;l<p.length;l++){let f=p[l];if(f.type==="run"){let m=f.content.filter(x=>x.type==="text").map(x=>x.text).join("");if(u+=m.length,!c&&u>=e.position.offset){p.splice(l+1,0,a),c=true;break}}}return c||p.push(a),s.content=p,o}function B(r,e){let o=h(r),n=o.package.document,{start:t,end:s}=e.range;if(t.paragraphIndex!==s.paragraphIndex)throw new Error("Hyperlinks cannot span multiple paragraphs");let i=g(n,t.paragraphIndex);if(i===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let a=n.content[i],p=y(a),c=e.displayText||p.slice(t.offset,s.offset);a.content=d(a,t.offset,s.offset);let u={type:"hyperlink",href:e.url,tooltip:e.tooltip,children:[T(c)]},l=false,f=0,m=[];for(let x of a.content)if(x.type==="run"){let b=x.content.filter(P=>P.type==="text").map(P=>P.text).join(""),H=f+b.length;if(!l&&f<=t.offset&&t.offset<=H){let P=t.offset-f;P>0&&m.push({...x,content:[{type:"text",text:b.slice(0,P)}]}),m.push(u),P<b.length&&m.push({...x,content:[{type:"text",text:b.slice(P)}]}),l=true;}else m.push(x);f=H;}else m.push(x);return l||m.push(u),a.content=m,o}function F(r,e){let o=h(r),n=o.package.document,{start:t}=e.range,s=g(n,t.paragraphIndex);if(s===-1)throw new Error(`Paragraph index ${t.paragraphIndex} not found`);let i=n.content[s],a=[];for(let p of i.content)if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&a.push(c);else a.push(p);return i.content=a,o}function k(r,e){let o=h(r),n=o.package.document,t=g(n,e.position.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.position.paragraphIndex} not found`);let s=n.content[t],i=y(s),a=d({content:[...s.content]},e.position.offset,i.length),p=d({content:[...s.content]},0,e.position.offset);s.content=a;let c={type:"paragraph",formatting:s.formatting,content:p};return n.content.splice(t+1,0,c),o}function L(r,e){let o=h(r),n=o.package.document,t=g(n,e.paragraphIndex);if(t===-1)throw new Error(`Paragraph index ${e.paragraphIndex} not found`);let s=n.content[t],i=[];for(let a=1;a<=e.count;a++){let p=g(n,e.paragraphIndex+a);if(p!==-1){let c=n.content[p];s.content.push(...c.content),i.push(p);}}for(let a=i.length-1;a>=0;a--)n.content.splice(i[a],1);return o}function V(r,e){return k(r,{position:e.position})}function O(r,e){let o=h(r);return o.templateVariables||(o.templateVariables=[]),o.templateVariables.includes(e.name)||o.templateVariables.push(e.name),o}function z(r,e){let o=h(r),n=o.package.document;function t(a){for(let p of a.content)if(p.type==="text")for(let[c,u]of Object.entries(e.values)){let l=new RegExp(`\\{${c}\\}`,"g");p.text=p.text.replace(l,u);}}function s(a){for(let p of a.content)if(p.type==="run")t(p);else if(p.type==="hyperlink")for(let c of p.children)c.type==="run"&&t(c);}function i(a){if(a.type==="paragraph")s(a);else if(a.type==="table")for(let p of a.rows)for(let c of p.cells)for(let u of c.content)i(u);}for(let a of n.content)i(a);return o}function j(r,e){let o=C.getCommandHandler(e.type);if(o)return o(r,e);switch(e.type){case "insertText":return R(r,e);case "replaceText":return _(r,e);case "deleteText":return v(r,e);case "formatText":return S(r,e);case "formatParagraph":return N(r,e);case "applyStyle":return A(r,e);case "insertTable":return M(r,e);case "insertImage":return $(r,e);case "insertHyperlink":return B(r,e);case "removeHyperlink":return F(r,e);case "insertParagraphBreak":return k(r,e);case "mergeParagraphs":return L(r,e);case "splitParagraph":return V(r,e);case "setVariable":return O(r,e);case "applyVariables":return z(r,e);default:{let n=e;throw new Error(`Unknown command type: ${n.type}`)}}}function ye(r,e){return e.reduce((o,n)=>j(o,n),r)}exports.a=D;exports.b=C;exports.c=U;exports.d=W;exports.e=Q;exports.f=Y;exports.g=Z;exports.h=E;exports.i=ee;exports.j=te;exports.k=ne;exports.l=re;exports.m=oe;exports.n=ae;exports.o=j;exports.p=ye;
@@ -1,8 +1,8 @@
1
- var d=["single","words","double","thick","dotted","dottedHeavy","dash","dashedHeavy","dashLong","dashLongHeavy","dotDash","dashDotHeavy","dotDotDash","dashDotDotHeavy","wave","wavyHeavy","wavyDouble","none"],o=["black","blue","cyan","darkBlue","darkCyan","darkGray","darkGreen","darkMagenta","darkRed","darkYellow","green","lightGray","magenta","red","white","yellow","none"],c={name:"apply_formatting",displayName:"Applying formatting",description:'Apply character formatting (bold, italic, underline, strike, color, highlight, font size, font family) to a paragraph or to a unique phrase within it. Pass `search` to scope the change to part of the paragraph; omit it to format the whole paragraph. Direct edit \u2014 does not create a tracked change. Pass `false` to clear a mark; omit a key to leave it untouched. Color uses `{rgb: "FF0000"}` (no hash) or `{themeColor: "accent1"}`. Font size is in points. Font family takes `{ascii, hAnsi}`.',inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Optional: format only this exact phrase within the paragraph (must be unique)."},marks:{type:"object",description:"Marks to set or clear. Omit a key to leave it untouched.",properties:{bold:{type:"boolean"},italic:{type:"boolean"},underline:{description:'true \u2192 single underline; false \u2192 clear; or { style: "single"|"double"|"thick"|"dotted"|"dottedHeavy"|"dash"|"dashedHeavy"|"dashLong"|"dashLongHeavy"|"dotDash"|"dashDotHeavy"|"dotDotDash"|"dashDotDotHeavy"|"wave"|"wavyHeavy"|"wavyDouble"|"words"|"none" }. Other values are rejected.'},strike:{type:"boolean"},color:{type:"object",description:'Either {rgb: "RRGGBB"} (no hash) or {themeColor: "accent1"|"text1"|...}.',properties:{rgb:{type:"string"},themeColor:{type:"string"}}},highlight:{type:"string",enum:[...o],description:"Highlight color \u2014 must be one of the Word-supported names: "+o.join(", ")+'. Pass "none" to clear. Hex values are rejected (Word does not accept hex for <w:highlight>).'},fontSize:{type:"number",description:"Size in points (e.g. 12, 14, 24)."},fontFamily:{type:"object",properties:{ascii:{type:"string"},hAnsi:{type:"string"}}}}}},required:["paraId","marks"]},handler:(e,r)=>{if(!e.marks||Object.keys(e.marks).length===0)return {success:false,error:"No marks provided. Specify at least one of bold/italic/etc."};let t=typeof e.marks.underline=="object"&&e.marks.underline!==null?e.marks.underline.style:void 0;if(t&&!d.includes(t))return {success:false,error:`Invalid underline.style "${t}". Must be one of: ${d.join(", ")}.`};let n=typeof e.marks.highlight=="string"?e.marks.highlight:void 0;if(n&&!o.includes(n))return {success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`};let a=n==="none"?{...e.marks,highlight:""}:e.marks;return r.applyFormatting({paraId:e.paraId,search:e.search,marks:a})?{success:true,data:`Formatting applied to ${e.search?`"${e.search}" in ${e.paraId}`:e.paraId}.`}:{success:false,error:"Could not apply formatting. The paraId may not exist, or `search` is missing / ambiguous."}}},p={name:"set_paragraph_style",displayName:"Setting paragraph style",description:`Apply a paragraph style by id (e.g. "Heading1", "Heading2", "Title", "Quote", "Normal"). The styleId must exist in the document's style definitions \u2014 unknown ids are no-ops. Direct edit, not a tracked change.`,inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},styleId:{type:"string",description:'Style id (e.g. "Heading1", "Title", "Quote", "Normal").'}},required:["paraId","styleId"]},handler:(e,r)=>r.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})?{success:true,data:`Style "${e.styleId}" applied to ${e.paraId}.`}:{success:false,error:`Could not set style. paraId "${e.paraId}" not found, or styleId "${e.styleId}" is not defined.`}};var l={name:"read_page",displayName:"Reading page",description:`Read the contents of one rendered page (1-indexed). Returns paragraphs on the page, each tagged with its stable paraId. Use this when the user asks "summarize page 3" or "comment on what's on this page".`,inputSchema:{type:"object",properties:{pageNumber:{type:"number",description:"1-indexed page number."}},required:["pageNumber"]},handler:(e,r)=>{let t=r.getPage(e.pageNumber);if(!t){let n=r.getTotalPages();return n===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`Page ${e.pageNumber} does not exist (document has ${n} page${n===1?"":"s"}).`}}return {success:true,data:t.text||"(empty page)"}}},m={name:"read_pages",displayName:"Reading pages",description:"Read a contiguous range of rendered pages (1-indexed, inclusive). Returns paragraphs across the range, each tagged with paraId. Cheaper than calling read_page repeatedly \u2014 single round-trip.",inputSchema:{type:"object",properties:{from:{type:"number",description:"1-indexed start page (inclusive)."},to:{type:"number",description:"1-indexed end page (inclusive)."}},required:["from","to"]},handler:(e,r)=>{let t=r.getPages({from:e.from,to:e.to});if(t.length===0){let a=r.getTotalPages();return a===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`No pages in range ${e.from}\u2013${e.to} (document has ${a} page${a===1?"":"s"}).`}}return {success:true,data:t.map(a=>`--- Page ${a.pageNumber} ---
1
+ var c=["single","words","double","thick","dotted","dottedHeavy","dash","dashedHeavy","dashLong","dashLongHeavy","dotDash","dashDotHeavy","dotDotDash","dashDotDotHeavy","wave","wavyHeavy","wavyDouble","none"],o=["black","blue","cyan","darkBlue","darkCyan","darkGray","darkGreen","darkMagenta","darkRed","darkYellow","green","lightGray","magenta","red","white","yellow","none"],p={name:"apply_formatting",displayName:"Applying formatting",description:'Apply character formatting (bold, italic, underline, strike, color, highlight, font size, font family) to a paragraph or to a unique phrase within it. Pass `search` to scope the change to part of the paragraph; omit it to format the whole paragraph. Direct edit \u2014 does not create a tracked change. Pass `false` to clear a mark; omit a key to leave it untouched. Color uses `{rgb: "FF0000"}` (no hash) or `{themeColor: "accent1"}`. Font size is in points. Font family takes `{ascii, hAnsi}`.',inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Optional: format only this exact phrase within the paragraph (must be unique)."},marks:{type:"object",description:"Marks to set or clear. Omit a key to leave it untouched.",properties:{bold:{type:"boolean"},italic:{type:"boolean"},underline:{description:'true \u2192 single underline; false \u2192 clear; or { style: "single"|"double"|"thick"|"dotted"|"dottedHeavy"|"dash"|"dashedHeavy"|"dashLong"|"dashLongHeavy"|"dotDash"|"dashDotHeavy"|"dotDotDash"|"dashDotDotHeavy"|"wave"|"wavyHeavy"|"wavyDouble"|"words"|"none" }. Other values are rejected.'},strike:{type:"boolean"},color:{type:"object",description:'Either {rgb: "RRGGBB"} (no hash) or {themeColor: "accent1"|"text1"|...}.',properties:{rgb:{type:"string"},themeColor:{type:"string"}}},highlight:{type:"string",enum:[...o],description:"Highlight color \u2014 must be one of the Word-supported names: "+o.join(", ")+'. Pass "none" to clear. Hex values are rejected (Word does not accept hex for <w:highlight>).'},fontSize:{type:"number",description:"Size in points (e.g. 12, 14, 24)."},fontFamily:{type:"object",properties:{ascii:{type:"string"},hAnsi:{type:"string"}}}}}},required:["paraId","marks"]},handler:(e,r)=>{if(!e.marks||Object.keys(e.marks).length===0)return {success:false,error:"No marks provided. Specify at least one of bold/italic/etc."};let t=typeof e.marks.underline=="object"&&e.marks.underline!==null?e.marks.underline.style:void 0;if(t&&!c.includes(t))return {success:false,error:`Invalid underline.style "${t}". Must be one of: ${c.join(", ")}.`};let n=typeof e.marks.highlight=="string"?e.marks.highlight:void 0;if(n&&!o.includes(n))return {success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`};let a=n==="none"?{...e.marks,highlight:""}:e.marks;return r.applyFormatting({paraId:e.paraId,search:e.search,marks:a})?{success:true,data:`Formatting applied to ${e.search?`"${e.search}" in ${e.paraId}`:e.paraId}.`}:{success:false,error:"Could not apply formatting. The paraId may not exist, or `search` is missing / ambiguous."}}},m={name:"set_paragraph_style",displayName:"Setting paragraph style",description:`Apply a paragraph style by id (e.g. "Heading1", "Heading2", "Title", "Quote", "Normal"). The styleId must exist in the document's style definitions \u2014 unknown ids are no-ops. Direct edit, not a tracked change.`,inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},styleId:{type:"string",description:'Style id (e.g. "Heading1", "Title", "Quote", "Normal").'}},required:["paraId","styleId"]},handler:(e,r)=>r.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})?{success:true,data:`Style "${e.styleId}" applied to ${e.paraId}.`}:{success:false,error:`Could not set style. paraId "${e.paraId}" not found, or styleId "${e.styleId}" is not defined.`}};var i=["page","sectionNextPage","sectionContinuous"],u={page:"Page break",sectionNextPage:"Section break (next page)",sectionContinuous:"Section break (continuous)"},l={name:"insert_break",displayName:"Inserting break",description:'Insert a break after a paragraph (located by paraId). `type: "page"` adds a page break so following content starts on a new page. `type: "sectionNextPage"` starts a new document section on a new page. `type: "sectionContinuous"` starts a new section on the same page (use this to change column layout or margins from that point onward). The target paragraph becomes the end of its page/section and the next paragraph begins the new one. Direct edit \u2014 not a tracked change.',inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text. The break is inserted after this paragraph."},type:{type:"string",enum:[...i],description:'Break kind: "page" (page break), "sectionNextPage" (new section, new page), or "sectionContinuous" (new section, same page).'}},required:["paraId","type"]},handler:(e,r)=>i.includes(e.type)?r.insertBreak({paraId:e.paraId,type:e.type})?{success:true,data:`${u[e.type]} inserted after ${e.paraId}.`}:{success:false,error:`Could not insert break. paraId "${e.paraId}" not found.`}:{success:false,error:`Invalid break type "${e.type}". Must be one of: ${i.join(", ")}.`}};var g={name:"read_page",displayName:"Reading page",description:`Read the contents of one rendered page (1-indexed). Returns paragraphs on the page, each tagged with its stable paraId. Use this when the user asks "summarize page 3" or "comment on what's on this page".`,inputSchema:{type:"object",properties:{pageNumber:{type:"number",description:"1-indexed page number."}},required:["pageNumber"]},handler:(e,r)=>{let t=r.getPage(e.pageNumber);if(!t){let n=r.getTotalPages();return n===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`Page ${e.pageNumber} does not exist (document has ${n} page${n===1?"":"s"}).`}}return {success:true,data:t.text||"(empty page)"}}},h={name:"read_pages",displayName:"Reading pages",description:"Read a contiguous range of rendered pages (1-indexed, inclusive). Returns paragraphs across the range, each tagged with paraId. Cheaper than calling read_page repeatedly \u2014 single round-trip.",inputSchema:{type:"object",properties:{from:{type:"number",description:"1-indexed start page (inclusive)."},to:{type:"number",description:"1-indexed end page (inclusive)."}},required:["from","to"]},handler:(e,r)=>{let t=r.getPages({from:e.from,to:e.to});if(t.length===0){let a=r.getTotalPages();return a===0?{success:false,error:"No pages rendered (headless mode or empty document)."}:{success:false,error:`No pages in range ${e.from}\u2013${e.to} (document has ${a} page${a===1?"":"s"}).`}}return {success:true,data:t.map(a=>`--- Page ${a.pageNumber} ---
2
2
  ${a.text||"(empty page)"}`).join(`
3
3
 
4
- `)}}};var h={name:"read_document",displayName:"Reading document",description:'Read the document content. Returns lines tagged with a stable paragraph id, e.g. "[2A1F3B] First paragraph". Use the bracketed id as `paraId` when commenting or suggesting changes \u2014 it survives edits, unlike ordinal indices. Returns the vanilla document (the doc as it exists right now, before any tracked suggestions are accepted): pending insertions are HIDDEN, pending deletions are shown as plain text (still part of the document until accepted), and comment markers are stripped. Use read_changes / read_comments to inspect what is pending.',inputSchema:{type:"object",properties:{fromIndex:{type:"number",description:"Start ordinal index (inclusive). Optional."},toIndex:{type:"number",description:"End ordinal index (inclusive). Optional."}}},handler:(e,r)=>({success:true,data:r.getContentAsText({fromIndex:e.fromIndex,toIndex:e.toIndex,includeTrackedChanges:false,includeCommentAnchors:false})})},g={name:"read_selection",displayName:"Reading selection",description:'Read the user\'s current cursor or selection. Returns the selected text, the paragraph it lives in, and that paragraph\'s `paraId`. Use this when the user asks "fix this" or "review what I have selected".',inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getSelection();return t?{success:true,data:t}:{success:false,error:"No selection (editor not focused)."}}},u={name:"find_text",displayName:"Finding text",description:"Locate paragraphs containing `query`. Returns up to `limit` handles, each with `paraId`, the matched substring, and surrounding context. Pass any returned `paraId` (and the `match` as `search`) to add_comment / suggest_change.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Text to find (substring match)."},caseSensitive:{type:"boolean",description:"Default: false."},limit:{type:"number",description:"Max paragraphs to return. Default: 20."}},required:["query"]},handler:(e,r)=>{let t=r.findText(e.query,{caseSensitive:e.caseSensitive,limit:e.limit});return t.length===0?{success:true,data:"No matches."}:{success:true,data:t}}},y={name:"read_comments",displayName:"Reading comments",description:"List all comments in the document with their paragraph anchors.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getComments();return t.length===0?{success:true,data:"No comments."}:{success:true,data:t.map(a=>`[Comment #${a.id}] ${a.author}: "${a.text}"`+(a.anchoredText?` (anchored to: "${a.anchoredText}")`:"")+(a.replies.length>0?`
4
+ `)}}};var y={name:"read_document",displayName:"Reading document",description:'Read the document content. Returns lines tagged with a stable paragraph id, e.g. "[2A1F3B] First paragraph". Use the bracketed id as `paraId` when commenting or suggesting changes \u2014 it survives edits, unlike ordinal indices. Returns the vanilla document (the doc as it exists right now, before any tracked suggestions are accepted): pending insertions are HIDDEN, pending deletions are shown as plain text (still part of the document until accepted), and comment markers are stripped. Use read_changes / read_comments to inspect what is pending.',inputSchema:{type:"object",properties:{fromIndex:{type:"number",description:"Start ordinal index (inclusive). Optional."},toIndex:{type:"number",description:"End ordinal index (inclusive). Optional."}}},handler:(e,r)=>({success:true,data:r.getContentAsText({fromIndex:e.fromIndex,toIndex:e.toIndex,includeTrackedChanges:false,includeCommentAnchors:false})})},f={name:"read_selection",displayName:"Reading selection",description:'Read the user\'s current cursor or selection. Returns the selected text, the paragraph it lives in, and that paragraph\'s `paraId`. Use this when the user asks "fix this" or "review what I have selected".',inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getSelection();return t?{success:true,data:t}:{success:false,error:"No selection (editor not focused)."}}},b={name:"find_text",displayName:"Finding text",description:"Locate paragraphs containing `query`. Returns up to `limit` handles, each with `paraId`, the matched substring, and surrounding context. Pass any returned `paraId` (and the `match` as `search`) to add_comment / suggest_change.",inputSchema:{type:"object",properties:{query:{type:"string",description:"Text to find (substring match)."},caseSensitive:{type:"boolean",description:"Default: false."},limit:{type:"number",description:"Max paragraphs to return. Default: 20."}},required:["query"]},handler:(e,r)=>{let t=r.findText(e.query,{caseSensitive:e.caseSensitive,limit:e.limit});return t.length===0?{success:true,data:"No matches."}:{success:true,data:t}}},I={name:"read_comments",displayName:"Reading comments",description:"List all comments in the document with their paragraph anchors.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getComments();return t.length===0?{success:true,data:"No comments."}:{success:true,data:t.map(a=>`[Comment #${a.id}] ${a.author}: "${a.text}"`+(a.anchoredText?` (anchored to: "${a.anchoredText}")`:"")+(a.replies.length>0?`
5
5
  `+a.replies.map(s=>` Reply by ${s.author}: "${s.text}"`).join(`
6
6
  `):"")).join(`
7
- `)}}},f={name:"read_changes",displayName:"Reading changes",description:"List tracked changes (insertions / deletions) currently in the document.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getChanges();return t.length===0?{success:true,data:"No tracked changes."}:{success:true,data:t.map(a=>`[Change #${a.id}] ${a.type} by ${a.author}: "${a.text}"`).join(`
8
- `)}}},b={name:"add_comment",displayName:"Adding comment",description:"Attach a comment to a paragraph, optionally anchored to a unique phrase within it. The user sees it instantly in the comments sidebar.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},text:{type:"string",description:"Comment body."},search:{type:"string",description:"Optional: anchor to this exact phrase within the paragraph. Must be unique."}},required:["paraId","text"]},handler:(e,r)=>{let t=r.addComment({paraId:e.paraId,text:e.text,search:e.search});return t===null?{success:false,error:"Could not add comment. The paraId may not exist, or `search` is missing / ambiguous."}:{success:true,data:`Comment ${t} added on ${e.paraId}.`}}},I={name:"suggest_change",displayName:"Suggesting change",description:"Suggest a tracked change. Three modes: (1) replacement \u2014 `search` non-empty, `replaceWith` non-empty; (2) deletion \u2014 `search` non-empty, `replaceWith` empty; (3) insertion at paragraph end \u2014 `search` empty, `replaceWith` non-empty. The user can accept or reject in the editor UI.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Phrase to find (must be unique). Empty string = insert at paragraph end."},replaceWith:{type:"string",description:"Replacement text. Empty string = delete the matched phrase."}},required:["paraId","search","replaceWith"]},handler:(e,r)=>r.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith})?e.search?e.replaceWith?{success:true,data:`Replacement proposed: "${e.search}" \u2192 "${e.replaceWith}" on ${e.paraId}.`}:{success:true,data:`Deletion proposed: "${e.search}" on ${e.paraId}.`}:{success:true,data:`Insertion proposed on ${e.paraId}.`}:{success:false,error:"Could not propose change. Possible causes: paraId not found; search missing or ambiguous; or the target overlaps an existing tracked change."}},x={name:"reply_comment",displayName:"Replying to comment",description:"Reply to an existing comment by id. Threaded under the original.",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."},text:{type:"string",description:"Reply body."}},required:["commentId","text"]},handler:(e,r)=>{let t=r.replyTo(e.commentId,{text:e.text});return t===null?{success:false,error:`Comment #${e.commentId} not found.`}:{success:true,data:`Reply ${t} added to comment ${e.commentId}.`}}},k={name:"resolve_comment",displayName:"Resolving comment",description:"Mark a comment as resolved (done).",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."}},required:["commentId"]},handler:(e,r)=>(r.resolveComment(e.commentId),{success:true,data:`Comment ${e.commentId} resolved.`})},v={name:"scroll",displayName:"Scrolling",description:"Scroll the editor to a paragraph by paraId. Does not move the user's cursor.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."}},required:["paraId"]},handler:(e,r)=>r.scrollTo(e.paraId)?{success:true,data:`Scrolled to ${e.paraId}.`}:{success:false,error:`paraId ${e.paraId} not found.`}},i=[h,g,l,m,u,y,f,b,I,c,p,x,k,v];function _(e,r,t){let n=i.find(a=>a.name===e);if(!n)return {success:false,error:`Unknown tool: ${e}`};try{return n.handler(r,t)}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}function N(e){let r=i.find(n=>n.name===e);if(r?.displayName)return r.displayName;let t=e.replace(/_/g," ");return t.charAt(0).toUpperCase()+t.slice(1)}function w(){return i.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}export{i as a,_ as b,N as c,w as d};
7
+ `)}}},x={name:"read_changes",displayName:"Reading changes",description:"List tracked changes (insertions / deletions) currently in the document.",inputSchema:{type:"object",properties:{}},handler:(e,r)=>{let t=r.getChanges();return t.length===0?{success:true,data:"No tracked changes."}:{success:true,data:t.map(a=>`[Change #${a.id}] ${a.type} by ${a.author}: "${a.text}"`).join(`
8
+ `)}}},k={name:"add_comment",displayName:"Adding comment",description:"Attach a comment to a paragraph, optionally anchored to a unique phrase within it. The user sees it instantly in the comments sidebar.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},text:{type:"string",description:"Comment body."},search:{type:"string",description:"Optional: anchor to this exact phrase within the paragraph. Must be unique."}},required:["paraId","text"]},handler:(e,r)=>{let t=r.addComment({paraId:e.paraId,text:e.text,search:e.search});return t===null?{success:false,error:"Could not add comment. The paraId may not exist, or `search` is missing / ambiguous."}:{success:true,data:`Comment ${t} added on ${e.paraId}.`}}},T={name:"suggest_change",displayName:"Suggesting change",description:"Suggest a tracked change. Three modes: (1) replacement \u2014 `search` non-empty, `replaceWith` non-empty; (2) deletion \u2014 `search` non-empty, `replaceWith` empty; (3) insertion at paragraph end \u2014 `search` empty, `replaceWith` non-empty. The user can accept or reject in the editor UI.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."},search:{type:"string",description:"Phrase to find (must be unique). Empty string = insert at paragraph end."},replaceWith:{type:"string",description:"Replacement text. Empty string = delete the matched phrase."}},required:["paraId","search","replaceWith"]},handler:(e,r)=>r.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith})?e.search?e.replaceWith?{success:true,data:`Replacement proposed: "${e.search}" \u2192 "${e.replaceWith}" on ${e.paraId}.`}:{success:true,data:`Deletion proposed: "${e.search}" on ${e.paraId}.`}:{success:true,data:`Insertion proposed on ${e.paraId}.`}:{success:false,error:"Could not propose change. Possible causes: paraId not found; search missing or ambiguous; or the target overlaps an existing tracked change."}},v={name:"reply_comment",displayName:"Replying to comment",description:"Reply to an existing comment by id. Threaded under the original.",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."},text:{type:"string",description:"Reply body."}},required:["commentId","text"]},handler:(e,r)=>{let t=r.replyTo(e.commentId,{text:e.text});return t===null?{success:false,error:`Comment #${e.commentId} not found.`}:{success:true,data:`Reply ${t} added to comment ${e.commentId}.`}}},$={name:"resolve_comment",displayName:"Resolving comment",description:"Mark a comment as resolved (done).",inputSchema:{type:"object",properties:{commentId:{type:"number",description:"Comment id from read_comments."}},required:["commentId"]},handler:(e,r)=>(r.resolveComment(e.commentId),{success:true,data:`Comment ${e.commentId} resolved.`})},D={name:"scroll",displayName:"Scrolling",description:"Scroll the editor to a paragraph by paraId. Does not move the user's cursor.",inputSchema:{type:"object",properties:{paraId:{type:"string",description:"Paragraph id from read_document / find_text."}},required:["paraId"]},handler:(e,r)=>r.scrollTo(e.paraId)?{success:true,data:`Scrolled to ${e.paraId}.`}:{success:false,error:`paraId ${e.paraId} not found.`}},d=[y,f,g,h,b,I,x,k,T,p,m,l,v,$,D];function j(e,r,t){let n=d.find(a=>a.name===e);if(!n)return {success:false,error:`Unknown tool: ${e}`};try{return n.handler(r,t)}catch(a){return {success:false,error:a instanceof Error?a.message:String(a)}}}function P(e){let r=d.find(n=>n.name===e);if(r?.displayName)return r.displayName;let t=e.replace(/_/g," ");return t.charAt(0).toUpperCase()+t.slice(1)}function H(){return d.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}export{d as a,j as b,P as c,H as d};