@eigenpal/docx-editor-agents 0.1.1 → 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.
- package/README.md +69 -16
- package/dist/ai-sdk/react.d.mts +67 -0
- package/dist/ai-sdk/react.d.ts +67 -0
- package/dist/ai-sdk/react.js +1 -0
- package/dist/ai-sdk/react.mjs +1 -0
- package/dist/ai-sdk/server.d.mts +42 -0
- package/dist/ai-sdk/server.d.ts +42 -0
- package/dist/ai-sdk/server.js +1 -0
- package/dist/ai-sdk/server.mjs +1 -0
- package/dist/bridge.d.mts +1 -11
- package/dist/bridge.d.ts +1 -11
- package/dist/bridge.js +1 -1
- package/dist/bridge.mjs +1 -1
- package/dist/{chunk-W2QSJSB7.mjs → chunk-25L7AEDN.mjs} +11 -11
- package/dist/chunk-3HEONW4M.js +5 -0
- package/dist/chunk-AMRM73UC.mjs +5 -0
- package/dist/chunk-HTCA4A6G.mjs +1 -0
- package/dist/chunk-O7DEBIDX.js +2 -0
- package/dist/chunk-T5P2DWHN.js +8 -0
- package/dist/chunk-TICYYVCD.mjs +8 -0
- package/dist/chunk-U7PAJJYD.js +1 -0
- package/dist/{chunk-G5XAABHF.js → chunk-VF25WARH.js} +11 -11
- package/dist/chunk-WGUYD2A2.mjs +2 -0
- package/dist/headless-B7TGKW6I.js +1 -0
- package/dist/{headless-I5CZ42MD.mjs → headless-PZWHORT6.mjs} +1 -1
- package/dist/index.d.mts +118 -1997
- package/dist/index.d.ts +118 -1997
- package/dist/index.js +1 -5
- package/dist/index.mjs +1 -5
- package/dist/mcp.d.mts +180 -0
- package/dist/mcp.d.ts +180 -0
- package/dist/mcp.js +4 -0
- package/dist/mcp.mjs +4 -0
- package/dist/react.d.mts +78 -0
- package/dist/react.d.ts +78 -0
- package/dist/react.js +1 -0
- package/dist/react.mjs +1 -0
- package/dist/server-B7dGWiLh.d.mts +2395 -0
- package/dist/server-B7dGWiLh.d.ts +2395 -0
- package/dist/server.d.mts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/server.js +1 -0
- package/dist/server.mjs +1 -0
- package/package.json +52 -1
- package/dist/headless-DGAHMYIU.js +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1 @@
|
|
|
1
|
-
'use strict';var
|
|
2
|
-
`));}s.push(a);}return {type:"table",index:e,rows:s}}function H(r){let e=[];for(let t of r)switch(t.type){case "heading":e.push(`[${t.index}] (h${t.level}) ${t.text}`);break;case "paragraph":e.push(`[${t.index}] ${t.text}`);break;case "list-item":{let o=" ".repeat(t.listLevel),s=t.listType==="bullet"?"\u2022":"-";e.push(`[${t.index}] ${o}${s} ${t.text}`);break}case "table":{let o=t.index;for(let s=0;s<t.rows.length;s++)for(let n=0;n<t.rows[s].length;n++){let i=t.rows[s][n].split(`
|
|
3
|
-
`);for(let c of i)e.push(`[${o}] (table, row ${s+1}, col ${n+1}) ${c}`),o++;}break}}return e.join(`
|
|
4
|
-
`)}function L(r,e,t){let o=[],s=new Set;for(let n of r.content){if(n.type==="commentRangeStart"&&t){s.add(n.id),o.push(`[comment:${n.id}]`);continue}if(n.type==="commentRangeEnd"&&t){s.has(n.id)&&(s.delete(n.id),o.push("[/comment]"));continue}if(n.type==="run")o.push(chunkG5XAABHF_js.Q(n));else if(n.type==="hyperlink")o.push(chunkG5XAABHF_js.R(n));else if(d(n)){let a=C(n.content);n.type==="insertion"||n.type==="moveTo"?e?o.push(`[+${a}+]{by:${n.info.author}}`):o.push(a):e&&o.push(`[-${a}-]{by:${n.info.author}}`);}}return o.join("")}var g=class extends Error{constructor(e,t){let o=t!==void 0?` in paragraph ${t}`:" in document";super(`Text not found${o}: "${e}"`),this.name="TextNotFoundError";}},x=class extends Error{constructor(e){super(`Tracked change not found: id=${e}`),this.name="ChangeNotFoundError";}},y=class extends Error{constructor(e){super(`Comment not found: id=${e}`),this.name="CommentNotFoundError";}};function U(r){let e=[],t=0;for(let o=0;o<r.content.length;o++){let s=r.content[o];if(s.type==="run"){let n=chunkG5XAABHF_js.Q(s);e.push({contentIndex:o,run:s,text:n,startPos:t}),t+=n.length;}else if(s.type==="hyperlink")for(let n=0;n<s.children.length;n++){let a=s.children[n];if(a.type==="run"){let i=chunkG5XAABHF_js.Q(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}}else if(d(s))for(let n=0;n<s.content.length;n++){let a=s.content[n];if(a.type==="run"){let i=chunkG5XAABHF_js.Q(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}else if(a.type==="hyperlink"){for(let i of a.children)if(i.type==="run"){let c=chunkG5XAABHF_js.Q(i);e.push({contentIndex:o,run:i,text:c,startPos:t}),t+=c.length;}}}}return e}function E(r){return U(r).map(e=>e.text).join("")}function F(r,e,t){let o=U(r),s=o.map(p=>p.text).join(""),n=ae(s,e);if(!n)throw new g(e,t);let a=-1,i=0;for(let p=0;p<o.length;p++)if(n.start<o[p].startPos+o[p].text.length){a=p,i=n.start-o[p].startPos;break}let c=-1,u=0;for(let p=o.length-1;p>=0;p--)if(n.end>o[p].startPos){c=p,u=n.end-o[p].startPos;break}if(a===-1||c===-1)throw new g(e,t);return {startRunIndex:o[a].contentIndex,startOffset:i,endRunIndex:o[c].contentIndex,endOffset:u}}function I(r,e,t){let o=F(r,e,t),{startRunIndex:s,endRunIndex:n}=o,{startOffset:a,endOffset:i}=o,c=r.content[n];if(c.type==="run"){let p=chunkG5XAABHF_js.Q(c);if(i<p.length){let m=G(p.slice(i),c);N(c,p.slice(0,i)),r.content.splice(n+1,0,m);}}let u=r.content[s];if(u.type==="run"&&a>0){let p=chunkG5XAABHF_js.Q(u),m=G(p.slice(0,a),u);N(u,p.slice(a)),r.content.splice(s,0,m),s++,n++;}return {startIndex:s,endIndex:n}}function G(r,e){return {type:"run",content:[{type:"text",text:r}],formatting:e.formatting?{...e.formatting}:void 0}}function N(r,e){let t=r.content.find(o=>o.type==="text");t&&(t.text=e);}function W(r){let e=[],t=[],o=true;for(let s=0;s<r.length;s++){let n=r[s];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(n)){if("\u201C\u201D\u201E\u201F".includes(n)&&(n='"'),"\u2018\u2019\u201A\u201B".includes(n)&&(n="'"),"\u2013\u2014\u2012\u2015".includes(n)&&(n="-"),n==="\u2026"){e.push(".",".","."),t.push(s,s,s),o=false;continue}if(/\s/.test(n)||n==="\xA0"){o||(e.push(" "),t.push(s),o=true);continue}e.push(n.toLowerCase()),t.push(s),o=false;}}return e.length>0&&e[e.length-1]===" "&&(e.pop(),t.pop()),{text:e.join(""),posMap:t}}function z(r,e,t,o){let s=r.posMap[e],n=r.posMap[e+t-1]+1;for(;n<o.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(o[n]);)n++;return {start:s,end:n}}function ae(r,e){if(!e||!r)return null;let t=r.indexOf(e);if(t!==-1)return {start:t,end:t+e.length};let o=W(r),s=W(e);if(!s.text)return null;let n=o.text.indexOf(s.text);if(n!==-1)return z(o,n,s.text.length,r);let a=s.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(" "),u=o.text.indexOf(c);if(u!==-1)return z(o,u,c.length,r)}return null}function q(r,e){let t=new Map;return f(r,(s,n)=>{let a=null;for(let i of s.content)if(d(i)){a===null&&(a=E(s));let c=C(i.content),u=i.info.id,p=t.get(u);p&&p.paragraphIndex===n?p.text+=c:t.set(u,{id:u,type:i.type,author:i.info.author,date:i.info.date??null,text:c,context:a,paragraphIndex:n});}}),Array.from(t.values()).filter(s=>!(e?.author&&s.author!==e.author||e?.type&&s.type!==e.type))}function J(r,e){let t=r.comments??[];if(t.length===0)return [];let o=ie(r),s=[],n=new Map;for(let i of t)if(i.parentId!==void 0){let c=n.get(i.parentId)??[];c.push(i),n.set(i.parentId,c);}else s.push(i);return s.map(i=>{let c=o.get(i.id),u=(n.get(i.id)??[]).map(p=>({id:p.id,author:p.author,date:p.date??null,text:X(p)}));return {id:i.id,author:i.author,date:i.date??null,text:X(i),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:u,done:i.done??false}}).filter(i=>!(e?.author&&i.author!==e.author||e?.done!==void 0&&i.done!==e.done))}function X(r){return r.content.map(e=>E(e)).join(`
|
|
5
|
-
`)}function ie(r){let e=new Map,t=new Map;return f(r,(o,s)=>{for(let n of o.content)if(n.type==="commentRangeStart")t.set(n.id,{paragraphIndex:s,parts:[]});else if(n.type==="commentRangeEnd"){let a=t.get(n.id);a&&(e.set(n.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),t.delete(n.id));}else if(n.type==="run"){let a=chunkG5XAABHF_js.Q(n);for(let i of t.values())i.parts.push(a);}else if(n.type==="hyperlink"){let a=n.children.filter(i=>i.type==="run").map(chunkG5XAABHF_js.Q).join("");for(let i of t.values())i.parts.push(a);}else if(d(n)){let a=C(n.content);for(let i of t.values())i.parts.push(a);}}),e}function R(r,e){let{paragraphIndex:t,author:o="AI",text:s,search:n}=e,a=h(r,t),i=(r.comments??[]).map(p=>p.id),c=i.length>0?Math.max(...i)+1:1,u={id:c,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(r.comments||(r.comments=[]),r.comments.push(u),n){let p=F(a,n,t);a.content.splice(p.endRunIndex+1,0,{type:"commentRangeEnd",id:c}),a.content.splice(p.startRunIndex,0,{type:"commentRangeStart",id:c});}else a.content.unshift({type:"commentRangeStart",id:c}),a.content.push({type:"commentRangeEnd",id:c});return c}function v(r,e,t){let o=r.comments??[];if(!o.find(c=>c.id===e))throw new y(e);let n=o.map(c=>c.id),a=Math.max(...n)+1,i={id:a,author:t.author??"AI",date:new Date().toISOString(),parentId:e,content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:t.text}]}],formatting:{}}]};return o.push(i),a}function K(r,e){let t=r.comments??[],o=t.find(a=>a.id===e);if(!o)throw new y(e);let s=o.parentId!==void 0,n=new Set([e]);if(!s)for(let a of t)a.parentId===e&&n.add(a.id);r.comments=t.filter(a=>!n.has(a.id)),!s&&f(r,a=>{for(let i=a.content.length-1;i>=0;i--){let c=a.content[i];(c.type==="commentRangeStart"||c.type==="commentRangeEnd")&&c.id===e&&a.content.splice(i,1);}});}function w(r,e){if(!_(r,e,"accept"))throw new x(e)}function B(r,e){if(!_(r,e,"reject"))throw new x(e)}function V(r){return Z(r,"accept")}function Y(r){return Z(r,"reject")}function Z(r,e){let t=0;return f(r,o=>{for(let s=o.content.length-1;s>=0;s--){let n=o.content[s];d(n)&&(ee(o,s,n,e),t++);}}),t}function _(r,e,t){let o=false;return f(r,s=>{for(let n=s.content.length-1;n>=0;n--){let a=s.content[n];d(a)&&a.info.id===e&&(ee(s,n,a,t),o=true);}if(o)return false}),o}function ee(r,e,t,o){if(t.type==="insertion"&&o==="accept"||t.type==="deletion"&&o==="reject"||t.type==="moveTo"&&o==="accept"||t.type==="moveFrom"&&o==="reject"){let n=t.content;r.content.splice(e,1,...n);}else r.content.splice(e,1);}function T(r,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:n}=e,a=h(r,t),{startIndex:i,endIndex:c}=I(a,o,t),u=new Date().toISOString(),p=j(r),m=a.content.slice(i,c+1),D={type:"deletion",info:{id:p,author:s,date:u},content:m},P={type:"insertion",info:{id:p+1,author:s,date:u},content:[{type:"run",content:[{type:"text",text:n}]}]};a.content.splice(i,c-i+1,D,P);}function te(r,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:n="after",search:a}=e,i=h(r,t),c=new Date().toISOString(),p={type:"insertion",info:{id:j(r),author:o,date:c},content:[{type:"run",content:[{type:"text",text:s}]}]};if(a){let{startIndex:m,endIndex:D}=I(i,a,t),P=n==="after"?D+1:m;i.content.splice(P,0,p);}else n==="before"?i.content.unshift(p):i.content.push(p);}function ne(r,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,n=h(r,t),{startIndex:a,endIndex:i}=I(n,o,t),c=new Date().toISOString(),u=j(r),p=n.content.slice(a,i+1),m={type:"deletion",info:{id:u,author:s,date:c},content:p};n.content.splice(a,i-a+1,m);}var Q=new WeakMap;function j(r){let e=Q.get(r);e===void 0&&(e=0,f(r,o=>{for(let s of o.content)d(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return Q.set(r,t+1),t}function oe(r,e,t="AI"){let o=[],s=0,n=0,a=0,i=0,c=0;for(let u of e.accept??[])try{w(r,u),s++;}catch(p){o.push({operation:"accept",id:u,error:p.message});}for(let u of e.reject??[])try{B(r,u),n++;}catch(p){o.push({operation:"reject",id:u,error:p.message});}for(let u of e.comments??[])try{R(r,{...u,author:u.author??t}),a++;}catch(p){o.push({operation:"comment",search:u.search,error:p.message});}for(let u of e.replies??[])try{v(r,u.commentId,{author:u.author??t,text:u.text}),i++;}catch(p){o.push({operation:"reply",id:u.commentId,error:p.message});}for(let u of e.proposals??[])try{T(r,{...u,author:u.author??t}),c++;}catch(p){o.push({operation:"proposal",search:u.search,error:p.message});}return {accepted:s,rejected:n,commentsAdded:a,repliesAdded:i,proposalsAdded:c,errors:o}}var M=class r{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:n,...a}=e;this.doc=structuredClone(a),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await chunkG5XAABHF_js.F(e,{preloadFonts:false});return new r(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return O(this.body,e)}getContentAsText(e){return H(O(this.body,e))}getChanges(e){return q(this.body,e)}getComments(e){return J(this.body,e)}addComment(e,t){let o=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return R(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return v(this.body,e,o)}removeComment(e){K(this.body,e);}replace(e,t,o){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:o,author:this.author}:{...e,author:this.resolveAuthor(e.author)};T(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){te(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){ne(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){w(this.body,e);}rejectChange(e){B(this.body,e);}acceptAll(){return V(this.body)}rejectAll(){return Y(this.body)}applyReview(e){return oe(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-DGAHMYIU.js');return e(this.doc)}};exports.ChangeNotFoundError=x;exports.CommentNotFoundError=y;exports.DocxReviewer=M;exports.TextNotFoundError=g;
|
|
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,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
`));}s.push(a);}return {type:"table",index:e,rows:s}}function H(r){let e=[];for(let t of r)switch(t.type){case "heading":e.push(`[${t.index}] (h${t.level}) ${t.text}`);break;case "paragraph":e.push(`[${t.index}] ${t.text}`);break;case "list-item":{let o=" ".repeat(t.listLevel),s=t.listType==="bullet"?"\u2022":"-";e.push(`[${t.index}] ${o}${s} ${t.text}`);break}case "table":{let o=t.index;for(let s=0;s<t.rows.length;s++)for(let n=0;n<t.rows[s].length;n++){let i=t.rows[s][n].split(`
|
|
3
|
-
`);for(let c of i)e.push(`[${o}] (table, row ${s+1}, col ${n+1}) ${c}`),o++;}break}}return e.join(`
|
|
4
|
-
`)}function L(r,e,t){let o=[],s=new Set;for(let n of r.content){if(n.type==="commentRangeStart"&&t){s.add(n.id),o.push(`[comment:${n.id}]`);continue}if(n.type==="commentRangeEnd"&&t){s.has(n.id)&&(s.delete(n.id),o.push("[/comment]"));continue}if(n.type==="run")o.push(Q$1(n));else if(n.type==="hyperlink")o.push(R$1(n));else if(d(n)){let a=C(n.content);n.type==="insertion"||n.type==="moveTo"?e?o.push(`[+${a}+]{by:${n.info.author}}`):o.push(a):e&&o.push(`[-${a}-]{by:${n.info.author}}`);}}return o.join("")}var g=class extends Error{constructor(e,t){let o=t!==void 0?` in paragraph ${t}`:" in document";super(`Text not found${o}: "${e}"`),this.name="TextNotFoundError";}},x=class extends Error{constructor(e){super(`Tracked change not found: id=${e}`),this.name="ChangeNotFoundError";}},y=class extends Error{constructor(e){super(`Comment not found: id=${e}`),this.name="CommentNotFoundError";}};function U(r){let e=[],t=0;for(let o=0;o<r.content.length;o++){let s=r.content[o];if(s.type==="run"){let n=Q$1(s);e.push({contentIndex:o,run:s,text:n,startPos:t}),t+=n.length;}else if(s.type==="hyperlink")for(let n=0;n<s.children.length;n++){let a=s.children[n];if(a.type==="run"){let i=Q$1(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}}else if(d(s))for(let n=0;n<s.content.length;n++){let a=s.content[n];if(a.type==="run"){let i=Q$1(a);e.push({contentIndex:o,run:a,text:i,startPos:t}),t+=i.length;}else if(a.type==="hyperlink"){for(let i of a.children)if(i.type==="run"){let c=Q$1(i);e.push({contentIndex:o,run:i,text:c,startPos:t}),t+=c.length;}}}}return e}function E(r){return U(r).map(e=>e.text).join("")}function F(r,e,t){let o=U(r),s=o.map(p=>p.text).join(""),n=ae(s,e);if(!n)throw new g(e,t);let a=-1,i=0;for(let p=0;p<o.length;p++)if(n.start<o[p].startPos+o[p].text.length){a=p,i=n.start-o[p].startPos;break}let c=-1,u=0;for(let p=o.length-1;p>=0;p--)if(n.end>o[p].startPos){c=p,u=n.end-o[p].startPos;break}if(a===-1||c===-1)throw new g(e,t);return {startRunIndex:o[a].contentIndex,startOffset:i,endRunIndex:o[c].contentIndex,endOffset:u}}function I(r,e,t){let o=F(r,e,t),{startRunIndex:s,endRunIndex:n}=o,{startOffset:a,endOffset:i}=o,c=r.content[n];if(c.type==="run"){let p=Q$1(c);if(i<p.length){let m=G(p.slice(i),c);N(c,p.slice(0,i)),r.content.splice(n+1,0,m);}}let u=r.content[s];if(u.type==="run"&&a>0){let p=Q$1(u),m=G(p.slice(0,a),u);N(u,p.slice(a)),r.content.splice(s,0,m),s++,n++;}return {startIndex:s,endIndex:n}}function G(r,e){return {type:"run",content:[{type:"text",text:r}],formatting:e.formatting?{...e.formatting}:void 0}}function N(r,e){let t=r.content.find(o=>o.type==="text");t&&(t.text=e);}function W(r){let e=[],t=[],o=true;for(let s=0;s<r.length;s++){let n=r[s];if(!"\u200B\u200C\u200D\uFEFF\xAD".includes(n)){if("\u201C\u201D\u201E\u201F".includes(n)&&(n='"'),"\u2018\u2019\u201A\u201B".includes(n)&&(n="'"),"\u2013\u2014\u2012\u2015".includes(n)&&(n="-"),n==="\u2026"){e.push(".",".","."),t.push(s,s,s),o=false;continue}if(/\s/.test(n)||n==="\xA0"){o||(e.push(" "),t.push(s),o=true);continue}e.push(n.toLowerCase()),t.push(s),o=false;}}return e.length>0&&e[e.length-1]===" "&&(e.pop(),t.pop()),{text:e.join(""),posMap:t}}function z(r,e,t,o){let s=r.posMap[e],n=r.posMap[e+t-1]+1;for(;n<o.length&&"\u200B\u200C\u200D\uFEFF\xAD".includes(o[n]);)n++;return {start:s,end:n}}function ae(r,e){if(!e||!r)return null;let t=r.indexOf(e);if(t!==-1)return {start:t,end:t+e.length};let o=W(r),s=W(e);if(!s.text)return null;let n=o.text.indexOf(s.text);if(n!==-1)return z(o,n,s.text.length,r);let a=s.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(" "),u=o.text.indexOf(c);if(u!==-1)return z(o,u,c.length,r)}return null}function q(r,e){let t=new Map;return f(r,(s,n)=>{let a=null;for(let i of s.content)if(d(i)){a===null&&(a=E(s));let c=C(i.content),u=i.info.id,p=t.get(u);p&&p.paragraphIndex===n?p.text+=c:t.set(u,{id:u,type:i.type,author:i.info.author,date:i.info.date??null,text:c,context:a,paragraphIndex:n});}}),Array.from(t.values()).filter(s=>!(e?.author&&s.author!==e.author||e?.type&&s.type!==e.type))}function J(r,e){let t=r.comments??[];if(t.length===0)return [];let o=ie(r),s=[],n=new Map;for(let i of t)if(i.parentId!==void 0){let c=n.get(i.parentId)??[];c.push(i),n.set(i.parentId,c);}else s.push(i);return s.map(i=>{let c=o.get(i.id),u=(n.get(i.id)??[]).map(p=>({id:p.id,author:p.author,date:p.date??null,text:X(p)}));return {id:i.id,author:i.author,date:i.date??null,text:X(i),anchoredText:c?.text??"",paragraphIndex:c?.paragraphIndex??-1,replies:u,done:i.done??false}}).filter(i=>!(e?.author&&i.author!==e.author||e?.done!==void 0&&i.done!==e.done))}function X(r){return r.content.map(e=>E(e)).join(`
|
|
5
|
-
`)}function ie(r){let e=new Map,t=new Map;return f(r,(o,s)=>{for(let n of o.content)if(n.type==="commentRangeStart")t.set(n.id,{paragraphIndex:s,parts:[]});else if(n.type==="commentRangeEnd"){let a=t.get(n.id);a&&(e.set(n.id,{text:a.parts.join(""),paragraphIndex:a.paragraphIndex}),t.delete(n.id));}else if(n.type==="run"){let a=Q$1(n);for(let i of t.values())i.parts.push(a);}else if(n.type==="hyperlink"){let a=n.children.filter(i=>i.type==="run").map(Q$1).join("");for(let i of t.values())i.parts.push(a);}else if(d(n)){let a=C(n.content);for(let i of t.values())i.parts.push(a);}}),e}function R(r,e){let{paragraphIndex:t,author:o="AI",text:s,search:n}=e,a=h(r,t),i=(r.comments??[]).map(p=>p.id),c=i.length>0?Math.max(...i)+1:1,u={id:c,author:o,date:new Date().toISOString(),content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:s}]}],formatting:{}}]};if(r.comments||(r.comments=[]),r.comments.push(u),n){let p=F(a,n,t);a.content.splice(p.endRunIndex+1,0,{type:"commentRangeEnd",id:c}),a.content.splice(p.startRunIndex,0,{type:"commentRangeStart",id:c});}else a.content.unshift({type:"commentRangeStart",id:c}),a.content.push({type:"commentRangeEnd",id:c});return c}function v(r,e,t){let o=r.comments??[];if(!o.find(c=>c.id===e))throw new y(e);let n=o.map(c=>c.id),a=Math.max(...n)+1,i={id:a,author:t.author??"AI",date:new Date().toISOString(),parentId:e,content:[{type:"paragraph",content:[{type:"run",content:[{type:"text",text:t.text}]}],formatting:{}}]};return o.push(i),a}function K(r,e){let t=r.comments??[],o=t.find(a=>a.id===e);if(!o)throw new y(e);let s=o.parentId!==void 0,n=new Set([e]);if(!s)for(let a of t)a.parentId===e&&n.add(a.id);r.comments=t.filter(a=>!n.has(a.id)),!s&&f(r,a=>{for(let i=a.content.length-1;i>=0;i--){let c=a.content[i];(c.type==="commentRangeStart"||c.type==="commentRangeEnd")&&c.id===e&&a.content.splice(i,1);}});}function w(r,e){if(!_(r,e,"accept"))throw new x(e)}function B(r,e){if(!_(r,e,"reject"))throw new x(e)}function V(r){return Z(r,"accept")}function Y(r){return Z(r,"reject")}function Z(r,e){let t=0;return f(r,o=>{for(let s=o.content.length-1;s>=0;s--){let n=o.content[s];d(n)&&(ee(o,s,n,e),t++);}}),t}function _(r,e,t){let o=false;return f(r,s=>{for(let n=s.content.length-1;n>=0;n--){let a=s.content[n];d(a)&&a.info.id===e&&(ee(s,n,a,t),o=true);}if(o)return false}),o}function ee(r,e,t,o){if(t.type==="insertion"&&o==="accept"||t.type==="deletion"&&o==="reject"||t.type==="moveTo"&&o==="accept"||t.type==="moveFrom"&&o==="reject"){let n=t.content;r.content.splice(e,1,...n);}else r.content.splice(e,1);}function T(r,e){let{paragraphIndex:t,search:o,author:s="AI",replaceWith:n}=e,a=h(r,t),{startIndex:i,endIndex:c}=I(a,o,t),u=new Date().toISOString(),p=j(r),m=a.content.slice(i,c+1),D={type:"deletion",info:{id:p,author:s,date:u},content:m},P={type:"insertion",info:{id:p+1,author:s,date:u},content:[{type:"run",content:[{type:"text",text:n}]}]};a.content.splice(i,c-i+1,D,P);}function te(r,e){let{paragraphIndex:t,author:o="AI",insertText:s,position:n="after",search:a}=e,i=h(r,t),c=new Date().toISOString(),p={type:"insertion",info:{id:j(r),author:o,date:c},content:[{type:"run",content:[{type:"text",text:s}]}]};if(a){let{startIndex:m,endIndex:D}=I(i,a,t),P=n==="after"?D+1:m;i.content.splice(P,0,p);}else n==="before"?i.content.unshift(p):i.content.push(p);}function ne(r,e){let{paragraphIndex:t,search:o,author:s="AI"}=e,n=h(r,t),{startIndex:a,endIndex:i}=I(n,o,t),c=new Date().toISOString(),u=j(r),p=n.content.slice(a,i+1),m={type:"deletion",info:{id:u,author:s,date:c},content:p};n.content.splice(a,i-a+1,m);}var Q=new WeakMap;function j(r){let e=Q.get(r);e===void 0&&(e=0,f(r,o=>{for(let s of o.content)d(s)&&(e=Math.max(e,s.info.id));}));let t=e+1;return Q.set(r,t+1),t}function oe(r,e,t="AI"){let o=[],s=0,n=0,a=0,i=0,c=0;for(let u of e.accept??[])try{w(r,u),s++;}catch(p){o.push({operation:"accept",id:u,error:p.message});}for(let u of e.reject??[])try{B(r,u),n++;}catch(p){o.push({operation:"reject",id:u,error:p.message});}for(let u of e.comments??[])try{R(r,{...u,author:u.author??t}),a++;}catch(p){o.push({operation:"comment",search:u.search,error:p.message});}for(let u of e.replies??[])try{v(r,u.commentId,{author:u.author??t,text:u.text}),i++;}catch(p){o.push({operation:"reply",id:u.commentId,error:p.message});}for(let u of e.proposals??[])try{T(r,{...u,author:u.author??t}),c++;}catch(p){o.push({operation:"proposal",search:u.search,error:p.message});}return {accepted:s,rejected:n,commentsAdded:a,repliesAdded:i,proposalsAdded:c,errors:o}}var M=class r{constructor(e,t="AI",o){let s=o??e.originalBuffer,{originalBuffer:n,...a}=e;this.doc=structuredClone(a),s&&(this.doc.originalBuffer=s),this.author=t;}static async fromBuffer(e,t="AI"){let o=await F$1(e,{preloadFonts:false});return new r(o,t,e)}get body(){return this.doc.package.document}resolveAuthor(e){return e??this.author}getContent(e){return O(this.body,e)}getContentAsText(e){return H(O(this.body,e))}getChanges(e){return q(this.body,e)}getComments(e){return J(this.body,e)}addComment(e,t){let o=typeof e=="number"?{paragraphIndex:e,text:t,author:this.author}:{...e,author:this.resolveAuthor(e.author)};return R(this.body,o)}replyTo(e,t){let o=typeof t=="string"?{text:t,author:this.author}:{...t,author:this.resolveAuthor(t.author)};return v(this.body,e,o)}removeComment(e){K(this.body,e);}replace(e,t,o){let s=typeof e=="number"?{paragraphIndex:e,search:t,replaceWith:o,author:this.author}:{...e,author:this.resolveAuthor(e.author)};T(this.body,s);}proposeReplacement(e){this.replace(e);}proposeInsertion(e){te(this.body,{...e,author:this.resolveAuthor(e.author)});}proposeDeletion(e){ne(this.body,{...e,author:this.resolveAuthor(e.author)});}acceptChange(e){w(this.body,e);}rejectChange(e){B(this.body,e);}acceptAll(){return V(this.body)}rejectAll(){return Y(this.body)}applyReview(e){return oe(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-I5CZ42MD.mjs');return e(this.doc)}};export{x as ChangeNotFoundError,y as CommentNotFoundError,M as DocxReviewer,g as TextNotFoundError};
|
|
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.d.mts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { v as EditorBridge } from './server-B7dGWiLh.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MCP wire protocol (subset) — JSON-RPC 2.0 framing + the message types we
|
|
5
|
+
* actually implement. Zero dependencies. Pure functions; everything is unit-
|
|
6
|
+
* testable without a transport.
|
|
7
|
+
*
|
|
8
|
+
* This is NOT a full MCP SDK. We implement only what the server needs:
|
|
9
|
+
* - initialize / initialized
|
|
10
|
+
* - tools/list
|
|
11
|
+
* - tools/call
|
|
12
|
+
* - notifications/cancelled (no-op, accepted)
|
|
13
|
+
*
|
|
14
|
+
* Spec reference: https://spec.modelcontextprotocol.io
|
|
15
|
+
*/
|
|
16
|
+
type JsonRpcId = string | number | null;
|
|
17
|
+
interface JsonRpcRequest {
|
|
18
|
+
jsonrpc: '2.0';
|
|
19
|
+
id: JsonRpcId;
|
|
20
|
+
method: string;
|
|
21
|
+
params?: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface JsonRpcNotification {
|
|
24
|
+
jsonrpc: '2.0';
|
|
25
|
+
method: string;
|
|
26
|
+
params?: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface JsonRpcSuccess {
|
|
29
|
+
jsonrpc: '2.0';
|
|
30
|
+
id: JsonRpcId;
|
|
31
|
+
result: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface JsonRpcError {
|
|
34
|
+
jsonrpc: '2.0';
|
|
35
|
+
id: JsonRpcId;
|
|
36
|
+
error: {
|
|
37
|
+
code: number;
|
|
38
|
+
message: string;
|
|
39
|
+
data?: unknown;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
type JsonRpcResponse = JsonRpcSuccess | JsonRpcError;
|
|
43
|
+
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
44
|
+
/** Standard JSON-RPC error codes. We only ever emit JSON-RPC errors for
|
|
45
|
+
* protocol-level problems; tool execution failures use MCP's `isError`
|
|
46
|
+
* envelope inside a successful response, per spec. */
|
|
47
|
+
declare const ErrorCode: {
|
|
48
|
+
readonly ParseError: -32700;
|
|
49
|
+
readonly InvalidRequest: -32600;
|
|
50
|
+
readonly MethodNotFound: -32601;
|
|
51
|
+
readonly InvalidParams: -32602;
|
|
52
|
+
readonly InternalError: -32603;
|
|
53
|
+
};
|
|
54
|
+
interface McpInitializeResult {
|
|
55
|
+
protocolVersion: string;
|
|
56
|
+
capabilities: {
|
|
57
|
+
tools?: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
serverInfo: {
|
|
60
|
+
name: string;
|
|
61
|
+
version: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
interface McpToolDescriptor {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
inputSchema: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
interface McpToolsListResult {
|
|
70
|
+
tools: McpToolDescriptor[];
|
|
71
|
+
}
|
|
72
|
+
interface McpToolsCallParams {
|
|
73
|
+
name: string;
|
|
74
|
+
arguments?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
interface McpContent {
|
|
77
|
+
type: 'text';
|
|
78
|
+
text: string;
|
|
79
|
+
}
|
|
80
|
+
interface McpToolsCallResult {
|
|
81
|
+
content: McpContent[];
|
|
82
|
+
isError?: boolean;
|
|
83
|
+
}
|
|
84
|
+
declare function isJsonRpcRequest(m: unknown): m is JsonRpcRequest;
|
|
85
|
+
declare function isJsonRpcNotification(m: unknown): m is JsonRpcNotification;
|
|
86
|
+
declare function makeSuccess(id: JsonRpcId, result: unknown): JsonRpcSuccess;
|
|
87
|
+
declare function makeError(id: JsonRpcId, code: number, message: string, data?: unknown): JsonRpcError;
|
|
88
|
+
interface ParseResult {
|
|
89
|
+
/** Parsed messages. */
|
|
90
|
+
messages: JsonRpcMessage[];
|
|
91
|
+
/** Lines that failed to parse — caller should send a ParseError per line if it had a discernible id. */
|
|
92
|
+
parseErrors: string[];
|
|
93
|
+
/** Remaining buffer (no trailing newline yet). */
|
|
94
|
+
rest: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parse newline-delimited JSON-RPC frames out of a buffer. Returns parsed
|
|
98
|
+
* messages plus any leftover bytes. Tolerates blank lines.
|
|
99
|
+
*/
|
|
100
|
+
declare function parseFrames(buffer: string): ParseResult;
|
|
101
|
+
/** Encode a JSON-RPC message as a single newline-terminated frame. */
|
|
102
|
+
declare function encodeFrame(message: JsonRpcMessage): string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* MCP server core. Transport-agnostic — accepts a JsonRpcRequest, returns
|
|
106
|
+
* either a JsonRpcResponse or `null` (for notifications, which never reply).
|
|
107
|
+
*
|
|
108
|
+
* Wraps an EditorBridge: tools/list returns the bridge's tool schemas in MCP
|
|
109
|
+
* shape; tools/call dispatches via executeToolCall and converts the
|
|
110
|
+
* AgentToolResult into MCP CallToolResult content.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
interface McpServerOptions {
|
|
114
|
+
/** Server name reported in `initialize` response. Default: `@eigenpal/docx-editor-agents`. */
|
|
115
|
+
name?: string;
|
|
116
|
+
/** Server version. Default: `0.0.0` (override at build time). */
|
|
117
|
+
version?: string;
|
|
118
|
+
/** MCP protocol version we claim to speak. Default: `2025-06-18`. */
|
|
119
|
+
protocolVersion?: string;
|
|
120
|
+
}
|
|
121
|
+
declare class McpServer {
|
|
122
|
+
private readonly bridge;
|
|
123
|
+
private readonly opts;
|
|
124
|
+
constructor(bridge: EditorBridge, options?: McpServerOptions);
|
|
125
|
+
/**
|
|
126
|
+
* Handle one inbound message. Returns the response to send back, or `null`
|
|
127
|
+
* for notifications and other no-reply messages. Never throws.
|
|
128
|
+
*/
|
|
129
|
+
handle(message: JsonRpcMessage): JsonRpcResponse | null;
|
|
130
|
+
private handleInitialize;
|
|
131
|
+
private handleToolsList;
|
|
132
|
+
private handleToolsCall;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Stdio transport for the MCP server. Reads newline-delimited JSON-RPC from
|
|
137
|
+
* an input stream, dispatches via McpServer, writes responses to an output
|
|
138
|
+
* stream. Pure stream handling — no Node-only assumptions beyond "Readable
|
|
139
|
+
* has .on('data') and Writable has .write".
|
|
140
|
+
*
|
|
141
|
+
* For real Node usage:
|
|
142
|
+
* import { runStdioServer } from '@eigenpal/docx-editor-agents/mcp';
|
|
143
|
+
* runStdioServer(bridge);
|
|
144
|
+
*
|
|
145
|
+
* For tests, pass any EventEmitter-shaped Readable + a function-shaped
|
|
146
|
+
* Writable; see __tests__/mcp/stdio.test.ts.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/** Minimal duck-typed input stream — anything with `on('data', cb)` works. */
|
|
150
|
+
interface InputStream {
|
|
151
|
+
on(event: 'data', listener: (chunk: Buffer | string) => void): unknown;
|
|
152
|
+
on(event: 'end', listener: () => void): unknown;
|
|
153
|
+
on(event: 'error', listener: (err: Error) => void): unknown;
|
|
154
|
+
}
|
|
155
|
+
/** Minimal duck-typed output stream — anything with a `write(string) => bool` works. */
|
|
156
|
+
interface OutputStream {
|
|
157
|
+
write(chunk: string): boolean | void;
|
|
158
|
+
}
|
|
159
|
+
interface StdioServerOptions extends McpServerOptions {
|
|
160
|
+
input?: InputStream;
|
|
161
|
+
output?: OutputStream;
|
|
162
|
+
/** Called with diagnostic strings (e.g. parse errors). Default: stderr. */
|
|
163
|
+
log?: (msg: string) => void;
|
|
164
|
+
}
|
|
165
|
+
interface StdioServerHandle {
|
|
166
|
+
/** Underlying server (for tests / introspection). */
|
|
167
|
+
server: McpServer;
|
|
168
|
+
/** Manually feed a raw chunk (used by tests; the live transport calls this internally). */
|
|
169
|
+
feed: (chunk: string | Buffer) => void;
|
|
170
|
+
/** Stop accepting input and reject further writes. Idempotent. */
|
|
171
|
+
close: () => void;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Wire an EditorBridge to a JSON-RPC stdio loop. Returns immediately; reading
|
|
175
|
+
* happens via the stream listeners. Designed to be testable: pass in fake
|
|
176
|
+
* streams, call `feed(...)` directly, then assert on what was written.
|
|
177
|
+
*/
|
|
178
|
+
declare function runStdioServer(bridge: EditorBridge, options?: StdioServerOptions): StdioServerHandle;
|
|
179
|
+
|
|
180
|
+
export { ErrorCode, type JsonRpcError, type JsonRpcId, type JsonRpcMessage, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccess, type McpContent, type McpInitializeResult, McpServer, type McpServerOptions, type McpToolDescriptor, type McpToolsCallParams, type McpToolsCallResult, type McpToolsListResult, type StdioServerHandle, type StdioServerOptions, encodeFrame, isJsonRpcNotification, isJsonRpcRequest, makeError, makeSuccess, parseFrames, runStdioServer };
|
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { v as EditorBridge } from './server-B7dGWiLh.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MCP wire protocol (subset) — JSON-RPC 2.0 framing + the message types we
|
|
5
|
+
* actually implement. Zero dependencies. Pure functions; everything is unit-
|
|
6
|
+
* testable without a transport.
|
|
7
|
+
*
|
|
8
|
+
* This is NOT a full MCP SDK. We implement only what the server needs:
|
|
9
|
+
* - initialize / initialized
|
|
10
|
+
* - tools/list
|
|
11
|
+
* - tools/call
|
|
12
|
+
* - notifications/cancelled (no-op, accepted)
|
|
13
|
+
*
|
|
14
|
+
* Spec reference: https://spec.modelcontextprotocol.io
|
|
15
|
+
*/
|
|
16
|
+
type JsonRpcId = string | number | null;
|
|
17
|
+
interface JsonRpcRequest {
|
|
18
|
+
jsonrpc: '2.0';
|
|
19
|
+
id: JsonRpcId;
|
|
20
|
+
method: string;
|
|
21
|
+
params?: unknown;
|
|
22
|
+
}
|
|
23
|
+
interface JsonRpcNotification {
|
|
24
|
+
jsonrpc: '2.0';
|
|
25
|
+
method: string;
|
|
26
|
+
params?: unknown;
|
|
27
|
+
}
|
|
28
|
+
interface JsonRpcSuccess {
|
|
29
|
+
jsonrpc: '2.0';
|
|
30
|
+
id: JsonRpcId;
|
|
31
|
+
result: unknown;
|
|
32
|
+
}
|
|
33
|
+
interface JsonRpcError {
|
|
34
|
+
jsonrpc: '2.0';
|
|
35
|
+
id: JsonRpcId;
|
|
36
|
+
error: {
|
|
37
|
+
code: number;
|
|
38
|
+
message: string;
|
|
39
|
+
data?: unknown;
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
type JsonRpcResponse = JsonRpcSuccess | JsonRpcError;
|
|
43
|
+
type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
|
|
44
|
+
/** Standard JSON-RPC error codes. We only ever emit JSON-RPC errors for
|
|
45
|
+
* protocol-level problems; tool execution failures use MCP's `isError`
|
|
46
|
+
* envelope inside a successful response, per spec. */
|
|
47
|
+
declare const ErrorCode: {
|
|
48
|
+
readonly ParseError: -32700;
|
|
49
|
+
readonly InvalidRequest: -32600;
|
|
50
|
+
readonly MethodNotFound: -32601;
|
|
51
|
+
readonly InvalidParams: -32602;
|
|
52
|
+
readonly InternalError: -32603;
|
|
53
|
+
};
|
|
54
|
+
interface McpInitializeResult {
|
|
55
|
+
protocolVersion: string;
|
|
56
|
+
capabilities: {
|
|
57
|
+
tools?: Record<string, unknown>;
|
|
58
|
+
};
|
|
59
|
+
serverInfo: {
|
|
60
|
+
name: string;
|
|
61
|
+
version: string;
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
interface McpToolDescriptor {
|
|
65
|
+
name: string;
|
|
66
|
+
description: string;
|
|
67
|
+
inputSchema: Record<string, unknown>;
|
|
68
|
+
}
|
|
69
|
+
interface McpToolsListResult {
|
|
70
|
+
tools: McpToolDescriptor[];
|
|
71
|
+
}
|
|
72
|
+
interface McpToolsCallParams {
|
|
73
|
+
name: string;
|
|
74
|
+
arguments?: Record<string, unknown>;
|
|
75
|
+
}
|
|
76
|
+
interface McpContent {
|
|
77
|
+
type: 'text';
|
|
78
|
+
text: string;
|
|
79
|
+
}
|
|
80
|
+
interface McpToolsCallResult {
|
|
81
|
+
content: McpContent[];
|
|
82
|
+
isError?: boolean;
|
|
83
|
+
}
|
|
84
|
+
declare function isJsonRpcRequest(m: unknown): m is JsonRpcRequest;
|
|
85
|
+
declare function isJsonRpcNotification(m: unknown): m is JsonRpcNotification;
|
|
86
|
+
declare function makeSuccess(id: JsonRpcId, result: unknown): JsonRpcSuccess;
|
|
87
|
+
declare function makeError(id: JsonRpcId, code: number, message: string, data?: unknown): JsonRpcError;
|
|
88
|
+
interface ParseResult {
|
|
89
|
+
/** Parsed messages. */
|
|
90
|
+
messages: JsonRpcMessage[];
|
|
91
|
+
/** Lines that failed to parse — caller should send a ParseError per line if it had a discernible id. */
|
|
92
|
+
parseErrors: string[];
|
|
93
|
+
/** Remaining buffer (no trailing newline yet). */
|
|
94
|
+
rest: string;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parse newline-delimited JSON-RPC frames out of a buffer. Returns parsed
|
|
98
|
+
* messages plus any leftover bytes. Tolerates blank lines.
|
|
99
|
+
*/
|
|
100
|
+
declare function parseFrames(buffer: string): ParseResult;
|
|
101
|
+
/** Encode a JSON-RPC message as a single newline-terminated frame. */
|
|
102
|
+
declare function encodeFrame(message: JsonRpcMessage): string;
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* MCP server core. Transport-agnostic — accepts a JsonRpcRequest, returns
|
|
106
|
+
* either a JsonRpcResponse or `null` (for notifications, which never reply).
|
|
107
|
+
*
|
|
108
|
+
* Wraps an EditorBridge: tools/list returns the bridge's tool schemas in MCP
|
|
109
|
+
* shape; tools/call dispatches via executeToolCall and converts the
|
|
110
|
+
* AgentToolResult into MCP CallToolResult content.
|
|
111
|
+
*/
|
|
112
|
+
|
|
113
|
+
interface McpServerOptions {
|
|
114
|
+
/** Server name reported in `initialize` response. Default: `@eigenpal/docx-editor-agents`. */
|
|
115
|
+
name?: string;
|
|
116
|
+
/** Server version. Default: `0.0.0` (override at build time). */
|
|
117
|
+
version?: string;
|
|
118
|
+
/** MCP protocol version we claim to speak. Default: `2025-06-18`. */
|
|
119
|
+
protocolVersion?: string;
|
|
120
|
+
}
|
|
121
|
+
declare class McpServer {
|
|
122
|
+
private readonly bridge;
|
|
123
|
+
private readonly opts;
|
|
124
|
+
constructor(bridge: EditorBridge, options?: McpServerOptions);
|
|
125
|
+
/**
|
|
126
|
+
* Handle one inbound message. Returns the response to send back, or `null`
|
|
127
|
+
* for notifications and other no-reply messages. Never throws.
|
|
128
|
+
*/
|
|
129
|
+
handle(message: JsonRpcMessage): JsonRpcResponse | null;
|
|
130
|
+
private handleInitialize;
|
|
131
|
+
private handleToolsList;
|
|
132
|
+
private handleToolsCall;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Stdio transport for the MCP server. Reads newline-delimited JSON-RPC from
|
|
137
|
+
* an input stream, dispatches via McpServer, writes responses to an output
|
|
138
|
+
* stream. Pure stream handling — no Node-only assumptions beyond "Readable
|
|
139
|
+
* has .on('data') and Writable has .write".
|
|
140
|
+
*
|
|
141
|
+
* For real Node usage:
|
|
142
|
+
* import { runStdioServer } from '@eigenpal/docx-editor-agents/mcp';
|
|
143
|
+
* runStdioServer(bridge);
|
|
144
|
+
*
|
|
145
|
+
* For tests, pass any EventEmitter-shaped Readable + a function-shaped
|
|
146
|
+
* Writable; see __tests__/mcp/stdio.test.ts.
|
|
147
|
+
*/
|
|
148
|
+
|
|
149
|
+
/** Minimal duck-typed input stream — anything with `on('data', cb)` works. */
|
|
150
|
+
interface InputStream {
|
|
151
|
+
on(event: 'data', listener: (chunk: Buffer | string) => void): unknown;
|
|
152
|
+
on(event: 'end', listener: () => void): unknown;
|
|
153
|
+
on(event: 'error', listener: (err: Error) => void): unknown;
|
|
154
|
+
}
|
|
155
|
+
/** Minimal duck-typed output stream — anything with a `write(string) => bool` works. */
|
|
156
|
+
interface OutputStream {
|
|
157
|
+
write(chunk: string): boolean | void;
|
|
158
|
+
}
|
|
159
|
+
interface StdioServerOptions extends McpServerOptions {
|
|
160
|
+
input?: InputStream;
|
|
161
|
+
output?: OutputStream;
|
|
162
|
+
/** Called with diagnostic strings (e.g. parse errors). Default: stderr. */
|
|
163
|
+
log?: (msg: string) => void;
|
|
164
|
+
}
|
|
165
|
+
interface StdioServerHandle {
|
|
166
|
+
/** Underlying server (for tests / introspection). */
|
|
167
|
+
server: McpServer;
|
|
168
|
+
/** Manually feed a raw chunk (used by tests; the live transport calls this internally). */
|
|
169
|
+
feed: (chunk: string | Buffer) => void;
|
|
170
|
+
/** Stop accepting input and reject further writes. Idempotent. */
|
|
171
|
+
close: () => void;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Wire an EditorBridge to a JSON-RPC stdio loop. Returns immediately; reading
|
|
175
|
+
* happens via the stream listeners. Designed to be testable: pass in fake
|
|
176
|
+
* streams, call `feed(...)` directly, then assert on what was written.
|
|
177
|
+
*/
|
|
178
|
+
declare function runStdioServer(bridge: EditorBridge, options?: StdioServerOptions): StdioServerHandle;
|
|
179
|
+
|
|
180
|
+
export { ErrorCode, type JsonRpcError, type JsonRpcId, type JsonRpcMessage, type JsonRpcNotification, type JsonRpcRequest, type JsonRpcResponse, type JsonRpcSuccess, type McpContent, type McpInitializeResult, McpServer, type McpServerOptions, type McpToolDescriptor, type McpToolsCallParams, type McpToolsCallResult, type McpToolsListResult, type StdioServerHandle, type StdioServerOptions, encodeFrame, isJsonRpcNotification, isJsonRpcRequest, makeError, makeSuccess, parseFrames, runStdioServer };
|
package/dist/mcp.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
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
|
+
`),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: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
|
+
`);});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
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
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
|
+
`),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: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
|
+
`);});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.d.mts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { E as EditorRefLike, A as AgentToolDefinition, g as getToolSchemas, a as AgentToolResult, b as AgentContextSnapshot } from './server-B7dGWiLh.mjs';
|
|
2
|
+
export { U as UseAgentChatOptions, c as UseAgentChatReturn, d as getToolDisplayName, u as useAgentChat } from './server-B7dGWiLh.mjs';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* useDocxAgentTools — wires the toolkit to a live DocxEditor for BYO chat
|
|
6
|
+
* frameworks.
|
|
7
|
+
*
|
|
8
|
+
* Returns three things consumers need to plug an agent into the editor:
|
|
9
|
+
*
|
|
10
|
+
* - `tools` — schemas in OpenAI function-calling format. Pass to `streamText({ tools })`,
|
|
11
|
+
* OpenAI's `tools` field, Anthropic's `tools`, or any provider that accepts
|
|
12
|
+
* that shape.
|
|
13
|
+
* - `executeToolCall` — the executor. Hand to AI SDK's `onToolCall`, or call
|
|
14
|
+
* yourself when you wire up tool calls manually.
|
|
15
|
+
* - `getContext` — snapshot of `{selection, currentPage, paragraphCount}` for
|
|
16
|
+
* system-prompt injection. Pass through `prepareRequestBody` (AI SDK) or
|
|
17
|
+
* inline into your own request body so the agent always knows what the
|
|
18
|
+
* user is looking at without an extra tool round-trip.
|
|
19
|
+
*
|
|
20
|
+
* Custom tools merge with the built-ins via the `tools` option. Names collide
|
|
21
|
+
* → consumer wins (your override replaces the built-in by name).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const { tools, executeToolCall, getContext } = useDocxAgentTools({
|
|
26
|
+
* editorRef,
|
|
27
|
+
* author: 'Assistant',
|
|
28
|
+
* tools: {
|
|
29
|
+
* fetch_clause: {
|
|
30
|
+
* name: 'fetch_clause',
|
|
31
|
+
* description: 'Fetch a clause template by name.',
|
|
32
|
+
* inputSchema: { type: 'object', properties: { name: { type: 'string' } } },
|
|
33
|
+
* handler: async (input) => ({ success: true, data: await fetchTemplate(input.name) }),
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
interface UseDocxAgentToolsOptions {
|
|
41
|
+
/** Reference to the DocxEditor (must match EditorRefLike). */
|
|
42
|
+
editorRef: React.RefObject<EditorRefLike | null>;
|
|
43
|
+
/** Default author name for comments / tracked changes. Default: 'AI'. */
|
|
44
|
+
author?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Optional consumer-defined tools to merge with the built-ins. Keyed by
|
|
47
|
+
* tool name. A tool with the same name as a built-in **replaces** it.
|
|
48
|
+
* Pass a stable reference (memoized or module-level) to avoid rebuilding
|
|
49
|
+
* the tool list on every render.
|
|
50
|
+
*/
|
|
51
|
+
tools?: Record<string, AgentToolDefinition<any>>;
|
|
52
|
+
/**
|
|
53
|
+
* Allow-list of built-in tool names to expose. When provided, only the
|
|
54
|
+
* named tools are returned (custom tools from `tools` always pass).
|
|
55
|
+
* Useful for read-only or scope-restricted agents:
|
|
56
|
+
*
|
|
57
|
+
* @example include: ['read_document', 'find_text', 'add_comment']
|
|
58
|
+
*/
|
|
59
|
+
include?: readonly string[];
|
|
60
|
+
/**
|
|
61
|
+
* Block-list of built-in tool names to hide. Applied after `include`.
|
|
62
|
+
* Use for agents that should not write tracked changes:
|
|
63
|
+
*
|
|
64
|
+
* @example exclude: ['suggest_change', 'apply_formatting', 'set_paragraph_style']
|
|
65
|
+
*/
|
|
66
|
+
exclude?: readonly string[];
|
|
67
|
+
}
|
|
68
|
+
interface UseDocxAgentToolsReturn {
|
|
69
|
+
/** Tool schemas in OpenAI function calling format — pass to your AI provider. */
|
|
70
|
+
tools: ReturnType<typeof getToolSchemas>;
|
|
71
|
+
/** Execute a tool call by name. Pass to AI SDK's `onToolCall`. */
|
|
72
|
+
executeToolCall: (name: string, args: Record<string, unknown>) => AgentToolResult;
|
|
73
|
+
/** Snapshot of the user's current view for system-prompt injection. */
|
|
74
|
+
getContext: () => AgentContextSnapshot;
|
|
75
|
+
}
|
|
76
|
+
declare function useDocxAgentTools(options: UseDocxAgentToolsOptions): UseDocxAgentToolsReturn;
|
|
77
|
+
|
|
78
|
+
export { AgentContextSnapshot, AgentToolDefinition, AgentToolResult, EditorRefLike, type UseDocxAgentToolsOptions, type UseDocxAgentToolsReturn, useDocxAgentTools };
|
package/dist/react.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { E as EditorRefLike, A as AgentToolDefinition, g as getToolSchemas, a as AgentToolResult, b as AgentContextSnapshot } from './server-B7dGWiLh.js';
|
|
2
|
+
export { U as UseAgentChatOptions, c as UseAgentChatReturn, d as getToolDisplayName, u as useAgentChat } from './server-B7dGWiLh.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* useDocxAgentTools — wires the toolkit to a live DocxEditor for BYO chat
|
|
6
|
+
* frameworks.
|
|
7
|
+
*
|
|
8
|
+
* Returns three things consumers need to plug an agent into the editor:
|
|
9
|
+
*
|
|
10
|
+
* - `tools` — schemas in OpenAI function-calling format. Pass to `streamText({ tools })`,
|
|
11
|
+
* OpenAI's `tools` field, Anthropic's `tools`, or any provider that accepts
|
|
12
|
+
* that shape.
|
|
13
|
+
* - `executeToolCall` — the executor. Hand to AI SDK's `onToolCall`, or call
|
|
14
|
+
* yourself when you wire up tool calls manually.
|
|
15
|
+
* - `getContext` — snapshot of `{selection, currentPage, paragraphCount}` for
|
|
16
|
+
* system-prompt injection. Pass through `prepareRequestBody` (AI SDK) or
|
|
17
|
+
* inline into your own request body so the agent always knows what the
|
|
18
|
+
* user is looking at without an extra tool round-trip.
|
|
19
|
+
*
|
|
20
|
+
* Custom tools merge with the built-ins via the `tools` option. Names collide
|
|
21
|
+
* → consumer wins (your override replaces the built-in by name).
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```tsx
|
|
25
|
+
* const { tools, executeToolCall, getContext } = useDocxAgentTools({
|
|
26
|
+
* editorRef,
|
|
27
|
+
* author: 'Assistant',
|
|
28
|
+
* tools: {
|
|
29
|
+
* fetch_clause: {
|
|
30
|
+
* name: 'fetch_clause',
|
|
31
|
+
* description: 'Fetch a clause template by name.',
|
|
32
|
+
* inputSchema: { type: 'object', properties: { name: { type: 'string' } } },
|
|
33
|
+
* handler: async (input) => ({ success: true, data: await fetchTemplate(input.name) }),
|
|
34
|
+
* },
|
|
35
|
+
* },
|
|
36
|
+
* });
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
interface UseDocxAgentToolsOptions {
|
|
41
|
+
/** Reference to the DocxEditor (must match EditorRefLike). */
|
|
42
|
+
editorRef: React.RefObject<EditorRefLike | null>;
|
|
43
|
+
/** Default author name for comments / tracked changes. Default: 'AI'. */
|
|
44
|
+
author?: string;
|
|
45
|
+
/**
|
|
46
|
+
* Optional consumer-defined tools to merge with the built-ins. Keyed by
|
|
47
|
+
* tool name. A tool with the same name as a built-in **replaces** it.
|
|
48
|
+
* Pass a stable reference (memoized or module-level) to avoid rebuilding
|
|
49
|
+
* the tool list on every render.
|
|
50
|
+
*/
|
|
51
|
+
tools?: Record<string, AgentToolDefinition<any>>;
|
|
52
|
+
/**
|
|
53
|
+
* Allow-list of built-in tool names to expose. When provided, only the
|
|
54
|
+
* named tools are returned (custom tools from `tools` always pass).
|
|
55
|
+
* Useful for read-only or scope-restricted agents:
|
|
56
|
+
*
|
|
57
|
+
* @example include: ['read_document', 'find_text', 'add_comment']
|
|
58
|
+
*/
|
|
59
|
+
include?: readonly string[];
|
|
60
|
+
/**
|
|
61
|
+
* Block-list of built-in tool names to hide. Applied after `include`.
|
|
62
|
+
* Use for agents that should not write tracked changes:
|
|
63
|
+
*
|
|
64
|
+
* @example exclude: ['suggest_change', 'apply_formatting', 'set_paragraph_style']
|
|
65
|
+
*/
|
|
66
|
+
exclude?: readonly string[];
|
|
67
|
+
}
|
|
68
|
+
interface UseDocxAgentToolsReturn {
|
|
69
|
+
/** Tool schemas in OpenAI function calling format — pass to your AI provider. */
|
|
70
|
+
tools: ReturnType<typeof getToolSchemas>;
|
|
71
|
+
/** Execute a tool call by name. Pass to AI SDK's `onToolCall`. */
|
|
72
|
+
executeToolCall: (name: string, args: Record<string, unknown>) => AgentToolResult;
|
|
73
|
+
/** Snapshot of the user's current view for system-prompt injection. */
|
|
74
|
+
getContext: () => AgentContextSnapshot;
|
|
75
|
+
}
|
|
76
|
+
declare function useDocxAgentTools(options: UseDocxAgentToolsOptions): UseDocxAgentToolsReturn;
|
|
77
|
+
|
|
78
|
+
export { AgentContextSnapshot, AgentToolDefinition, AgentToolResult, EditorRefLike, type UseDocxAgentToolsOptions, type UseDocxAgentToolsReturn, useDocxAgentTools };
|
package/dist/react.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1 @@
|
|
|
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};
|