@eigenpal/docx-editor-agents 0.2.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- 'use strict';var chunkGZG3RJXW_js=require('../chunk-GZG3RJXW.js'),ai=require('ai');function n(){return Object.fromEntries(chunkGZG3RJXW_js.a.map(o=>[o.name,{description:o.description,inputSchema:ai.jsonSchema(o.inputSchema)}]))}exports.getAiSdkTools=n;
1
+ 'use strict';var chunkT5P2DWHN_js=require('../chunk-T5P2DWHN.js'),ai=require('ai');function n(){return Object.fromEntries(chunkT5P2DWHN_js.a.map(o=>[o.name,{description:o.description,inputSchema:ai.jsonSchema(o.inputSchema)}]))}exports.getAiSdkTools=n;
@@ -1 +1 @@
1
- import {a}from'../chunk-S2PFUY23.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-TICYYVCD.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.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunk2MJYWSD3_js=require('./chunk-2MJYWSD3.js'),chunkDOKVZKIP_js=require('./chunk-DOKVZKIP.js'),chunkGZG3RJXW_js=require('./chunk-GZG3RJXW.js');Object.defineProperty(exports,"createEditorBridge",{enumerable:true,get:function(){return chunk2MJYWSD3_js.b}});Object.defineProperty(exports,"useAgentChat",{enumerable:true,get:function(){return chunk2MJYWSD3_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunkDOKVZKIP_js.m}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkGZG3RJXW_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkGZG3RJXW_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkGZG3RJXW_js.d}});
1
+ 'use strict';var chunkO7DEBIDX_js=require('./chunk-O7DEBIDX.js'),chunk3HEONW4M_js=require('./chunk-3HEONW4M.js'),chunkT5P2DWHN_js=require('./chunk-T5P2DWHN.js');Object.defineProperty(exports,"createEditorBridge",{enumerable:true,get:function(){return chunkO7DEBIDX_js.b}});Object.defineProperty(exports,"useAgentChat",{enumerable:true,get:function(){return chunkO7DEBIDX_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunk3HEONW4M_js.m}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkT5P2DWHN_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkT5P2DWHN_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkT5P2DWHN_js.d}});
package/dist/bridge.mjs CHANGED
@@ -1 +1 @@
1
- export{b as createEditorBridge,a as useAgentChat}from'./chunk-AITWKLUF.mjs';export{m as createReviewerBridge}from'./chunk-4OJA3FMM.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-S2PFUY23.mjs';
1
+ export{b as createEditorBridge,a as useAgentChat}from'./chunk-WGUYD2A2.mjs';export{m as createReviewerBridge}from'./chunk-AMRM73UC.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-TICYYVCD.mjs';
@@ -0,0 +1,5 @@
1
+ 'use strict';var chunkVF25WARH_js=require('./chunk-VF25WARH.js');function h(s){return s.type==="insertion"||s.type==="deletion"||s.type==="moveFrom"||s.type==="moveTo"}function x(s){let n=[];for(let o of s)o.type==="run"?n.push(chunkVF25WARH_js.Q(o)):o.type==="hyperlink"&&n.push(chunkVF25WARH_js.R(o));return n.join("")}function K(s,n){let o=0;for(let t of s.content)if(t.type==="paragraph"){if(o===n)return t;o++;}else if(t.type==="table"){for(let r of t.rows)for(let e of r.cells)for(let a of e.content)if(a.type==="paragraph"){if(o===n)return a;o++;}}else o++;throw new Error(`Paragraph index ${n} out of bounds (max: ${o-1})`)}function R(s,n){let o=0;for(let t of s.content)if(t.type==="paragraph"){if(n(t,o)===false)return;o++;}else if(t.type==="table"){for(let r of t.rows)for(let e of r.cells)for(let a of e.content)if(a.type==="paragraph"){if(n(a,o)===false)return;o++;}}else o++;}function V(s,n={}){let{fromIndex:o,toIndex:t,includeTrackedChanges:r=true,includeCommentAnchors:e=true}=n,a=[],i=0;for(let c of s.content)if(c.type==="paragraph")w(i,o,t)&&a.push(L(c,i,r,e)),i++;else if(c.type==="table"){w(i,o,t)&&a.push(H(c,i,r,e));for(let l of c.rows)for(let u of l.cells)for(let p of u.content)p.type==="paragraph"&&i++;}else i++;return a}function w(s,n,o){return (n===void 0||s>=n)&&(o===void 0||s<=o)}function L(s,n,o,t){let r=B(s,o,t),e=s.formatting?.styleId,a=s.paraId;return chunkVF25WARH_js.ba(e)?{type:"heading",index:n,paraId:a,level:chunkVF25WARH_js.ca(e)??1,text:r}:s.listRendering?{type:"list-item",index:n,paraId:a,text:r,listLevel:s.listRendering.level??0,listType:s.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:n,paraId:a,text:r}}function H(s,n,o,t){let r=[],e=[];for(let a of s.rows){let i=[],c=[];for(let l of a.cells){let u=[],p;for(let g of l.content)g.type==="paragraph"&&(p===void 0&&(p=g.paraId),u.push(B(g,o,t)));i.push(u.join(`
2
+ `)),c.push(p);}r.push(i),e.push(c);}return {type:"table",index:n,rows:r,cellParaIds:e}}function Y(s){let n=[],o=t=>t.paraId?t.paraId:String(t.index);for(let t of s)switch(t.type){case "heading":n.push(`[${o(t)}] (h${t.level}) ${t.text}`);break;case "paragraph":n.push(`[${o(t)}] ${t.text}`);break;case "list-item":{let r=" ".repeat(t.listLevel),e=t.listType==="bullet"?"\u2022":"-";n.push(`[${o(t)}] ${r}${e} ${t.text}`);break}case "table":{let r=t.index;for(let e=0;e<t.rows.length;e++)for(let a=0;a<t.rows[e].length;a++){let c=t.rows[e][a].split(`
3
+ `),l=t.cellParaIds?.[e]?.[a];for(let u=0;u<c.length;u++){let p=u===0&&l?l:String(r);n.push(`[${p}] (table, row ${e+1}, col ${a+1}) ${c[u]}`),r++;}}break}}return n.join(`
4
+ `)}function B(s,n,o){let t=[],r=new Set;for(let e of s.content){if(e.type==="commentRangeStart"&&o){r.add(e.id),t.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&o){r.has(e.id)&&(r.delete(e.id),t.push("[/comment]"));continue}if(e.type==="run")t.push(chunkVF25WARH_js.Q(e));else if(e.type==="hyperlink")t.push(chunkVF25WARH_js.R(e));else if(h(e)){let a=x(e.content);e.type==="insertion"||e.type==="moveTo"?n&&t.push(`[+${a}+]{by:${e.info.author}}`):n?t.push(`[-${a}-]{by:${e.info.author}}`):t.push(a);}}return t.join("")}var y=class extends Error{constructor(n,o){let t=o!==void 0?` in paragraph ${o}`:" in document";super(`Text not found${t}: "${n}"`),this.name="TextNotFoundError";}},M=class extends Error{constructor(n){super(`Tracked change not found: id=${n}`),this.name="ChangeNotFoundError";}},F=class extends Error{constructor(n){super(`Comment not found: id=${n}`),this.name="CommentNotFoundError";}};function E(s){let n=[],o=0;for(let t=0;t<s.content.length;t++){let r=s.content[t];if(r.type==="run"){let e=chunkVF25WARH_js.Q(r);n.push({contentIndex:t,run:r,text:e,startPos:o}),o+=e.length;}else if(r.type==="hyperlink")for(let e=0;e<r.children.length;e++){let a=r.children[e];if(a.type==="run"){let i=chunkVF25WARH_js.Q(a);n.push({contentIndex:t,run:a,text:i,startPos:o}),o+=i.length;}}else if(h(r)){if(r.type==="insertion"||r.type==="moveTo")continue;for(let e=0;e<r.content.length;e++){let a=r.content[e];if(a.type==="run"){let i=chunkVF25WARH_js.Q(a);n.push({contentIndex:t,run:a,text:i,startPos:o}),o+=i.length;}else if(a.type==="hyperlink"){for(let i of a.children)if(i.type==="run"){let c=chunkVF25WARH_js.Q(i);n.push({contentIndex:t,run:i,text:c,startPos:o}),o+=c.length;}}}}}return n}function k(s){return E(s).map(n=>n.text).join("")}function G(s,n,o){let t=E(s),r=t.map(u=>u.text).join(""),e=W(r,n);if(!e)throw new y(n,o);let a=-1,i=0;for(let u=0;u<t.length;u++)if(e.start<t[u].startPos+t[u].text.length){a=u,i=e.start-t[u].startPos;break}let c=-1,l=0;for(let u=t.length-1;u>=0;u--)if(e.end>t[u].startPos){c=u,l=e.end-t[u].startPos;break}if(a===-1||c===-1)throw new y(n,o);return {startRunIndex:t[a].contentIndex,startOffset:i,endRunIndex:t[c].contentIndex,endOffset:l}}function te(s,n,o){let t=G(s,n,o),{startRunIndex:r,endRunIndex:e}=t,{startOffset:a,endOffset:i}=t,c=s.content[e];if(c.type==="run"){let u=chunkVF25WARH_js.Q(c);if(i<u.length){let p=D(u.slice(i),c);$(c,u.slice(0,i)),s.content.splice(e+1,0,p);}}let l=s.content[r];if(l.type==="run"&&a>0){let u=chunkVF25WARH_js.Q(l),p=D(u.slice(0,a),l);$(l,u.slice(a)),s.content.splice(r,0,p),r++,e++;}return {startIndex:r,endIndex:e}}function D(s,n){return {type:"run",content:[{type:"text",text:s}],formatting:n.formatting?{...n.formatting}:void 0}}function $(s,n){let o=s.content.find(t=>t.type==="text");o&&(o.text=n);}function O(s){let n=[],o=[],t=true;for(let r=0;r<s.length;r++){let e=s[r];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"){n.push(".",".","."),o.push(r,r,r),t=false;continue}if(/\s/.test(e)||e==="\xA0"){t||(n.push(" "),o.push(r),t=true);continue}n.push(e.toLowerCase()),o.push(r),t=false;}}return n.length>0&&n[n.length-1]===" "&&(n.pop(),o.pop()),{text:n.join(""),posMap:o}}function S(s,n,o,t){let r=s.posMap[n],e=s.posMap[n+o-1]+1;for(;e<t.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(t[e]);)e++;return {start:r,end:e}}function W(s,n){if(!n||!s)return null;let o=s.indexOf(n);if(o!==-1)return {start:o,end:o+n.length};let t=O(s),r=O(n);if(!r.text)return null;let e=t.text.indexOf(r.text);if(e!==-1)return S(t,e,r.text.length,s);let a=r.text.split(" ");if(a.length>=3)for(let i=1;i<=Math.min(2,a.length-2);i++){let c=a.slice(0,-i).join(" "),l=t.text.indexOf(c);if(l!==-1)return S(t,l,c.length,s)}return null}function se(s,n){let o=new Map;return R(s,(r,e)=>{let a=null;for(let i of r.content)if(h(i)){a===null&&(a=k(r));let c=x(i.content),l=i.info.id,u=o.get(l);u&&u.paragraphIndex===e?u.text+=c:o.set(l,{id:l,type:i.type,author:i.info.author,date:i.info.date??null,text:c,context:a,paragraphIndex:e});}}),Array.from(o.values()).filter(r=>!(n?.author&&r.author!==n.author||n?.type&&r.type!==n.type))}function ae(s,n){let o=s.comments??[];if(o.length===0)return [];let t=z(s),r=[],e=new Map;for(let i of o)if(i.parentId!==void 0){let c=e.get(i.parentId)??[];c.push(i),e.set(i.parentId,c);}else r.push(i);return r.map(i=>{let c=t.get(i.id),l=(e.get(i.id)??[]).map(u=>({id:u.id,author:u.author,date:u.date??null,text:A(u)}));return {id:i.id,author:i.author,date:i.date??null,text:A(i),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:l,done:i.done??false}}).filter(i=>!(n?.author&&i.author!==n.author||n?.done!==void 0&&i.done!==n.done))}function A(s){return s.content.map(n=>k(n)).join(`
5
+ `)}function z(s){let n=new Map,o=new Map;return R(s,(t,r)=>{for(let e of t.content)if(e.type==="commentRangeStart")o.set(e.id,{paragraphIndex:r,parts:[]});else if(e.type==="commentRangeEnd"){let a=o.get(e.id);a&&(n.set(e.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),o.delete(e.id));}else if(e.type==="run"){let a=chunkVF25WARH_js.Q(e);for(let i of o.values())i.parts.push(a);}else if(e.type==="hyperlink"){let a=e.children.filter(i=>i.type==="run").map(chunkVF25WARH_js.Q).join("");for(let i of o.values())i.parts.push(a);}else if(h(e)){if(e.type==="insertion"||e.type==="moveTo")continue;let a=x(e.content);for(let i of o.values())i.parts.push(a);}}),n}function N(s){let n=s.toDocument().package?.document;if(!n)return new Map;let o=new Map,t=0;for(let r of n.content)if(r.type==="paragraph"){let e=r.paraId;e&&o.set(e,t),t++;}else if(r.type==="table")for(let e of r.rows)for(let a of e.cells)for(let i of a.content)i.type==="paragraph"&&t++;else t++;return o}function X(s){let n=[],o=t=>{for(let r of t.content)r.type==="text"&&n.push(r.text??"");};for(let t of s.content)if(t.type==="run")o(t);else if(t.type==="hyperlink")for(let r of t.children)r.type==="run"&&o(r);else if(t.type==="deletion"||t.type==="moveFrom"){for(let r of t.content)if(r.type==="run")o(r);else if(r.type==="hyperlink")for(let e of r.children)e.type==="run"&&o(e);}return n.join("")}function ce(s){let n=new Set,o=null;function t(){return o===null&&(o=N(s)),o}function r(){if(n.size===0)return;let e=s.getComments(),a=s.getChanges(),i={commentCount:e.length,changeCount:a.length,comments:e,changes:a};for(let c of n)try{c(i);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return s.getContentAsText(e)},getContent(e){return s.getContent(e)},getComments(e){return s.getComments(e)},getChanges(e){return s.getChanges(e)},findText(e,a){if(!e)return [];let i=a?.caseSensitive??false,c=a?.limit??20,l=i?e:e.toLowerCase(),u=s.toDocument().package?.document;if(!u)return [];let p=[],g=40;for(let P of u.content){if(p.length>=c)break;if(P.type!=="paragraph")continue;let C=P;if(!C.paraId)continue;let m=X(C),v=i?m:m.toLowerCase(),d=v.indexOf(l);if(d===-1||v.indexOf(l,d+1)!==-1)continue;let j=m.slice(d,d+e.length);p.push({paraId:C.paraId,match:j,before:m.slice(Math.max(0,d-g),d),after:m.slice(d+e.length,d+e.length+g)});}return p},getSelection(){return null},addComment(e){let a=t().get(e.paraId);if(a===void 0)return null;try{let i=s.addComment({paragraphIndex:a,text:e.text,author:e.author,search:e.search});return r(),i}catch{return null}},replyTo(e,a){try{let i=s.replyTo(e,a);return r(),i}catch{return null}},resolveComment(e){let i=s.toDocument().package?.document?.comments?.find(c=>c.id===e);i&&(i.done=true,r());},proposeChange(e){let a=t().get(e.paraId);if(a===void 0)return false;let i=e.search==="",c=e.replaceWith==="";if(i&&c)return false;try{return i?s.proposeInsertion({paragraphIndex:a,insertText:e.replaceWith,author:e.author}):c?s.proposeDeletion({paragraphIndex:a,search:e.search,author:e.author}):s.replace({paragraphIndex:a,search:e.search,replaceWith:e.replaceWith,author:e.author}),r(),true}catch{return false}},scrollTo(e){return t().has(e)},applyFormatting(){return false},setParagraphStyle(){return false},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return n.add(e),()=>{n.delete(e);}},onSelectionChange(){return ()=>{}}}}exports.a=h;exports.b=K;exports.c=R;exports.d=V;exports.e=Y;exports.f=y;exports.g=M;exports.h=F;exports.i=G;exports.j=te;exports.k=se;exports.l=ae;exports.m=ce;
@@ -0,0 +1,5 @@
1
+ import {ba,ca,Q,R as R$1}from'./chunk-25L7AEDN.mjs';function h(s){return s.type==="insertion"||s.type==="deletion"||s.type==="moveFrom"||s.type==="moveTo"}function x(s){let n=[];for(let o of s)o.type==="run"?n.push(Q(o)):o.type==="hyperlink"&&n.push(R$1(o));return n.join("")}function K(s,n){let o=0;for(let t of s.content)if(t.type==="paragraph"){if(o===n)return t;o++;}else if(t.type==="table"){for(let r of t.rows)for(let e of r.cells)for(let a of e.content)if(a.type==="paragraph"){if(o===n)return a;o++;}}else o++;throw new Error(`Paragraph index ${n} out of bounds (max: ${o-1})`)}function R(s,n){let o=0;for(let t of s.content)if(t.type==="paragraph"){if(n(t,o)===false)return;o++;}else if(t.type==="table"){for(let r of t.rows)for(let e of r.cells)for(let a of e.content)if(a.type==="paragraph"){if(n(a,o)===false)return;o++;}}else o++;}function V(s,n={}){let{fromIndex:o,toIndex:t,includeTrackedChanges:r=true,includeCommentAnchors:e=true}=n,a=[],i=0;for(let c of s.content)if(c.type==="paragraph")w(i,o,t)&&a.push(L(c,i,r,e)),i++;else if(c.type==="table"){w(i,o,t)&&a.push(H(c,i,r,e));for(let l of c.rows)for(let u of l.cells)for(let p of u.content)p.type==="paragraph"&&i++;}else i++;return a}function w(s,n,o){return (n===void 0||s>=n)&&(o===void 0||s<=o)}function L(s,n,o,t){let r=B(s,o,t),e=s.formatting?.styleId,a=s.paraId;return ba(e)?{type:"heading",index:n,paraId:a,level:ca(e)??1,text:r}:s.listRendering?{type:"list-item",index:n,paraId:a,text:r,listLevel:s.listRendering.level??0,listType:s.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:n,paraId:a,text:r}}function H(s,n,o,t){let r=[],e=[];for(let a of s.rows){let i=[],c=[];for(let l of a.cells){let u=[],p;for(let g of l.content)g.type==="paragraph"&&(p===void 0&&(p=g.paraId),u.push(B(g,o,t)));i.push(u.join(`
2
+ `)),c.push(p);}r.push(i),e.push(c);}return {type:"table",index:n,rows:r,cellParaIds:e}}function Y(s){let n=[],o=t=>t.paraId?t.paraId:String(t.index);for(let t of s)switch(t.type){case "heading":n.push(`[${o(t)}] (h${t.level}) ${t.text}`);break;case "paragraph":n.push(`[${o(t)}] ${t.text}`);break;case "list-item":{let r=" ".repeat(t.listLevel),e=t.listType==="bullet"?"\u2022":"-";n.push(`[${o(t)}] ${r}${e} ${t.text}`);break}case "table":{let r=t.index;for(let e=0;e<t.rows.length;e++)for(let a=0;a<t.rows[e].length;a++){let c=t.rows[e][a].split(`
3
+ `),l=t.cellParaIds?.[e]?.[a];for(let u=0;u<c.length;u++){let p=u===0&&l?l:String(r);n.push(`[${p}] (table, row ${e+1}, col ${a+1}) ${c[u]}`),r++;}}break}}return n.join(`
4
+ `)}function B(s,n,o){let t=[],r=new Set;for(let e of s.content){if(e.type==="commentRangeStart"&&o){r.add(e.id),t.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&o){r.has(e.id)&&(r.delete(e.id),t.push("[/comment]"));continue}if(e.type==="run")t.push(Q(e));else if(e.type==="hyperlink")t.push(R$1(e));else if(h(e)){let a=x(e.content);e.type==="insertion"||e.type==="moveTo"?n&&t.push(`[+${a}+]{by:${e.info.author}}`):n?t.push(`[-${a}-]{by:${e.info.author}}`):t.push(a);}}return t.join("")}var y=class extends Error{constructor(n,o){let t=o!==void 0?` in paragraph ${o}`:" in document";super(`Text not found${t}: "${n}"`),this.name="TextNotFoundError";}},M=class extends Error{constructor(n){super(`Tracked change not found: id=${n}`),this.name="ChangeNotFoundError";}},F=class extends Error{constructor(n){super(`Comment not found: id=${n}`),this.name="CommentNotFoundError";}};function E(s){let n=[],o=0;for(let t=0;t<s.content.length;t++){let r=s.content[t];if(r.type==="run"){let e=Q(r);n.push({contentIndex:t,run:r,text:e,startPos:o}),o+=e.length;}else if(r.type==="hyperlink")for(let e=0;e<r.children.length;e++){let a=r.children[e];if(a.type==="run"){let i=Q(a);n.push({contentIndex:t,run:a,text:i,startPos:o}),o+=i.length;}}else if(h(r)){if(r.type==="insertion"||r.type==="moveTo")continue;for(let e=0;e<r.content.length;e++){let a=r.content[e];if(a.type==="run"){let i=Q(a);n.push({contentIndex:t,run:a,text:i,startPos:o}),o+=i.length;}else if(a.type==="hyperlink"){for(let i of a.children)if(i.type==="run"){let c=Q(i);n.push({contentIndex:t,run:i,text:c,startPos:o}),o+=c.length;}}}}}return n}function k(s){return E(s).map(n=>n.text).join("")}function G(s,n,o){let t=E(s),r=t.map(u=>u.text).join(""),e=W(r,n);if(!e)throw new y(n,o);let a=-1,i=0;for(let u=0;u<t.length;u++)if(e.start<t[u].startPos+t[u].text.length){a=u,i=e.start-t[u].startPos;break}let c=-1,l=0;for(let u=t.length-1;u>=0;u--)if(e.end>t[u].startPos){c=u,l=e.end-t[u].startPos;break}if(a===-1||c===-1)throw new y(n,o);return {startRunIndex:t[a].contentIndex,startOffset:i,endRunIndex:t[c].contentIndex,endOffset:l}}function te(s,n,o){let t=G(s,n,o),{startRunIndex:r,endRunIndex:e}=t,{startOffset:a,endOffset:i}=t,c=s.content[e];if(c.type==="run"){let u=Q(c);if(i<u.length){let p=D(u.slice(i),c);$(c,u.slice(0,i)),s.content.splice(e+1,0,p);}}let l=s.content[r];if(l.type==="run"&&a>0){let u=Q(l),p=D(u.slice(0,a),l);$(l,u.slice(a)),s.content.splice(r,0,p),r++,e++;}return {startIndex:r,endIndex:e}}function D(s,n){return {type:"run",content:[{type:"text",text:s}],formatting:n.formatting?{...n.formatting}:void 0}}function $(s,n){let o=s.content.find(t=>t.type==="text");o&&(o.text=n);}function O(s){let n=[],o=[],t=true;for(let r=0;r<s.length;r++){let e=s[r];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"){n.push(".",".","."),o.push(r,r,r),t=false;continue}if(/\s/.test(e)||e==="\xA0"){t||(n.push(" "),o.push(r),t=true);continue}n.push(e.toLowerCase()),o.push(r),t=false;}}return n.length>0&&n[n.length-1]===" "&&(n.pop(),o.pop()),{text:n.join(""),posMap:o}}function S(s,n,o,t){let r=s.posMap[n],e=s.posMap[n+o-1]+1;for(;e<t.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(t[e]);)e++;return {start:r,end:e}}function W(s,n){if(!n||!s)return null;let o=s.indexOf(n);if(o!==-1)return {start:o,end:o+n.length};let t=O(s),r=O(n);if(!r.text)return null;let e=t.text.indexOf(r.text);if(e!==-1)return S(t,e,r.text.length,s);let a=r.text.split(" ");if(a.length>=3)for(let i=1;i<=Math.min(2,a.length-2);i++){let c=a.slice(0,-i).join(" "),l=t.text.indexOf(c);if(l!==-1)return S(t,l,c.length,s)}return null}function se(s,n){let o=new Map;return R(s,(r,e)=>{let a=null;for(let i of r.content)if(h(i)){a===null&&(a=k(r));let c=x(i.content),l=i.info.id,u=o.get(l);u&&u.paragraphIndex===e?u.text+=c:o.set(l,{id:l,type:i.type,author:i.info.author,date:i.info.date??null,text:c,context:a,paragraphIndex:e});}}),Array.from(o.values()).filter(r=>!(n?.author&&r.author!==n.author||n?.type&&r.type!==n.type))}function ae(s,n){let o=s.comments??[];if(o.length===0)return [];let t=z(s),r=[],e=new Map;for(let i of o)if(i.parentId!==void 0){let c=e.get(i.parentId)??[];c.push(i),e.set(i.parentId,c);}else r.push(i);return r.map(i=>{let c=t.get(i.id),l=(e.get(i.id)??[]).map(u=>({id:u.id,author:u.author,date:u.date??null,text:A(u)}));return {id:i.id,author:i.author,date:i.date??null,text:A(i),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:l,done:i.done??false}}).filter(i=>!(n?.author&&i.author!==n.author||n?.done!==void 0&&i.done!==n.done))}function A(s){return s.content.map(n=>k(n)).join(`
5
+ `)}function z(s){let n=new Map,o=new Map;return R(s,(t,r)=>{for(let e of t.content)if(e.type==="commentRangeStart")o.set(e.id,{paragraphIndex:r,parts:[]});else if(e.type==="commentRangeEnd"){let a=o.get(e.id);a&&(n.set(e.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),o.delete(e.id));}else if(e.type==="run"){let a=Q(e);for(let i of o.values())i.parts.push(a);}else if(e.type==="hyperlink"){let a=e.children.filter(i=>i.type==="run").map(Q).join("");for(let i of o.values())i.parts.push(a);}else if(h(e)){if(e.type==="insertion"||e.type==="moveTo")continue;let a=x(e.content);for(let i of o.values())i.parts.push(a);}}),n}function N(s){let n=s.toDocument().package?.document;if(!n)return new Map;let o=new Map,t=0;for(let r of n.content)if(r.type==="paragraph"){let e=r.paraId;e&&o.set(e,t),t++;}else if(r.type==="table")for(let e of r.rows)for(let a of e.cells)for(let i of a.content)i.type==="paragraph"&&t++;else t++;return o}function X(s){let n=[],o=t=>{for(let r of t.content)r.type==="text"&&n.push(r.text??"");};for(let t of s.content)if(t.type==="run")o(t);else if(t.type==="hyperlink")for(let r of t.children)r.type==="run"&&o(r);else if(t.type==="deletion"||t.type==="moveFrom"){for(let r of t.content)if(r.type==="run")o(r);else if(r.type==="hyperlink")for(let e of r.children)e.type==="run"&&o(e);}return n.join("")}function ce(s){let n=new Set,o=null;function t(){return o===null&&(o=N(s)),o}function r(){if(n.size===0)return;let e=s.getComments(),a=s.getChanges(),i={commentCount:e.length,changeCount:a.length,comments:e,changes:a};for(let c of n)try{c(i);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return s.getContentAsText(e)},getContent(e){return s.getContent(e)},getComments(e){return s.getComments(e)},getChanges(e){return s.getChanges(e)},findText(e,a){if(!e)return [];let i=a?.caseSensitive??false,c=a?.limit??20,l=i?e:e.toLowerCase(),u=s.toDocument().package?.document;if(!u)return [];let p=[],g=40;for(let P of u.content){if(p.length>=c)break;if(P.type!=="paragraph")continue;let C=P;if(!C.paraId)continue;let m=X(C),v=i?m:m.toLowerCase(),d=v.indexOf(l);if(d===-1||v.indexOf(l,d+1)!==-1)continue;let j=m.slice(d,d+e.length);p.push({paraId:C.paraId,match:j,before:m.slice(Math.max(0,d-g),d),after:m.slice(d+e.length,d+e.length+g)});}return p},getSelection(){return null},addComment(e){let a=t().get(e.paraId);if(a===void 0)return null;try{let i=s.addComment({paragraphIndex:a,text:e.text,author:e.author,search:e.search});return r(),i}catch{return null}},replyTo(e,a){try{let i=s.replyTo(e,a);return r(),i}catch{return null}},resolveComment(e){let i=s.toDocument().package?.document?.comments?.find(c=>c.id===e);i&&(i.done=true,r());},proposeChange(e){let a=t().get(e.paraId);if(a===void 0)return false;let i=e.search==="",c=e.replaceWith==="";if(i&&c)return false;try{return i?s.proposeInsertion({paragraphIndex:a,insertText:e.replaceWith,author:e.author}):c?s.proposeDeletion({paragraphIndex:a,search:e.search,author:e.author}):s.replace({paragraphIndex:a,search:e.search,replaceWith:e.replaceWith,author:e.author}),r(),true}catch{return false}},scrollTo(e){return t().has(e)},applyFormatting(){return false},setParagraphStyle(){return false},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return n.add(e),()=>{n.delete(e);}},onSelectionChange(){return ()=>{}}}}export{h as a,K as b,R as c,V as d,Y as e,y as f,M as g,F as h,G as i,te as j,se as k,ae as l,ce as m};
@@ -1 +1 @@
1
- import {d,e,k as k$1,l,b,i,h,c,j,g as g$1,a}from'./chunk-4OJA3FMM.mjs';import {F as F$1}from'./chunk-25L7AEDN.mjs';function g(o,e){let{paragraphIndex:t,author:n="AI",text:s,search:a}=e,r=b(o,t),p=(o.comments??[]).map(m=>m.id),i$1=p.length>0?Math.max(...p)+1:1,c={id:i$1,author:n,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(o.comments||(o.comments=[]),o.comments.push(c),a){let m=i(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:i$1}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:i$1});}else r.content.unshift({type:"commentRangeStart",id:i$1}),r.content.push({type:"commentRangeEnd",id:i$1});return i$1}function y(o,e,t){let n=o.comments??[];if(!n.find(i=>i.id===e))throw new h(e);let a=n.map(i=>i.id),r=Math.max(...a)+1,p={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 n.push(p),r}function E(o,e){let t=o.comments??[],n=t.find(r=>r.id===e);if(!n)throw new h(e);let s=n.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);o.comments=t.filter(r=>!a.has(r.id)),!s&&c(o,r=>{for(let p=r.content.length-1;p>=0;p--){let i=r.content[p];(i.type==="commentRangeStart"||i.type==="commentRangeEnd")&&i.id===e&&r.content.splice(p,1);}});}function C(o,e){if(!W(o,e,"accept"))throw new g$1(e)}function I(o,e){if(!W(o,e,"reject"))throw new g$1(e)}function k(o){return M(o,"accept")}function F(o){return M(o,"reject")}function M(o,e){let t=0;return c(o,n=>{for(let s=n.content.length-1;s>=0;s--){let a$1=n.content[s];a(a$1)&&(G(n,s,a$1,e),t++);}}),t}function W(o,e,t){let n=false;return c(o,s=>{for(let a$1=s.content.length-1;a$1>=0;a$1--){let r=s.content[a$1];a(r)&&r.info.id===e&&(G(s,a$1,r,t),n=true);}if(n)return false}),n}function G(o,e,t,n){if(t.type==="insertion"&&n==="accept"||t.type==="deletion"&&n==="reject"||t.type==="moveTo"&&n==="accept"||t.type==="moveFrom"&&n==="reject"){let a=t.content;o.content.splice(e,1,...a);}else o.content.splice(e,1);}function x(o,e){let{paragraphIndex:t,search:n,author:s="AI",replaceWith:a}=e,r=b(o,t),{startIndex:p,endIndex:i}=j(r,n,t),c=new Date().toISOString(),m=w(o),d=r.content.slice(p,i+1),R={type:"deletion",info:{id:m,author:s,date:c},content:d},v={type:"insertion",info:{id:m+1,author:s,date:c},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(p,i-p+1,R,v);}function H(o,e){let{paragraphIndex:t,author:n="AI",insertText:s,position:a="after",search:r}=e,p=b(o,t),i=new Date().toISOString(),m={type:"insertion",info:{id:w(o),author:n,date:i},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:R}=j(p,r,t),v=a==="after"?R+1:d;p.content.splice(v,0,m);}else a==="before"?p.content.unshift(m):p.content.push(m);}function L(o,e){let{paragraphIndex:t,search:n,author:s="AI"}=e,a=b(o,t),{startIndex:r,endIndex:p}=j(a,n,t),i=new Date().toISOString(),c=w(o),m=a.content.slice(r,p+1),d={type:"deletion",info:{id:c,author:s,date:i},content:m};a.content.splice(r,p-r+1,d);}var S=new WeakMap;function w(o){let e=S.get(o);e===void 0&&(e=0,c(o,n=>{for(let s of n.content)a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(o,t+1),t}function N(o,e,t="AI"){let n=[],s=0,a=0,r=0,p=0,i=0;for(let c of e.accept??[])try{C(o,c),s++;}catch(m){n.push({operation:"accept",id:c,error:m.message});}for(let c of e.reject??[])try{I(o,c),a++;}catch(m){n.push({operation:"reject",id:c,error:m.message});}for(let c of e.comments??[])try{g(o,{...c,author:c.author??t}),r++;}catch(m){n.push({operation:"comment",search:c.search,error:m.message});}for(let c of e.replies??[])try{y(o,c.commentId,{author:c.author??t,text:c.text}),p++;}catch(m){n.push({operation:"reply",id:c.commentId,error:m.message});}for(let c of e.proposals??[])try{x(o,{...c,author:c.author??t}),i++;}catch(m){n.push({operation:"proposal",search:c.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:p,proposalsAdded:i,errors:n}}var U=class o{constructor(e,t="AI",n){let s=n??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 n=await F$1(e,{preloadFonts:false});return new o(n,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return d(this.body,e)}getContentAsText(e$1){return e(d(this.body,e$1))}getChanges(e){return k$1(this.body,e)}getComments(e){return l(this.body,e)}addComment(e,t){let n=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return g(this.body,n)}replyTo(e,t){let n=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return y(this.body,e,n)}removeComment(e){E(this.body,e);}replace(e,t,n){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:n,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){C(this.body,e);}rejectChange(e){I(this.body,e);}acceptAll(){return k(this.body)}rejectAll(){return F(this.body)}applyReview(e){return N(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-PZWHORT6.mjs');return e(this.doc)}};export{U as a};
1
+ import {d,e,k as k$1,l,b,i,h,c,j,g as g$1,a}from'./chunk-AMRM73UC.mjs';import {F as F$1}from'./chunk-25L7AEDN.mjs';function g(o,e){let{paragraphIndex:t,author:n="AI",text:s,search:a}=e,r=b(o,t),p=(o.comments??[]).map(m=>m.id),i$1=p.length>0?Math.max(...p)+1:1,c={id:i$1,author:n,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(o.comments||(o.comments=[]),o.comments.push(c),a){let m=i(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:i$1}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:i$1});}else r.content.unshift({type:"commentRangeStart",id:i$1}),r.content.push({type:"commentRangeEnd",id:i$1});return i$1}function y(o,e,t){let n=o.comments??[];if(!n.find(i=>i.id===e))throw new h(e);let a=n.map(i=>i.id),r=Math.max(...a)+1,p={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 n.push(p),r}function E(o,e){let t=o.comments??[],n=t.find(r=>r.id===e);if(!n)throw new h(e);let s=n.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);o.comments=t.filter(r=>!a.has(r.id)),!s&&c(o,r=>{for(let p=r.content.length-1;p>=0;p--){let i=r.content[p];(i.type==="commentRangeStart"||i.type==="commentRangeEnd")&&i.id===e&&r.content.splice(p,1);}});}function C(o,e){if(!W(o,e,"accept"))throw new g$1(e)}function I(o,e){if(!W(o,e,"reject"))throw new g$1(e)}function k(o){return M(o,"accept")}function F(o){return M(o,"reject")}function M(o,e){let t=0;return c(o,n=>{for(let s=n.content.length-1;s>=0;s--){let a$1=n.content[s];a(a$1)&&(G(n,s,a$1,e),t++);}}),t}function W(o,e,t){let n=false;return c(o,s=>{for(let a$1=s.content.length-1;a$1>=0;a$1--){let r=s.content[a$1];a(r)&&r.info.id===e&&(G(s,a$1,r,t),n=true);}if(n)return false}),n}function G(o,e,t,n){if(t.type==="insertion"&&n==="accept"||t.type==="deletion"&&n==="reject"||t.type==="moveTo"&&n==="accept"||t.type==="moveFrom"&&n==="reject"){let a=t.content;o.content.splice(e,1,...a);}else o.content.splice(e,1);}function x(o,e){let{paragraphIndex:t,search:n,author:s="AI",replaceWith:a}=e,r=b(o,t),{startIndex:p,endIndex:i}=j(r,n,t),c=new Date().toISOString(),m=w(o),d=r.content.slice(p,i+1),R={type:"deletion",info:{id:m,author:s,date:c},content:d},v={type:"insertion",info:{id:m+1,author:s,date:c},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(p,i-p+1,R,v);}function H(o,e){let{paragraphIndex:t,author:n="AI",insertText:s,position:a="after",search:r}=e,p=b(o,t),i=new Date().toISOString(),m={type:"insertion",info:{id:w(o),author:n,date:i},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:R}=j(p,r,t),v=a==="after"?R+1:d;p.content.splice(v,0,m);}else a==="before"?p.content.unshift(m):p.content.push(m);}function L(o,e){let{paragraphIndex:t,search:n,author:s="AI"}=e,a=b(o,t),{startIndex:r,endIndex:p}=j(a,n,t),i=new Date().toISOString(),c=w(o),m=a.content.slice(r,p+1),d={type:"deletion",info:{id:c,author:s,date:i},content:m};a.content.splice(r,p-r+1,d);}var S=new WeakMap;function w(o){let e=S.get(o);e===void 0&&(e=0,c(o,n=>{for(let s of n.content)a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(o,t+1),t}function N(o,e,t="AI"){let n=[],s=0,a=0,r=0,p=0,i=0;for(let c of e.accept??[])try{C(o,c),s++;}catch(m){n.push({operation:"accept",id:c,error:m.message});}for(let c of e.reject??[])try{I(o,c),a++;}catch(m){n.push({operation:"reject",id:c,error:m.message});}for(let c of e.comments??[])try{g(o,{...c,author:c.author??t}),r++;}catch(m){n.push({operation:"comment",search:c.search,error:m.message});}for(let c of e.replies??[])try{y(o,c.commentId,{author:c.author??t,text:c.text}),p++;}catch(m){n.push({operation:"reply",id:c.commentId,error:m.message});}for(let c of e.proposals??[])try{x(o,{...c,author:c.author??t}),i++;}catch(m){n.push({operation:"proposal",search:c.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:p,proposalsAdded:i,errors:n}}var U=class o{constructor(e,t="AI",n){let s=n??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 n=await F$1(e,{preloadFonts:false});return new o(n,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return d(this.body,e)}getContentAsText(e$1){return e(d(this.body,e$1))}getChanges(e){return k$1(this.body,e)}getComments(e){return l(this.body,e)}addComment(e,t){let n=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return g(this.body,n)}replyTo(e,t){let n=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return y(this.body,e,n)}removeComment(e){E(this.body,e);}replace(e,t,n){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:n,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){C(this.body,e);}rejectChange(e){I(this.body,e);}acceptAll(){return k(this.body)}rejectAll(){return F(this.body)}applyReview(e){return N(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-PZWHORT6.mjs');return e(this.doc)}};export{U as a};
@@ -1,2 +1,2 @@
1
- 'use strict';var chunkDOKVZKIP_js=require('./chunk-DOKVZKIP.js'),chunkGZG3RJXW_js=require('./chunk-GZG3RJXW.js'),react=require('react');var S=chunkGZG3RJXW_js.d();function T(t){let{editorRef:a,author:s="AI"}=t,e=react.useMemo(()=>({get:()=>a.current?I(a.current,s):null}),[a,s]);return {executeToolCall:react.useCallback((l,i)=>{let r=e.get();return r?chunkGZG3RJXW_js.b(l,i,r):{success:false,error:"Editor not ready"}},[e]),toolSchemas:S}}function x(t){return !t||t.length===0?"":t.map(a=>{let s=a;return s?.content?s.content.map(e=>e.content?.map(n=>n.text||"").join("")||"").join(""):""}).join(`
2
- `)}function m(t){let a=t.getEditorRef();if(a){let e=a.getDocument();if(e?.package?.document)return e.package.document}return t.getDocument()?.package?.document??null}function I(t,a="AI"){function s(e){return e??a}return {getContentAsText(e){let n=m(t);return n?chunkDOKVZKIP_js.e(chunkDOKVZKIP_js.d(n,e)):""},getContent(e){let n=m(t);return n?chunkDOKVZKIP_js.d(n,e):[]},getComments(e){let n=m(t);if(!n)return [];let l=chunkDOKVZKIP_js.l(n,e);if(l.length>0)return l;let i=t.getComments();if(i.length===0)return [];let r=new Map,g=[];for(let o of i)if(o.parentId){let c=r.get(o.parentId);c?c.push(o):r.set(o.parentId,[o]);}else g.push(o);let u=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let c=r.get(o.id)??[];u.push({id:o.id,author:o.author,date:o.date??null,text:x(o.content),anchoredText:"",paragraphIndex:-1,replies:c.map(p=>({id:p.id,author:p.author,date:p.date??null,text:x(p.content)})),done:o.done??false});}return u},getChanges(e){let n=m(t);return n?chunkDOKVZKIP_js.k(n,e):[]},findText(e,n){return t.findInDocument(e,n)},getSelection(){return t.getSelectionInfo()},addComment(e){return t.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,n){return t.replyToComment(e,n.text,s(n.author))},resolveComment(e){t.resolveComment(e);},proposeChange(e){return t.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return t.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return t.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},getPage(e){return t.getPageContent(e)},getPages(e){let n=t.getTotalPages(),l=Math.max(1,Math.min(e.from,n)),i=Math.max(l,Math.min(e.to,n)),r=[];for(let g=l;g<=i;g++){let u=t.getPageContent(g);u&&r.push(u);}return r},getTotalPages(){return t.getTotalPages()},getCurrentPage(){return t.getCurrentPage()},scrollTo(e){return t.scrollToParaId(e)},onContentChange(e){return t.onContentChange(()=>{let n=m(t),l=n?chunkDOKVZKIP_js.l(n):[],i=n?chunkDOKVZKIP_js.k(n):[];try{e({commentCount:l.length,changeCount:i.length,comments:l,changes:i});}catch(r){console.error("onContentChange listener threw:",r);}})},onSelectionChange(e){return t.onSelectionChange(()=>{try{e(t.getSelectionInfo());}catch(n){console.error("onSelectionChange listener threw:",n);}})}}}exports.a=T;exports.b=I;
1
+ 'use strict';var chunk3HEONW4M_js=require('./chunk-3HEONW4M.js'),chunkT5P2DWHN_js=require('./chunk-T5P2DWHN.js'),react=require('react');var S=chunkT5P2DWHN_js.d();function T(t){let{editorRef:a,author:s="AI"}=t,e=react.useMemo(()=>({get:()=>a.current?I(a.current,s):null}),[a,s]);return {executeToolCall:react.useCallback((l,i)=>{let r=e.get();return r?chunkT5P2DWHN_js.b(l,i,r):{success:false,error:"Editor not ready"}},[e]),toolSchemas:S}}function x(t){return !t||t.length===0?"":t.map(a=>{let s=a;return s?.content?s.content.map(e=>e.content?.map(n=>n.text||"").join("")||"").join(""):""}).join(`
2
+ `)}function m(t){let a=t.getEditorRef();if(a){let e=a.getDocument();if(e?.package?.document)return e.package.document}return t.getDocument()?.package?.document??null}function I(t,a="AI"){function s(e){return e??a}return {getContentAsText(e){let n=m(t);return n?chunk3HEONW4M_js.e(chunk3HEONW4M_js.d(n,e)):""},getContent(e){let n=m(t);return n?chunk3HEONW4M_js.d(n,e):[]},getComments(e){let n=m(t);if(!n)return [];let l=chunk3HEONW4M_js.l(n,e);if(l.length>0)return l;let i=t.getComments();if(i.length===0)return [];let r=new Map,g=[];for(let o of i)if(o.parentId){let c=r.get(o.parentId);c?c.push(o):r.set(o.parentId,[o]);}else g.push(o);let u=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let c=r.get(o.id)??[];u.push({id:o.id,author:o.author,date:o.date??null,text:x(o.content),anchoredText:"",paragraphIndex:-1,replies:c.map(p=>({id:p.id,author:p.author,date:p.date??null,text:x(p.content)})),done:o.done??false});}return u},getChanges(e){let n=m(t);return n?chunk3HEONW4M_js.k(n,e):[]},findText(e,n){return t.findInDocument(e,n)},getSelection(){return t.getSelectionInfo()},addComment(e){return t.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,n){return t.replyToComment(e,n.text,s(n.author))},resolveComment(e){t.resolveComment(e);},proposeChange(e){return t.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return t.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return t.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},getPage(e){return t.getPageContent(e)},getPages(e){let n=t.getTotalPages(),l=Math.max(1,Math.min(e.from,n)),i=Math.max(l,Math.min(e.to,n)),r=[];for(let g=l;g<=i;g++){let u=t.getPageContent(g);u&&r.push(u);}return r},getTotalPages(){return t.getTotalPages()},getCurrentPage(){return t.getCurrentPage()},scrollTo(e){return t.scrollToParaId(e)},onContentChange(e){return t.onContentChange(()=>{let n=m(t),l=n?chunk3HEONW4M_js.l(n):[],i=n?chunk3HEONW4M_js.k(n):[];try{e({commentCount:l.length,changeCount:i.length,comments:l,changes:i});}catch(r){console.error("onContentChange listener threw:",r);}})},onSelectionChange(e){return t.onSelectionChange(()=>{try{e(t.getSelectionInfo());}catch(n){console.error("onSelectionChange listener threw:",n);}})}}}exports.a=T;exports.b=I;
@@ -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 empty string 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;return n&&!o.includes(n)?{success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`}:r.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})?{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 m={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)"}}},l={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 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 empty string 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;return n&&!o.includes(n)?{success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`}:r.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})?{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} ---
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. Tracked changes and comment markers are stripped; use read_comments / read_changes to inspect them.',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 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?`
5
5
  `+a.replies.map(s=>` Reply by ${s.author}: "${s.text}"`).join(`
6
6
  `):"")).join(`
7
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.`})},T={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,m,l,u,y,f,b,I,c,p,x,k,T];function C(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 _(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 N(){return i.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}exports.a=i;exports.b=C;exports.c=_;exports.d=N;
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 C(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 _(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 N(){return i.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}exports.a=i;exports.b=C;exports.c=_;exports.d=N;
@@ -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 empty string 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;return n&&!o.includes(n)?{success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`}:r.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})?{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 m={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)"}}},l={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 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 empty string 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;return n&&!o.includes(n)?{success:false,error:`Invalid highlight "${n}". Must be one of: ${o.join(", ")}. Hex values are not supported by Word's highlight attribute.`}:r.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})?{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} ---
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. Tracked changes and comment markers are stripped; use read_comments / read_changes to inspect them.',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 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?`
5
5
  `+a.replies.map(s=>` Reply by ${s.author}: "${s.text}"`).join(`
6
6
  `):"")).join(`
7
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.`})},T={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,m,l,u,y,f,b,I,c,p,x,k,T];function C(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 _(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 N(){return i.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}export{i as a,C as b,_ as c,N as d};
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 C(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 _(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 N(){return i.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))}export{i as a,C as b,_ as c,N as d};
@@ -1 +1 @@
1
- 'use strict';var chunkDOKVZKIP_js=require('./chunk-DOKVZKIP.js'),chunkVF25WARH_js=require('./chunk-VF25WARH.js');function g(o,e){let{paragraphIndex:t,author:n="AI",text:s,search:a}=e,r=chunkDOKVZKIP_js.b(o,t),p=(o.comments??[]).map(m=>m.id),i=p.length>0?Math.max(...p)+1:1,c={id:i,author:n,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(o.comments||(o.comments=[]),o.comments.push(c),a){let m=chunkDOKVZKIP_js.i(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:i}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:i});}else r.content.unshift({type:"commentRangeStart",id:i}),r.content.push({type:"commentRangeEnd",id:i});return i}function y(o,e,t){let n=o.comments??[];if(!n.find(i=>i.id===e))throw new chunkDOKVZKIP_js.h(e);let a=n.map(i=>i.id),r=Math.max(...a)+1,p={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 n.push(p),r}function E(o,e){let t=o.comments??[],n=t.find(r=>r.id===e);if(!n)throw new chunkDOKVZKIP_js.h(e);let s=n.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);o.comments=t.filter(r=>!a.has(r.id)),!s&&chunkDOKVZKIP_js.c(o,r=>{for(let p=r.content.length-1;p>=0;p--){let i=r.content[p];(i.type==="commentRangeStart"||i.type==="commentRangeEnd")&&i.id===e&&r.content.splice(p,1);}});}function C(o,e){if(!W(o,e,"accept"))throw new chunkDOKVZKIP_js.g(e)}function I(o,e){if(!W(o,e,"reject"))throw new chunkDOKVZKIP_js.g(e)}function k(o){return M(o,"accept")}function F(o){return M(o,"reject")}function M(o,e){let t=0;return chunkDOKVZKIP_js.c(o,n=>{for(let s=n.content.length-1;s>=0;s--){let a=n.content[s];chunkDOKVZKIP_js.a(a)&&(G(n,s,a,e),t++);}}),t}function W(o,e,t){let n=false;return chunkDOKVZKIP_js.c(o,s=>{for(let a=s.content.length-1;a>=0;a--){let r=s.content[a];chunkDOKVZKIP_js.a(r)&&r.info.id===e&&(G(s,a,r,t),n=true);}if(n)return false}),n}function G(o,e,t,n){if(t.type==="insertion"&&n==="accept"||t.type==="deletion"&&n==="reject"||t.type==="moveTo"&&n==="accept"||t.type==="moveFrom"&&n==="reject"){let a=t.content;o.content.splice(e,1,...a);}else o.content.splice(e,1);}function x(o,e){let{paragraphIndex:t,search:n,author:s="AI",replaceWith:a}=e,r=chunkDOKVZKIP_js.b(o,t),{startIndex:p,endIndex:i}=chunkDOKVZKIP_js.j(r,n,t),c=new Date().toISOString(),m=w(o),d=r.content.slice(p,i+1),R={type:"deletion",info:{id:m,author:s,date:c},content:d},v={type:"insertion",info:{id:m+1,author:s,date:c},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(p,i-p+1,R,v);}function H(o,e){let{paragraphIndex:t,author:n="AI",insertText:s,position:a="after",search:r}=e,p=chunkDOKVZKIP_js.b(o,t),i=new Date().toISOString(),m={type:"insertion",info:{id:w(o),author:n,date:i},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:R}=chunkDOKVZKIP_js.j(p,r,t),v=a==="after"?R+1:d;p.content.splice(v,0,m);}else a==="before"?p.content.unshift(m):p.content.push(m);}function L(o,e){let{paragraphIndex:t,search:n,author:s="AI"}=e,a=chunkDOKVZKIP_js.b(o,t),{startIndex:r,endIndex:p}=chunkDOKVZKIP_js.j(a,n,t),i=new Date().toISOString(),c=w(o),m=a.content.slice(r,p+1),d={type:"deletion",info:{id:c,author:s,date:i},content:m};a.content.splice(r,p-r+1,d);}var S=new WeakMap;function w(o){let e=S.get(o);e===void 0&&(e=0,chunkDOKVZKIP_js.c(o,n=>{for(let s of n.content)chunkDOKVZKIP_js.a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(o,t+1),t}function N(o,e,t="AI"){let n=[],s=0,a=0,r=0,p=0,i=0;for(let c of e.accept??[])try{C(o,c),s++;}catch(m){n.push({operation:"accept",id:c,error:m.message});}for(let c of e.reject??[])try{I(o,c),a++;}catch(m){n.push({operation:"reject",id:c,error:m.message});}for(let c of e.comments??[])try{g(o,{...c,author:c.author??t}),r++;}catch(m){n.push({operation:"comment",search:c.search,error:m.message});}for(let c of e.replies??[])try{y(o,c.commentId,{author:c.author??t,text:c.text}),p++;}catch(m){n.push({operation:"reply",id:c.commentId,error:m.message});}for(let c of e.proposals??[])try{x(o,{...c,author:c.author??t}),i++;}catch(m){n.push({operation:"proposal",search:c.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:p,proposalsAdded:i,errors:n}}var U=class o{constructor(e,t="AI",n){let s=n??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 n=await chunkVF25WARH_js.F(e,{preloadFonts:false});return new o(n,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return chunkDOKVZKIP_js.d(this.body,e)}getContentAsText(e){return chunkDOKVZKIP_js.e(chunkDOKVZKIP_js.d(this.body,e))}getChanges(e){return chunkDOKVZKIP_js.k(this.body,e)}getComments(e){return chunkDOKVZKIP_js.l(this.body,e)}addComment(e,t){let n=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return g(this.body,n)}replyTo(e,t){let n=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return y(this.body,e,n)}removeComment(e){E(this.body,e);}replace(e,t,n){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:n,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){C(this.body,e);}rejectChange(e){I(this.body,e);}acceptAll(){return k(this.body)}rejectAll(){return F(this.body)}applyReview(e){return N(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-B7TGKW6I.js');return e(this.doc)}};exports.a=U;
1
+ 'use strict';var chunk3HEONW4M_js=require('./chunk-3HEONW4M.js'),chunkVF25WARH_js=require('./chunk-VF25WARH.js');function g(o,e){let{paragraphIndex:t,author:n="AI",text:s,search:a}=e,r=chunk3HEONW4M_js.b(o,t),p=(o.comments??[]).map(m=>m.id),i=p.length>0?Math.max(...p)+1:1,c={id:i,author:n,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(o.comments||(o.comments=[]),o.comments.push(c),a){let m=chunk3HEONW4M_js.i(r,a,t);r.content.splice(m.endRunIndex+1,0,{type:"commentRangeEnd",id:i}),r.content.splice(m.startRunIndex,0,{type:"commentRangeStart",id:i});}else r.content.unshift({type:"commentRangeStart",id:i}),r.content.push({type:"commentRangeEnd",id:i});return i}function y(o,e,t){let n=o.comments??[];if(!n.find(i=>i.id===e))throw new chunk3HEONW4M_js.h(e);let a=n.map(i=>i.id),r=Math.max(...a)+1,p={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 n.push(p),r}function E(o,e){let t=o.comments??[],n=t.find(r=>r.id===e);if(!n)throw new chunk3HEONW4M_js.h(e);let s=n.parentId!==void 0,a=new Set([e]);if(!s)for(let r of t)r.parentId===e&&a.add(r.id);o.comments=t.filter(r=>!a.has(r.id)),!s&&chunk3HEONW4M_js.c(o,r=>{for(let p=r.content.length-1;p>=0;p--){let i=r.content[p];(i.type==="commentRangeStart"||i.type==="commentRangeEnd")&&i.id===e&&r.content.splice(p,1);}});}function C(o,e){if(!W(o,e,"accept"))throw new chunk3HEONW4M_js.g(e)}function I(o,e){if(!W(o,e,"reject"))throw new chunk3HEONW4M_js.g(e)}function k(o){return M(o,"accept")}function F(o){return M(o,"reject")}function M(o,e){let t=0;return chunk3HEONW4M_js.c(o,n=>{for(let s=n.content.length-1;s>=0;s--){let a=n.content[s];chunk3HEONW4M_js.a(a)&&(G(n,s,a,e),t++);}}),t}function W(o,e,t){let n=false;return chunk3HEONW4M_js.c(o,s=>{for(let a=s.content.length-1;a>=0;a--){let r=s.content[a];chunk3HEONW4M_js.a(r)&&r.info.id===e&&(G(s,a,r,t),n=true);}if(n)return false}),n}function G(o,e,t,n){if(t.type==="insertion"&&n==="accept"||t.type==="deletion"&&n==="reject"||t.type==="moveTo"&&n==="accept"||t.type==="moveFrom"&&n==="reject"){let a=t.content;o.content.splice(e,1,...a);}else o.content.splice(e,1);}function x(o,e){let{paragraphIndex:t,search:n,author:s="AI",replaceWith:a}=e,r=chunk3HEONW4M_js.b(o,t),{startIndex:p,endIndex:i}=chunk3HEONW4M_js.j(r,n,t),c=new Date().toISOString(),m=w(o),d=r.content.slice(p,i+1),R={type:"deletion",info:{id:m,author:s,date:c},content:d},v={type:"insertion",info:{id:m+1,author:s,date:c},content:[{type:"run",content:[{type:"text",text:a}]}]};r.content.splice(p,i-p+1,R,v);}function H(o,e){let{paragraphIndex:t,author:n="AI",insertText:s,position:a="after",search:r}=e,p=chunk3HEONW4M_js.b(o,t),i=new Date().toISOString(),m={type:"insertion",info:{id:w(o),author:n,date:i},content:[{type:"run",content:[{type:"text",text:s}]}]};if(r){let{startIndex:d,endIndex:R}=chunk3HEONW4M_js.j(p,r,t),v=a==="after"?R+1:d;p.content.splice(v,0,m);}else a==="before"?p.content.unshift(m):p.content.push(m);}function L(o,e){let{paragraphIndex:t,search:n,author:s="AI"}=e,a=chunk3HEONW4M_js.b(o,t),{startIndex:r,endIndex:p}=chunk3HEONW4M_js.j(a,n,t),i=new Date().toISOString(),c=w(o),m=a.content.slice(r,p+1),d={type:"deletion",info:{id:c,author:s,date:i},content:m};a.content.splice(r,p-r+1,d);}var S=new WeakMap;function w(o){let e=S.get(o);e===void 0&&(e=0,chunk3HEONW4M_js.c(o,n=>{for(let s of n.content)chunk3HEONW4M_js.a(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return S.set(o,t+1),t}function N(o,e,t="AI"){let n=[],s=0,a=0,r=0,p=0,i=0;for(let c of e.accept??[])try{C(o,c),s++;}catch(m){n.push({operation:"accept",id:c,error:m.message});}for(let c of e.reject??[])try{I(o,c),a++;}catch(m){n.push({operation:"reject",id:c,error:m.message});}for(let c of e.comments??[])try{g(o,{...c,author:c.author??t}),r++;}catch(m){n.push({operation:"comment",search:c.search,error:m.message});}for(let c of e.replies??[])try{y(o,c.commentId,{author:c.author??t,text:c.text}),p++;}catch(m){n.push({operation:"reply",id:c.commentId,error:m.message});}for(let c of e.proposals??[])try{x(o,{...c,author:c.author??t}),i++;}catch(m){n.push({operation:"proposal",search:c.search,error:m.message});}return {accepted:s,rejected:a,commentsAdded:r,repliesAdded:p,proposalsAdded:i,errors:n}}var U=class o{constructor(e,t="AI",n){let s=n??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 n=await chunkVF25WARH_js.F(e,{preloadFonts:false});return new o(n,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return chunk3HEONW4M_js.d(this.body,e)}getContentAsText(e){return chunk3HEONW4M_js.e(chunk3HEONW4M_js.d(this.body,e))}getChanges(e){return chunk3HEONW4M_js.k(this.body,e)}getComments(e){return chunk3HEONW4M_js.l(this.body,e)}addComment(e,t){let n=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return g(this.body,n)}replyTo(e,t){let n=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return y(this.body,e,n)}removeComment(e){E(this.body,e);}replace(e,t,n){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:n,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){C(this.body,e);}rejectChange(e){I(this.body,e);}acceptAll(){return k(this.body)}rejectAll(){return F(this.body)}applyReview(e){return N(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-B7TGKW6I.js');return e(this.doc)}};exports.a=U;
@@ -1,2 +1,2 @@
1
- import {l,k,d as d$1,e}from'./chunk-4OJA3FMM.mjs';import {d,b}from'./chunk-S2PFUY23.mjs';import {useMemo,useCallback}from'react';var S=d();function T(t){let{editorRef:a,author:s="AI"}=t,e=useMemo(()=>({get:()=>a.current?I(a.current,s):null}),[a,s]);return {executeToolCall:useCallback((l,i)=>{let r=e.get();return r?b(l,i,r):{success:false,error:"Editor not ready"}},[e]),toolSchemas:S}}function x(t){return !t||t.length===0?"":t.map(a=>{let s=a;return s?.content?s.content.map(e=>e.content?.map(n=>n.text||"").join("")||"").join(""):""}).join(`
1
+ import {l,k,d as d$1,e}from'./chunk-AMRM73UC.mjs';import {d,b}from'./chunk-TICYYVCD.mjs';import {useMemo,useCallback}from'react';var S=d();function T(t){let{editorRef:a,author:s="AI"}=t,e=useMemo(()=>({get:()=>a.current?I(a.current,s):null}),[a,s]);return {executeToolCall:useCallback((l,i)=>{let r=e.get();return r?b(l,i,r):{success:false,error:"Editor not ready"}},[e]),toolSchemas:S}}function x(t){return !t||t.length===0?"":t.map(a=>{let s=a;return s?.content?s.content.map(e=>e.content?.map(n=>n.text||"").join("")||"").join(""):""}).join(`
2
2
  `)}function m(t){let a=t.getEditorRef();if(a){let e=a.getDocument();if(e?.package?.document)return e.package.document}return t.getDocument()?.package?.document??null}function I(t,a="AI"){function s(e){return e??a}return {getContentAsText(e$1){let n=m(t);return n?e(d$1(n,e$1)):""},getContent(e){let n=m(t);return n?d$1(n,e):[]},getComments(e){let n=m(t);if(!n)return [];let l$1=l(n,e);if(l$1.length>0)return l$1;let i=t.getComments();if(i.length===0)return [];let r=new Map,g=[];for(let o of i)if(o.parentId){let c=r.get(o.parentId);c?c.push(o):r.set(o.parentId,[o]);}else g.push(o);let u=[];for(let o of g){if(e?.author&&o.author!==e.author||e?.done!==void 0&&(o.done??false)!==e.done)continue;let c=r.get(o.id)??[];u.push({id:o.id,author:o.author,date:o.date??null,text:x(o.content),anchoredText:"",paragraphIndex:-1,replies:c.map(p=>({id:p.id,author:p.author,date:p.date??null,text:x(p.content)})),done:o.done??false});}return u},getChanges(e){let n=m(t);return n?k(n,e):[]},findText(e,n){return t.findInDocument(e,n)},getSelection(){return t.getSelectionInfo()},addComment(e){return t.addComment({paraId:e.paraId,text:e.text,author:s(e.author),search:e.search})},replyTo(e,n){return t.replyToComment(e,n.text,s(n.author))},resolveComment(e){t.resolveComment(e);},proposeChange(e){return t.proposeChange({paraId:e.paraId,search:e.search,replaceWith:e.replaceWith,author:s(e.author)})},applyFormatting(e){return t.applyFormatting({paraId:e.paraId,search:e.search,marks:e.marks})},setParagraphStyle(e){return t.setParagraphStyle({paraId:e.paraId,styleId:e.styleId})},getPage(e){return t.getPageContent(e)},getPages(e){let n=t.getTotalPages(),l=Math.max(1,Math.min(e.from,n)),i=Math.max(l,Math.min(e.to,n)),r=[];for(let g=l;g<=i;g++){let u=t.getPageContent(g);u&&r.push(u);}return r},getTotalPages(){return t.getTotalPages()},getCurrentPage(){return t.getCurrentPage()},scrollTo(e){return t.scrollToParaId(e)},onContentChange(e){return t.onContentChange(()=>{let n=m(t),l$1=n?l(n):[],i=n?k(n):[];try{e({commentCount:l$1.length,changeCount:i.length,comments:l$1,changes:i});}catch(r){console.error("onContentChange listener threw:",r);}})},onSelectionChange(e){return t.onSelectionChange(()=>{try{e(t.getSelectionInfo());}catch(n){console.error("onSelectionChange listener threw:",n);}})}}}export{T as a,I as b};
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkALS6DG4A_js=require('./chunk-ALS6DG4A.js'),chunkDOKVZKIP_js=require('./chunk-DOKVZKIP.js'),chunkGZG3RJXW_js=require('./chunk-GZG3RJXW.js');Object.defineProperty(exports,"DocxReviewer",{enumerable:true,get:function(){return chunkALS6DG4A_js.a}});Object.defineProperty(exports,"ChangeNotFoundError",{enumerable:true,get:function(){return chunkDOKVZKIP_js.g}});Object.defineProperty(exports,"CommentNotFoundError",{enumerable:true,get:function(){return chunkDOKVZKIP_js.h}});Object.defineProperty(exports,"TextNotFoundError",{enumerable:true,get:function(){return chunkDOKVZKIP_js.f}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunkDOKVZKIP_js.m}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkGZG3RJXW_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkGZG3RJXW_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkGZG3RJXW_js.d}});
1
+ 'use strict';var chunkU7PAJJYD_js=require('./chunk-U7PAJJYD.js'),chunk3HEONW4M_js=require('./chunk-3HEONW4M.js'),chunkT5P2DWHN_js=require('./chunk-T5P2DWHN.js');Object.defineProperty(exports,"DocxReviewer",{enumerable:true,get:function(){return chunkU7PAJJYD_js.a}});Object.defineProperty(exports,"ChangeNotFoundError",{enumerable:true,get:function(){return chunk3HEONW4M_js.g}});Object.defineProperty(exports,"CommentNotFoundError",{enumerable:true,get:function(){return chunk3HEONW4M_js.h}});Object.defineProperty(exports,"TextNotFoundError",{enumerable:true,get:function(){return chunk3HEONW4M_js.f}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunk3HEONW4M_js.m}});Object.defineProperty(exports,"agentTools",{enumerable:true,get:function(){return chunkT5P2DWHN_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkT5P2DWHN_js.b}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkT5P2DWHN_js.d}});
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- export{a as DocxReviewer}from'./chunk-CWKXKM35.mjs';export{g as ChangeNotFoundError,h as CommentNotFoundError,f as TextNotFoundError,m as createReviewerBridge}from'./chunk-4OJA3FMM.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-S2PFUY23.mjs';
1
+ export{a as DocxReviewer}from'./chunk-HTCA4A6G.mjs';export{g as ChangeNotFoundError,h as CommentNotFoundError,f as TextNotFoundError,m as createReviewerBridge}from'./chunk-AMRM73UC.mjs';export{a as agentTools,b as executeToolCall,d as getToolSchemas}from'./chunk-TICYYVCD.mjs';
package/dist/mcp.js CHANGED
@@ -1,4 +1,4 @@
1
- 'use strict';var chunkGZG3RJXW_js=require('./chunk-GZG3RJXW.js'),string_decoder=require('string_decoder');var i={ParseError:-32700,InvalidRequest:-32600,MethodNotFound:-32601,InvalidParams:-32602,InternalError:-32603};function v(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&"id"in t}function I(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&!("id"in t)}function u(t,r){return {jsonrpc:"2.0",id:t,result:r}}function p(t,r,e,o){return {jsonrpc:"2.0",id:t,error:o===void 0?{code:r,message:e}:{code:r,message:e,data:o}}}function y(t){let r=[],e=[],o=t.split(`
1
+ 'use strict';var chunkT5P2DWHN_js=require('./chunk-T5P2DWHN.js'),string_decoder=require('string_decoder');var i={ParseError:-32700,InvalidRequest:-32600,MethodNotFound:-32601,InvalidParams:-32602,InternalError:-32603};function v(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&"id"in t}function I(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&!("id"in t)}function u(t,r){return {jsonrpc:"2.0",id:t,result:r}}function p(t,r,e,o){return {jsonrpc:"2.0",id:t,error:o===void 0?{code:r,message:e}:{code:r,message:e,data:o}}}function y(t){let r=[],e=[],o=t.split(`
2
2
  `),n=o.pop()??"";for(let c of o){let a=c.trim();if(a)try{r.push(JSON.parse(a));}catch{e.push(a);}}return {messages:r,parseErrors:e,rest:n}}function d(t){return JSON.stringify(t)+`
3
- `}var T="2025-06-18",f=class{constructor(r,e={}){this.bridge=r,this.opts={name:e.name??"@eigenpal/docx-editor-agents",version:e.version??"0.0.0",protocolVersion:e.protocolVersion??T};}handle(r){if(!v(r))return null;let e=r;try{switch(e.method){case "initialize":return u(e.id,this.handleInitialize());case "tools/list":return u(e.id,this.handleToolsList());case "tools/call":return this.handleToolsCall(e);case "ping":return u(e.id,{});default:return p(e.id,i.MethodNotFound,`Method not found: ${e.method}`)}}catch(o){return p(e.id,i.InternalError,o instanceof Error?o.message:String(o))}}handleInitialize(){return {protocolVersion:this.opts.protocolVersion,capabilities:{tools:{}},serverInfo:{name:this.opts.name,version:this.opts.version}}}handleToolsList(){return {tools:chunkGZG3RJXW_js.a.map(r=>({name:r.name,description:r.description,inputSchema:r.inputSchema}))}}handleToolsCall(r){let e=r.params;if(!e||typeof e.name!="string")return p(r.id,i.InvalidParams,'tools/call requires a "name" string');let o=e.arguments??{},n=chunkGZG3RJXW_js.b(e.name,o,this.bridge),c=n.success?{content:[{type:"text",text:typeof n.data=="string"?n.data:JSON.stringify(n.data,null,2)}]}:{isError:true,content:[{type:"text",text:n.error??"Unknown tool error"}]};return u(r.id,c)}};var x=1024*1024;function b(t,r={}){let e=new f(t,r),o=r.input??(typeof process<"u"&&process.stdin?process.stdin:null),n=r.output??(typeof process<"u"&&process.stdout?process.stdout:null),c=r.log??(s=>{typeof process<"u"&&process.stderr&&process.stderr.write(s+`
3
+ `}var T="2025-06-18",f=class{constructor(r,e={}){this.bridge=r,this.opts={name:e.name??"@eigenpal/docx-editor-agents",version:e.version??"0.0.0",protocolVersion:e.protocolVersion??T};}handle(r){if(!v(r))return null;let e=r;try{switch(e.method){case "initialize":return u(e.id,this.handleInitialize());case "tools/list":return u(e.id,this.handleToolsList());case "tools/call":return this.handleToolsCall(e);case "ping":return u(e.id,{});default:return p(e.id,i.MethodNotFound,`Method not found: ${e.method}`)}}catch(o){return p(e.id,i.InternalError,o instanceof Error?o.message:String(o))}}handleInitialize(){return {protocolVersion:this.opts.protocolVersion,capabilities:{tools:{}},serverInfo:{name:this.opts.name,version:this.opts.version}}}handleToolsList(){return {tools:chunkT5P2DWHN_js.a.map(r=>({name:r.name,description:r.description,inputSchema:r.inputSchema}))}}handleToolsCall(r){let e=r.params;if(!e||typeof e.name!="string")return p(r.id,i.InvalidParams,'tools/call requires a "name" string');let o=e.arguments??{},n=chunkT5P2DWHN_js.b(e.name,o,this.bridge),c=n.success?{content:[{type:"text",text:typeof n.data=="string"?n.data:JSON.stringify(n.data,null,2)}]}:{isError:true,content:[{type:"text",text:n.error??"Unknown tool error"}]};return u(r.id,c)}};var x=1024*1024;function b(t,r={}){let e=new f(t,r),o=r.input??(typeof process<"u"&&process.stdin?process.stdin:null),n=r.output??(typeof process<"u"&&process.stdout?process.stdout:null),c=r.log??(s=>{typeof process<"u"&&process.stderr&&process.stderr.write(s+`
4
4
  `);});if(!o||!n)throw new Error("runStdioServer: no input/output stream available. Pass options.input and options.output, or run inside a Node process with stdin/stdout.");let a=n,h=new string_decoder.StringDecoder("utf8"),l="",R=false;function w(s){let g=e.handle(s);g!==null&&a.write(d(g));}function J(s){if(R)return;if(l+=typeof s=="string"?s:h.write(s),l.length>x){l="",c(`MCP buffer overflow (>${x} bytes without newline) \u2014 dropped`),a.write(d(p(null,i.ParseError,"Frame too large")));return}let{messages:g,parseErrors:E,rest:k}=y(l);l=k;for(let m of g)w(m);for(let m of E)c(`MCP parse error: ${m}`),a.write(d(p(null,i.ParseError,"Parse error",m)));}return o.on("data",J),o.on("end",()=>{R=true;}),o.on("error",s=>{c(`MCP input error: ${s.message}`),R=true;}),{server:e,feed:J,close(){R=true;}}}exports.ErrorCode=i;exports.McpServer=f;exports.encodeFrame=d;exports.isJsonRpcNotification=I;exports.isJsonRpcRequest=v;exports.makeError=p;exports.makeSuccess=u;exports.parseFrames=y;exports.runStdioServer=b;
package/dist/mcp.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import {a,b as b$1}from'./chunk-S2PFUY23.mjs';import {StringDecoder}from'string_decoder';var i={ParseError:-32700,InvalidRequest:-32600,MethodNotFound:-32601,InvalidParams:-32602,InternalError:-32603};function v(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&"id"in t}function I(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&!("id"in t)}function u(t,r){return {jsonrpc:"2.0",id:t,result:r}}function p(t,r,e,o){return {jsonrpc:"2.0",id:t,error:o===void 0?{code:r,message:e}:{code:r,message:e,data:o}}}function y(t){let r=[],e=[],o=t.split(`
1
+ import {a,b as b$1}from'./chunk-TICYYVCD.mjs';import {StringDecoder}from'string_decoder';var i={ParseError:-32700,InvalidRequest:-32600,MethodNotFound:-32601,InvalidParams:-32602,InternalError:-32603};function v(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&"id"in t}function I(t){return typeof t=="object"&&t!==null&&t.jsonrpc==="2.0"&&typeof t.method=="string"&&!("id"in t)}function u(t,r){return {jsonrpc:"2.0",id:t,result:r}}function p(t,r,e,o){return {jsonrpc:"2.0",id:t,error:o===void 0?{code:r,message:e}:{code:r,message:e,data:o}}}function y(t){let r=[],e=[],o=t.split(`
2
2
  `),n=o.pop()??"";for(let c of o){let a=c.trim();if(a)try{r.push(JSON.parse(a));}catch{e.push(a);}}return {messages:r,parseErrors:e,rest:n}}function d(t){return JSON.stringify(t)+`
3
3
  `}var T="2025-06-18",f=class{constructor(r,e={}){this.bridge=r,this.opts={name:e.name??"@eigenpal/docx-editor-agents",version:e.version??"0.0.0",protocolVersion:e.protocolVersion??T};}handle(r){if(!v(r))return null;let e=r;try{switch(e.method){case "initialize":return u(e.id,this.handleInitialize());case "tools/list":return u(e.id,this.handleToolsList());case "tools/call":return this.handleToolsCall(e);case "ping":return u(e.id,{});default:return p(e.id,i.MethodNotFound,`Method not found: ${e.method}`)}}catch(o){return p(e.id,i.InternalError,o instanceof Error?o.message:String(o))}}handleInitialize(){return {protocolVersion:this.opts.protocolVersion,capabilities:{tools:{}},serverInfo:{name:this.opts.name,version:this.opts.version}}}handleToolsList(){return {tools:a.map(r=>({name:r.name,description:r.description,inputSchema:r.inputSchema}))}}handleToolsCall(r){let e=r.params;if(!e||typeof e.name!="string")return p(r.id,i.InvalidParams,'tools/call requires a "name" string');let o=e.arguments??{},n=b$1(e.name,o,this.bridge),c=n.success?{content:[{type:"text",text:typeof n.data=="string"?n.data:JSON.stringify(n.data,null,2)}]}:{isError:true,content:[{type:"text",text:n.error??"Unknown tool error"}]};return u(r.id,c)}};var x=1024*1024;function b(t,r={}){let e=new f(t,r),o=r.input??(typeof process<"u"&&process.stdin?process.stdin:null),n=r.output??(typeof process<"u"&&process.stdout?process.stdout:null),c=r.log??(s=>{typeof process<"u"&&process.stderr&&process.stderr.write(s+`
4
4
  `);});if(!o||!n)throw new Error("runStdioServer: no input/output stream available. Pass options.input and options.output, or run inside a Node process with stdin/stdout.");let a=n,h=new StringDecoder("utf8"),l="",R=false;function w(s){let g=e.handle(s);g!==null&&a.write(d(g));}function J(s){if(R)return;if(l+=typeof s=="string"?s:h.write(s),l.length>x){l="",c(`MCP buffer overflow (>${x} bytes without newline) \u2014 dropped`),a.write(d(p(null,i.ParseError,"Frame too large")));return}let{messages:g,parseErrors:E,rest:k}=y(l);l=k;for(let m of g)w(m);for(let m of E)c(`MCP parse error: ${m}`),a.write(d(p(null,i.ParseError,"Parse error",m)));}return o.on("data",J),o.on("end",()=>{R=true;}),o.on("error",s=>{c(`MCP input error: ${s.message}`),R=true;}),{server:e,feed:J,close(){R=true;}}}export{i as ErrorCode,f as McpServer,d as encodeFrame,I as isJsonRpcNotification,v as isJsonRpcRequest,p as makeError,u as makeSuccess,y as parseFrames,b as runStdioServer};
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunk2MJYWSD3_js=require('./chunk-2MJYWSD3.js'),chunkGZG3RJXW_js=require('./chunk-GZG3RJXW.js'),react=require('react');function S(T){let{editorRef:i,author:l="AI",tools:n,include:r,exclude:s}=T,m=!!n&&Object.keys(n).length>0,c=react.useCallback(t=>!(r&&!r.includes(t)||s&&s.includes(t)),[r,s]),A=react.useMemo(()=>{let t=r||s?chunkGZG3RJXW_js.a.filter(e=>c(e.name)):chunkGZG3RJXW_js.a;if(!m)return t.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}));let o=new Map(t.map(e=>[e.name,e]));for(let[e,a]of Object.entries(n))o.set(e,a);return Array.from(o.values()).map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))},[n,m,r,s,c]),y=react.useCallback((t,o)=>{let e=i.current;if(!e)return {success:false,error:"Editor not ready."};let a=chunk2MJYWSD3_js.b(e,l),d=n?.[t];if(d)try{return d.handler(o,a)}catch(u){return {success:false,error:u instanceof Error?u.message:String(u)}}return c(t)?chunkGZG3RJXW_js.b(t,o,a):{success:false,error:`Tool '${t}' is not enabled.`}},[i,l,n,c]),h=react.useCallback(()=>{let t=i.current;if(!t)return {selection:null,currentPage:0,totalPages:0};let o=chunk2MJYWSD3_js.b(t,l);return {selection:o.getSelection(),currentPage:o.getCurrentPage(),totalPages:o.getTotalPages()}},[i,l]);return {tools:A,executeToolCall:y,getContext:h}}Object.defineProperty(exports,"useAgentChat",{enumerable:true,get:function(){return chunk2MJYWSD3_js.a}});Object.defineProperty(exports,"getToolDisplayName",{enumerable:true,get:function(){return chunkGZG3RJXW_js.c}});exports.useDocxAgentTools=S;
1
+ 'use strict';var chunkO7DEBIDX_js=require('./chunk-O7DEBIDX.js'),chunkT5P2DWHN_js=require('./chunk-T5P2DWHN.js'),react=require('react');function S(T){let{editorRef:i,author:l="AI",tools:n,include:r,exclude:s}=T,m=!!n&&Object.keys(n).length>0,c=react.useCallback(t=>!(r&&!r.includes(t)||s&&s.includes(t)),[r,s]),A=react.useMemo(()=>{let t=r||s?chunkT5P2DWHN_js.a.filter(e=>c(e.name)):chunkT5P2DWHN_js.a;if(!m)return t.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}));let o=new Map(t.map(e=>[e.name,e]));for(let[e,a]of Object.entries(n))o.set(e,a);return Array.from(o.values()).map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))},[n,m,r,s,c]),y=react.useCallback((t,o)=>{let e=i.current;if(!e)return {success:false,error:"Editor not ready."};let a=chunkO7DEBIDX_js.b(e,l),d=n?.[t];if(d)try{return d.handler(o,a)}catch(u){return {success:false,error:u instanceof Error?u.message:String(u)}}return c(t)?chunkT5P2DWHN_js.b(t,o,a):{success:false,error:`Tool '${t}' is not enabled.`}},[i,l,n,c]),h=react.useCallback(()=>{let t=i.current;if(!t)return {selection:null,currentPage:0,totalPages:0};let o=chunkO7DEBIDX_js.b(t,l);return {selection:o.getSelection(),currentPage:o.getCurrentPage(),totalPages:o.getTotalPages()}},[i,l]);return {tools:A,executeToolCall:y,getContext:h}}Object.defineProperty(exports,"useAgentChat",{enumerable:true,get:function(){return chunkO7DEBIDX_js.a}});Object.defineProperty(exports,"getToolDisplayName",{enumerable:true,get:function(){return chunkT5P2DWHN_js.c}});exports.useDocxAgentTools=S;
package/dist/react.mjs CHANGED
@@ -1 +1 @@
1
- import {b}from'./chunk-AITWKLUF.mjs';export{a as useAgentChat}from'./chunk-AITWKLUF.mjs';import {a,b as b$1}from'./chunk-S2PFUY23.mjs';export{c as getToolDisplayName}from'./chunk-S2PFUY23.mjs';import {useCallback,useMemo}from'react';function S(T){let{editorRef:i,author:l="AI",tools:n,include:r,exclude:s}=T,m=!!n&&Object.keys(n).length>0,c=useCallback(t=>!(r&&!r.includes(t)||s&&s.includes(t)),[r,s]),A=useMemo(()=>{let t=r||s?a.filter(e=>c(e.name)):a;if(!m)return t.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}));let o=new Map(t.map(e=>[e.name,e]));for(let[e,a]of Object.entries(n))o.set(e,a);return Array.from(o.values()).map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))},[n,m,r,s,c]),y=useCallback((t,o)=>{let e=i.current;if(!e)return {success:false,error:"Editor not ready."};let a=b(e,l),d=n?.[t];if(d)try{return d.handler(o,a)}catch(u){return {success:false,error:u instanceof Error?u.message:String(u)}}return c(t)?b$1(t,o,a):{success:false,error:`Tool '${t}' is not enabled.`}},[i,l,n,c]),h=useCallback(()=>{let t=i.current;if(!t)return {selection:null,currentPage:0,totalPages:0};let o=b(t,l);return {selection:o.getSelection(),currentPage:o.getCurrentPage(),totalPages:o.getTotalPages()}},[i,l]);return {tools:A,executeToolCall:y,getContext:h}}export{S as useDocxAgentTools};
1
+ import {b}from'./chunk-WGUYD2A2.mjs';export{a as useAgentChat}from'./chunk-WGUYD2A2.mjs';import {a,b as b$1}from'./chunk-TICYYVCD.mjs';export{c as getToolDisplayName}from'./chunk-TICYYVCD.mjs';import {useCallback,useMemo}from'react';function S(T){let{editorRef:i,author:l="AI",tools:n,include:r,exclude:s}=T,m=!!n&&Object.keys(n).length>0,c=useCallback(t=>!(r&&!r.includes(t)||s&&s.includes(t)),[r,s]),A=useMemo(()=>{let t=r||s?a.filter(e=>c(e.name)):a;if(!m)return t.map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}));let o=new Map(t.map(e=>[e.name,e]));for(let[e,a]of Object.entries(n))o.set(e,a);return Array.from(o.values()).map(e=>({type:"function",function:{name:e.name,description:e.description,parameters:e.inputSchema}}))},[n,m,r,s,c]),y=useCallback((t,o)=>{let e=i.current;if(!e)return {success:false,error:"Editor not ready."};let a=b(e,l),d=n?.[t];if(d)try{return d.handler(o,a)}catch(u){return {success:false,error:u instanceof Error?u.message:String(u)}}return c(t)?b$1(t,o,a):{success:false,error:`Tool '${t}' is not enabled.`}},[i,l,n,c]),h=useCallback(()=>{let t=i.current;if(!t)return {selection:null,currentPage:0,totalPages:0};let o=b(t,l);return {selection:o.getSelection(),currentPage:o.getCurrentPage(),totalPages:o.getTotalPages()}},[i,l]);return {tools:A,executeToolCall:y,getContext:h}}export{S as useDocxAgentTools};
package/dist/server.js CHANGED
@@ -1 +1 @@
1
- 'use strict';var chunkALS6DG4A_js=require('./chunk-ALS6DG4A.js'),chunkDOKVZKIP_js=require('./chunk-DOKVZKIP.js'),chunkGZG3RJXW_js=require('./chunk-GZG3RJXW.js');Object.defineProperty(exports,"DocxReviewer",{enumerable:true,get:function(){return chunkALS6DG4A_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunkDOKVZKIP_js.m}});Object.defineProperty(exports,"docxAgentTools",{enumerable:true,get:function(){return chunkGZG3RJXW_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkGZG3RJXW_js.b}});Object.defineProperty(exports,"getToolDisplayName",{enumerable:true,get:function(){return chunkGZG3RJXW_js.c}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkGZG3RJXW_js.d}});
1
+ 'use strict';var chunkU7PAJJYD_js=require('./chunk-U7PAJJYD.js'),chunk3HEONW4M_js=require('./chunk-3HEONW4M.js'),chunkT5P2DWHN_js=require('./chunk-T5P2DWHN.js');Object.defineProperty(exports,"DocxReviewer",{enumerable:true,get:function(){return chunkU7PAJJYD_js.a}});Object.defineProperty(exports,"createReviewerBridge",{enumerable:true,get:function(){return chunk3HEONW4M_js.m}});Object.defineProperty(exports,"docxAgentTools",{enumerable:true,get:function(){return chunkT5P2DWHN_js.a}});Object.defineProperty(exports,"executeToolCall",{enumerable:true,get:function(){return chunkT5P2DWHN_js.b}});Object.defineProperty(exports,"getToolDisplayName",{enumerable:true,get:function(){return chunkT5P2DWHN_js.c}});Object.defineProperty(exports,"getToolSchemas",{enumerable:true,get:function(){return chunkT5P2DWHN_js.d}});
package/dist/server.mjs CHANGED
@@ -1 +1 @@
1
- export{a as DocxReviewer}from'./chunk-CWKXKM35.mjs';export{m as createReviewerBridge}from'./chunk-4OJA3FMM.mjs';export{a as docxAgentTools,b as executeToolCall,c as getToolDisplayName,d as getToolSchemas}from'./chunk-S2PFUY23.mjs';
1
+ export{a as DocxReviewer}from'./chunk-HTCA4A6G.mjs';export{m as createReviewerBridge}from'./chunk-AMRM73UC.mjs';export{a as docxAgentTools,b as executeToolCall,c as getToolDisplayName,d as getToolSchemas}from'./chunk-TICYYVCD.mjs';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@eigenpal/docx-editor-agents",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Agent-friendly API for DOCX document review — read, comment, propose changes, accept/reject tracked changes",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -1,5 +0,0 @@
1
- import {ba,ca,Q,R as R$1}from'./chunk-25L7AEDN.mjs';function h(r){return r.type==="insertion"||r.type==="deletion"||r.type==="moveFrom"||r.type==="moveTo"}function x(r){let n=[];for(let o of r)o.type==="run"?n.push(Q(o)):o.type==="hyperlink"&&n.push(R$1(o));return n.join("")}function K(r,n){let o=0;for(let t of r.content)if(t.type==="paragraph"){if(o===n)return t;o++;}else if(t.type==="table"){for(let i of t.rows)for(let e of i.cells)for(let s of e.content)if(s.type==="paragraph"){if(o===n)return s;o++;}}else o++;throw new Error(`Paragraph index ${n} out of bounds (max: ${o-1})`)}function R(r,n){let o=0;for(let t of r.content)if(t.type==="paragraph"){if(n(t,o)===false)return;o++;}else if(t.type==="table"){for(let i of t.rows)for(let e of i.cells)for(let s of e.content)if(s.type==="paragraph"){if(n(s,o)===false)return;o++;}}else o++;}function V(r,n={}){let{fromIndex:o,toIndex:t,includeTrackedChanges:i=true,includeCommentAnchors:e=true}=n,s=[],a=0;for(let c of r.content)if(c.type==="paragraph")v(a,o,t)&&s.push(L(c,a,i,e)),a++;else if(c.type==="table"){v(a,o,t)&&s.push(H(c,a,i,e));for(let l of c.rows)for(let u of l.cells)for(let p of u.content)p.type==="paragraph"&&a++;}else a++;return s}function v(r,n,o){return (n===void 0||r>=n)&&(o===void 0||r<=o)}function L(r,n,o,t){let i=B(r,o,t),e=r.formatting?.styleId,s=r.paraId;return ba(e)?{type:"heading",index:n,paraId:s,level:ca(e)??1,text:i}:r.listRendering?{type:"list-item",index:n,paraId:s,text:i,listLevel:r.listRendering.level??0,listType:r.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:n,paraId:s,text:i}}function H(r,n,o,t){let i=[],e=[];for(let s of r.rows){let a=[],c=[];for(let l of s.cells){let u=[],p;for(let g of l.content)g.type==="paragraph"&&(p===void 0&&(p=g.paraId),u.push(B(g,o,t)));a.push(u.join(`
2
- `)),c.push(p);}i.push(a),e.push(c);}return {type:"table",index:n,rows:i,cellParaIds:e}}function Y(r){let n=[],o=t=>t.paraId?t.paraId:String(t.index);for(let t of r)switch(t.type){case "heading":n.push(`[${o(t)}] (h${t.level}) ${t.text}`);break;case "paragraph":n.push(`[${o(t)}] ${t.text}`);break;case "list-item":{let i=" ".repeat(t.listLevel),e=t.listType==="bullet"?"\u2022":"-";n.push(`[${o(t)}] ${i}${e} ${t.text}`);break}case "table":{let i=t.index;for(let e=0;e<t.rows.length;e++)for(let s=0;s<t.rows[e].length;s++){let c=t.rows[e][s].split(`
3
- `),l=t.cellParaIds?.[e]?.[s];for(let u=0;u<c.length;u++){let p=u===0&&l?l:String(i);n.push(`[${p}] (table, row ${e+1}, col ${s+1}) ${c[u]}`),i++;}}break}}return n.join(`
4
- `)}function B(r,n,o){let t=[],i=new Set;for(let e of r.content){if(e.type==="commentRangeStart"&&o){i.add(e.id),t.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&o){i.has(e.id)&&(i.delete(e.id),t.push("[/comment]"));continue}if(e.type==="run")t.push(Q(e));else if(e.type==="hyperlink")t.push(R$1(e));else if(h(e)){let s=x(e.content);e.type==="insertion"||e.type==="moveTo"?n?t.push(`[+${s}+]{by:${e.info.author}}`):t.push(s):n&&t.push(`[-${s}-]{by:${e.info.author}}`);}}return t.join("")}var y=class extends Error{constructor(n,o){let t=o!==void 0?` in paragraph ${o}`:" in document";super(`Text not found${t}: "${n}"`),this.name="TextNotFoundError";}},M=class extends Error{constructor(n){super(`Tracked change not found: id=${n}`),this.name="ChangeNotFoundError";}},F=class extends Error{constructor(n){super(`Comment not found: id=${n}`),this.name="CommentNotFoundError";}};function E(r){let n=[],o=0;for(let t=0;t<r.content.length;t++){let i=r.content[t];if(i.type==="run"){let e=Q(i);n.push({contentIndex:t,run:i,text:e,startPos:o}),o+=e.length;}else if(i.type==="hyperlink")for(let e=0;e<i.children.length;e++){let s=i.children[e];if(s.type==="run"){let a=Q(s);n.push({contentIndex:t,run:s,text:a,startPos:o}),o+=a.length;}}else if(h(i))for(let e=0;e<i.content.length;e++){let s=i.content[e];if(s.type==="run"){let a=Q(s);n.push({contentIndex:t,run:s,text:a,startPos:o}),o+=a.length;}else if(s.type==="hyperlink"){for(let a of s.children)if(a.type==="run"){let c=Q(a);n.push({contentIndex:t,run:a,text:c,startPos:o}),o+=c.length;}}}}return n}function P(r){return E(r).map(n=>n.text).join("")}function G(r,n,o){let t=E(r),i=t.map(u=>u.text).join(""),e=W(i,n);if(!e)throw new y(n,o);let s=-1,a=0;for(let u=0;u<t.length;u++)if(e.start<t[u].startPos+t[u].text.length){s=u,a=e.start-t[u].startPos;break}let c=-1,l=0;for(let u=t.length-1;u>=0;u--)if(e.end>t[u].startPos){c=u,l=e.end-t[u].startPos;break}if(s===-1||c===-1)throw new y(n,o);return {startRunIndex:t[s].contentIndex,startOffset:a,endRunIndex:t[c].contentIndex,endOffset:l}}function te(r,n,o){let t=G(r,n,o),{startRunIndex:i,endRunIndex:e}=t,{startOffset:s,endOffset:a}=t,c=r.content[e];if(c.type==="run"){let u=Q(c);if(a<u.length){let p=D(u.slice(a),c);$(c,u.slice(0,a)),r.content.splice(e+1,0,p);}}let l=r.content[i];if(l.type==="run"&&s>0){let u=Q(l),p=D(u.slice(0,s),l);$(l,u.slice(s)),r.content.splice(i,0,p),i++,e++;}return {startIndex:i,endIndex:e}}function D(r,n){return {type:"run",content:[{type:"text",text:r}],formatting:n.formatting?{...n.formatting}:void 0}}function $(r,n){let o=r.content.find(t=>t.type==="text");o&&(o.text=n);}function O(r){let n=[],o=[],t=true;for(let i=0;i<r.length;i++){let e=r[i];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"){n.push(".",".","."),o.push(i,i,i),t=false;continue}if(/\s/.test(e)||e==="\xA0"){t||(n.push(" "),o.push(i),t=true);continue}n.push(e.toLowerCase()),o.push(i),t=false;}}return n.length>0&&n[n.length-1]===" "&&(n.pop(),o.pop()),{text:n.join(""),posMap:o}}function S(r,n,o,t){let i=r.posMap[n],e=r.posMap[n+o-1]+1;for(;e<t.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(t[e]);)e++;return {start:i,end:e}}function W(r,n){if(!n||!r)return null;let o=r.indexOf(n);if(o!==-1)return {start:o,end:o+n.length};let t=O(r),i=O(n);if(!i.text)return null;let e=t.text.indexOf(i.text);if(e!==-1)return S(t,e,i.text.length,r);let s=i.text.split(" ");if(s.length>=3)for(let a=1;a<=Math.min(2,s.length-2);a++){let c=s.slice(0,-a).join(" "),l=t.text.indexOf(c);if(l!==-1)return S(t,l,c.length,r)}return null}function se(r,n){let o=new Map;return R(r,(i,e)=>{let s=null;for(let a of i.content)if(h(a)){s===null&&(s=P(i));let c=x(a.content),l=a.info.id,u=o.get(l);u&&u.paragraphIndex===e?u.text+=c:o.set(l,{id:l,type:a.type,author:a.info.author,date:a.info.date??null,text:c,context:s,paragraphIndex:e});}}),Array.from(o.values()).filter(i=>!(n?.author&&i.author!==n.author||n?.type&&i.type!==n.type))}function ae(r,n){let o=r.comments??[];if(o.length===0)return [];let t=z(r),i=[],e=new Map;for(let a of o)if(a.parentId!==void 0){let c=e.get(a.parentId)??[];c.push(a),e.set(a.parentId,c);}else i.push(a);return i.map(a=>{let c=t.get(a.id),l=(e.get(a.id)??[]).map(u=>({id:u.id,author:u.author,date:u.date??null,text:A(u)}));return {id:a.id,author:a.author,date:a.date??null,text:A(a),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:l,done:a.done??false}}).filter(a=>!(n?.author&&a.author!==n.author||n?.done!==void 0&&a.done!==n.done))}function A(r){return r.content.map(n=>P(n)).join(`
5
- `)}function z(r){let n=new Map,o=new Map;return R(r,(t,i)=>{for(let e of t.content)if(e.type==="commentRangeStart")o.set(e.id,{paragraphIndex:i,parts:[]});else if(e.type==="commentRangeEnd"){let s=o.get(e.id);s&&(n.set(e.id,{text:s.parts.join(""),paragraphIndex:s.paragraphIndex}),o.delete(e.id));}else if(e.type==="run"){let s=Q(e);for(let a of o.values())a.parts.push(s);}else if(e.type==="hyperlink"){let s=e.children.filter(a=>a.type==="run").map(Q).join("");for(let a of o.values())a.parts.push(s);}else if(h(e)){let s=x(e.content);for(let a of o.values())a.parts.push(s);}}),n}function N(r){let n=r.toDocument().package?.document;if(!n)return new Map;let o=new Map,t=0;for(let i of n.content)if(i.type==="paragraph"){let e=i.paraId;e&&o.set(e,t),t++;}else if(i.type==="table")for(let e of i.rows)for(let s of e.cells)for(let a of s.content)a.type==="paragraph"&&t++;else t++;return o}function X(r){let n=[];for(let o of r.content)if(o.type==="run")for(let t of o.content)t.type==="text"&&n.push(t.text??"");return n.join("")}function ce(r){let n=new Set,o=null;function t(){return o===null&&(o=N(r)),o}function i(){if(n.size===0)return;let e=r.getComments(),s=r.getChanges(),a={commentCount:e.length,changeCount:s.length,comments:e,changes:s};for(let c of n)try{c(a);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return r.getContentAsText(e)},getContent(e){return r.getContent(e)},getComments(e){return r.getComments(e)},getChanges(e){return r.getChanges(e)},findText(e,s){if(!e)return [];let a=s?.caseSensitive??false,c=s?.limit??20,l=a?e:e.toLowerCase(),u=r.toDocument().package?.document;if(!u)return [];let p=[],g=40;for(let k of u.content){if(p.length>=c)break;if(k.type!=="paragraph")continue;let C=k;if(!C.paraId)continue;let m=X(C),w=a?m:m.toLowerCase(),d=w.indexOf(l);if(d===-1||w.indexOf(l,d+1)!==-1)continue;let j=m.slice(d,d+e.length);p.push({paraId:C.paraId,match:j,before:m.slice(Math.max(0,d-g),d),after:m.slice(d+e.length,d+e.length+g)});}return p},getSelection(){return null},addComment(e){let s=t().get(e.paraId);if(s===void 0)return null;try{let a=r.addComment({paragraphIndex:s,text:e.text,author:e.author,search:e.search});return i(),a}catch{return null}},replyTo(e,s){try{let a=r.replyTo(e,s);return i(),a}catch{return null}},resolveComment(e){let a=r.toDocument().package?.document?.comments?.find(c=>c.id===e);a&&(a.done=true,i());},proposeChange(e){let s=t().get(e.paraId);if(s===void 0)return false;let a=e.search==="",c=e.replaceWith==="";if(a&&c)return false;try{return a?r.proposeInsertion({paragraphIndex:s,insertText:e.replaceWith,author:e.author}):c?r.proposeDeletion({paragraphIndex:s,search:e.search,author:e.author}):r.replace({paragraphIndex:s,search:e.search,replaceWith:e.replaceWith,author:e.author}),i(),true}catch{return false}},scrollTo(e){return t().has(e)},applyFormatting(){return false},setParagraphStyle(){return false},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return n.add(e),()=>{n.delete(e);}},onSelectionChange(){return ()=>{}}}}export{h as a,K as b,R as c,V as d,Y as e,y as f,M as g,F as h,G as i,te as j,se as k,ae as l,ce as m};
@@ -1,5 +0,0 @@
1
- 'use strict';var chunkVF25WARH_js=require('./chunk-VF25WARH.js');function h(r){return r.type==="insertion"||r.type==="deletion"||r.type==="moveFrom"||r.type==="moveTo"}function x(r){let n=[];for(let o of r)o.type==="run"?n.push(chunkVF25WARH_js.Q(o)):o.type==="hyperlink"&&n.push(chunkVF25WARH_js.R(o));return n.join("")}function K(r,n){let o=0;for(let t of r.content)if(t.type==="paragraph"){if(o===n)return t;o++;}else if(t.type==="table"){for(let i of t.rows)for(let e of i.cells)for(let s of e.content)if(s.type==="paragraph"){if(o===n)return s;o++;}}else o++;throw new Error(`Paragraph index ${n} out of bounds (max: ${o-1})`)}function R(r,n){let o=0;for(let t of r.content)if(t.type==="paragraph"){if(n(t,o)===false)return;o++;}else if(t.type==="table"){for(let i of t.rows)for(let e of i.cells)for(let s of e.content)if(s.type==="paragraph"){if(n(s,o)===false)return;o++;}}else o++;}function V(r,n={}){let{fromIndex:o,toIndex:t,includeTrackedChanges:i=true,includeCommentAnchors:e=true}=n,s=[],a=0;for(let c of r.content)if(c.type==="paragraph")v(a,o,t)&&s.push(L(c,a,i,e)),a++;else if(c.type==="table"){v(a,o,t)&&s.push(H(c,a,i,e));for(let l of c.rows)for(let u of l.cells)for(let p of u.content)p.type==="paragraph"&&a++;}else a++;return s}function v(r,n,o){return (n===void 0||r>=n)&&(o===void 0||r<=o)}function L(r,n,o,t){let i=B(r,o,t),e=r.formatting?.styleId,s=r.paraId;return chunkVF25WARH_js.ba(e)?{type:"heading",index:n,paraId:s,level:chunkVF25WARH_js.ca(e)??1,text:i}:r.listRendering?{type:"list-item",index:n,paraId:s,text:i,listLevel:r.listRendering.level??0,listType:r.listRendering.isBullet?"bullet":"number"}:{type:"paragraph",index:n,paraId:s,text:i}}function H(r,n,o,t){let i=[],e=[];for(let s of r.rows){let a=[],c=[];for(let l of s.cells){let u=[],p;for(let g of l.content)g.type==="paragraph"&&(p===void 0&&(p=g.paraId),u.push(B(g,o,t)));a.push(u.join(`
2
- `)),c.push(p);}i.push(a),e.push(c);}return {type:"table",index:n,rows:i,cellParaIds:e}}function Y(r){let n=[],o=t=>t.paraId?t.paraId:String(t.index);for(let t of r)switch(t.type){case "heading":n.push(`[${o(t)}] (h${t.level}) ${t.text}`);break;case "paragraph":n.push(`[${o(t)}] ${t.text}`);break;case "list-item":{let i=" ".repeat(t.listLevel),e=t.listType==="bullet"?"\u2022":"-";n.push(`[${o(t)}] ${i}${e} ${t.text}`);break}case "table":{let i=t.index;for(let e=0;e<t.rows.length;e++)for(let s=0;s<t.rows[e].length;s++){let c=t.rows[e][s].split(`
3
- `),l=t.cellParaIds?.[e]?.[s];for(let u=0;u<c.length;u++){let p=u===0&&l?l:String(i);n.push(`[${p}] (table, row ${e+1}, col ${s+1}) ${c[u]}`),i++;}}break}}return n.join(`
4
- `)}function B(r,n,o){let t=[],i=new Set;for(let e of r.content){if(e.type==="commentRangeStart"&&o){i.add(e.id),t.push(`[comment:${e.id}]`);continue}if(e.type==="commentRangeEnd"&&o){i.has(e.id)&&(i.delete(e.id),t.push("[/comment]"));continue}if(e.type==="run")t.push(chunkVF25WARH_js.Q(e));else if(e.type==="hyperlink")t.push(chunkVF25WARH_js.R(e));else if(h(e)){let s=x(e.content);e.type==="insertion"||e.type==="moveTo"?n?t.push(`[+${s}+]{by:${e.info.author}}`):t.push(s):n&&t.push(`[-${s}-]{by:${e.info.author}}`);}}return t.join("")}var y=class extends Error{constructor(n,o){let t=o!==void 0?` in paragraph ${o}`:" in document";super(`Text not found${t}: "${n}"`),this.name="TextNotFoundError";}},M=class extends Error{constructor(n){super(`Tracked change not found: id=${n}`),this.name="ChangeNotFoundError";}},F=class extends Error{constructor(n){super(`Comment not found: id=${n}`),this.name="CommentNotFoundError";}};function E(r){let n=[],o=0;for(let t=0;t<r.content.length;t++){let i=r.content[t];if(i.type==="run"){let e=chunkVF25WARH_js.Q(i);n.push({contentIndex:t,run:i,text:e,startPos:o}),o+=e.length;}else if(i.type==="hyperlink")for(let e=0;e<i.children.length;e++){let s=i.children[e];if(s.type==="run"){let a=chunkVF25WARH_js.Q(s);n.push({contentIndex:t,run:s,text:a,startPos:o}),o+=a.length;}}else if(h(i))for(let e=0;e<i.content.length;e++){let s=i.content[e];if(s.type==="run"){let a=chunkVF25WARH_js.Q(s);n.push({contentIndex:t,run:s,text:a,startPos:o}),o+=a.length;}else if(s.type==="hyperlink"){for(let a of s.children)if(a.type==="run"){let c=chunkVF25WARH_js.Q(a);n.push({contentIndex:t,run:a,text:c,startPos:o}),o+=c.length;}}}}return n}function P(r){return E(r).map(n=>n.text).join("")}function G(r,n,o){let t=E(r),i=t.map(u=>u.text).join(""),e=W(i,n);if(!e)throw new y(n,o);let s=-1,a=0;for(let u=0;u<t.length;u++)if(e.start<t[u].startPos+t[u].text.length){s=u,a=e.start-t[u].startPos;break}let c=-1,l=0;for(let u=t.length-1;u>=0;u--)if(e.end>t[u].startPos){c=u,l=e.end-t[u].startPos;break}if(s===-1||c===-1)throw new y(n,o);return {startRunIndex:t[s].contentIndex,startOffset:a,endRunIndex:t[c].contentIndex,endOffset:l}}function te(r,n,o){let t=G(r,n,o),{startRunIndex:i,endRunIndex:e}=t,{startOffset:s,endOffset:a}=t,c=r.content[e];if(c.type==="run"){let u=chunkVF25WARH_js.Q(c);if(a<u.length){let p=D(u.slice(a),c);$(c,u.slice(0,a)),r.content.splice(e+1,0,p);}}let l=r.content[i];if(l.type==="run"&&s>0){let u=chunkVF25WARH_js.Q(l),p=D(u.slice(0,s),l);$(l,u.slice(s)),r.content.splice(i,0,p),i++,e++;}return {startIndex:i,endIndex:e}}function D(r,n){return {type:"run",content:[{type:"text",text:r}],formatting:n.formatting?{...n.formatting}:void 0}}function $(r,n){let o=r.content.find(t=>t.type==="text");o&&(o.text=n);}function O(r){let n=[],o=[],t=true;for(let i=0;i<r.length;i++){let e=r[i];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"){n.push(".",".","."),o.push(i,i,i),t=false;continue}if(/\s/.test(e)||e==="\xA0"){t||(n.push(" "),o.push(i),t=true);continue}n.push(e.toLowerCase()),o.push(i),t=false;}}return n.length>0&&n[n.length-1]===" "&&(n.pop(),o.pop()),{text:n.join(""),posMap:o}}function S(r,n,o,t){let i=r.posMap[n],e=r.posMap[n+o-1]+1;for(;e<t.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(t[e]);)e++;return {start:i,end:e}}function W(r,n){if(!n||!r)return null;let o=r.indexOf(n);if(o!==-1)return {start:o,end:o+n.length};let t=O(r),i=O(n);if(!i.text)return null;let e=t.text.indexOf(i.text);if(e!==-1)return S(t,e,i.text.length,r);let s=i.text.split(" ");if(s.length>=3)for(let a=1;a<=Math.min(2,s.length-2);a++){let c=s.slice(0,-a).join(" "),l=t.text.indexOf(c);if(l!==-1)return S(t,l,c.length,r)}return null}function se(r,n){let o=new Map;return R(r,(i,e)=>{let s=null;for(let a of i.content)if(h(a)){s===null&&(s=P(i));let c=x(a.content),l=a.info.id,u=o.get(l);u&&u.paragraphIndex===e?u.text+=c:o.set(l,{id:l,type:a.type,author:a.info.author,date:a.info.date??null,text:c,context:s,paragraphIndex:e});}}),Array.from(o.values()).filter(i=>!(n?.author&&i.author!==n.author||n?.type&&i.type!==n.type))}function ae(r,n){let o=r.comments??[];if(o.length===0)return [];let t=z(r),i=[],e=new Map;for(let a of o)if(a.parentId!==void 0){let c=e.get(a.parentId)??[];c.push(a),e.set(a.parentId,c);}else i.push(a);return i.map(a=>{let c=t.get(a.id),l=(e.get(a.id)??[]).map(u=>({id:u.id,author:u.author,date:u.date??null,text:A(u)}));return {id:a.id,author:a.author,date:a.date??null,text:A(a),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:l,done:a.done??false}}).filter(a=>!(n?.author&&a.author!==n.author||n?.done!==void 0&&a.done!==n.done))}function A(r){return r.content.map(n=>P(n)).join(`
5
- `)}function z(r){let n=new Map,o=new Map;return R(r,(t,i)=>{for(let e of t.content)if(e.type==="commentRangeStart")o.set(e.id,{paragraphIndex:i,parts:[]});else if(e.type==="commentRangeEnd"){let s=o.get(e.id);s&&(n.set(e.id,{text:s.parts.join(""),paragraphIndex:s.paragraphIndex}),o.delete(e.id));}else if(e.type==="run"){let s=chunkVF25WARH_js.Q(e);for(let a of o.values())a.parts.push(s);}else if(e.type==="hyperlink"){let s=e.children.filter(a=>a.type==="run").map(chunkVF25WARH_js.Q).join("");for(let a of o.values())a.parts.push(s);}else if(h(e)){let s=x(e.content);for(let a of o.values())a.parts.push(s);}}),n}function N(r){let n=r.toDocument().package?.document;if(!n)return new Map;let o=new Map,t=0;for(let i of n.content)if(i.type==="paragraph"){let e=i.paraId;e&&o.set(e,t),t++;}else if(i.type==="table")for(let e of i.rows)for(let s of e.cells)for(let a of s.content)a.type==="paragraph"&&t++;else t++;return o}function X(r){let n=[];for(let o of r.content)if(o.type==="run")for(let t of o.content)t.type==="text"&&n.push(t.text??"");return n.join("")}function ce(r){let n=new Set,o=null;function t(){return o===null&&(o=N(r)),o}function i(){if(n.size===0)return;let e=r.getComments(),s=r.getChanges(),a={commentCount:e.length,changeCount:s.length,comments:e,changes:s};for(let c of n)try{c(a);}catch(l){console.error("reviewerBridge content listener threw:",l);}}return {getContentAsText(e){return r.getContentAsText(e)},getContent(e){return r.getContent(e)},getComments(e){return r.getComments(e)},getChanges(e){return r.getChanges(e)},findText(e,s){if(!e)return [];let a=s?.caseSensitive??false,c=s?.limit??20,l=a?e:e.toLowerCase(),u=r.toDocument().package?.document;if(!u)return [];let p=[],g=40;for(let k of u.content){if(p.length>=c)break;if(k.type!=="paragraph")continue;let C=k;if(!C.paraId)continue;let m=X(C),w=a?m:m.toLowerCase(),d=w.indexOf(l);if(d===-1||w.indexOf(l,d+1)!==-1)continue;let j=m.slice(d,d+e.length);p.push({paraId:C.paraId,match:j,before:m.slice(Math.max(0,d-g),d),after:m.slice(d+e.length,d+e.length+g)});}return p},getSelection(){return null},addComment(e){let s=t().get(e.paraId);if(s===void 0)return null;try{let a=r.addComment({paragraphIndex:s,text:e.text,author:e.author,search:e.search});return i(),a}catch{return null}},replyTo(e,s){try{let a=r.replyTo(e,s);return i(),a}catch{return null}},resolveComment(e){let a=r.toDocument().package?.document?.comments?.find(c=>c.id===e);a&&(a.done=true,i());},proposeChange(e){let s=t().get(e.paraId);if(s===void 0)return false;let a=e.search==="",c=e.replaceWith==="";if(a&&c)return false;try{return a?r.proposeInsertion({paragraphIndex:s,insertText:e.replaceWith,author:e.author}):c?r.proposeDeletion({paragraphIndex:s,search:e.search,author:e.author}):r.replace({paragraphIndex:s,search:e.search,replaceWith:e.replaceWith,author:e.author}),i(),true}catch{return false}},scrollTo(e){return t().has(e)},applyFormatting(){return false},setParagraphStyle(){return false},getPage(){return null},getPages(){return []},getTotalPages(){return 0},getCurrentPage(){return 0},onContentChange(e){return n.add(e),()=>{n.delete(e);}},onSelectionChange(){return ()=>{}}}}exports.a=h;exports.b=K;exports.c=R;exports.d=V;exports.e=Y;exports.f=y;exports.g=M;exports.h=F;exports.i=G;exports.j=te;exports.k=se;exports.l=ae;exports.m=ce;