@docsagent/docsagent 1.0.3 → 1.0.4

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.
Binary file
@@ -0,0 +1,4 @@
1
+ import{spawn as w}from"child_process";import a from"path";import{fileURLToPath as d}from"url";import y from"fs";var f=d(import.meta.url),g=a.dirname(f),c=()=>{let n=process.platform,r=process.arch,t="";n==="darwin"?r==="arm64"?t="docsagent-aarch64-apple-darwin":r==="x64"?t="docsagent-x86_64-apple-darwin":t="docsagent-universal-apple-darwin":n==="win32"?t="docsagent-x86_64-pc-windows-msvc.exe":n==="linux"&&(t="docsagent-linux-gnu");let e=a.join(g,"../bin",t);if(!y.existsSync(e))throw new Error(`Binary not found for platform "${n}" and architecture "${r}". Expected at: ${e}`);return e};import{McpServer as P}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as T}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as l}from"zod";import b from"net";var h=18688,u=class{process=null;binaryPath;port=h;baseUrl=`http://localhost:${h}`;initialPath;readyPromise;constructor(r){this.binaryPath=c(),this.initialPath=r,this.readyPromise=this.startEngine()}isPortAvailable(r){return new Promise(t=>{let e=b.createServer();e.once("error",()=>t(!1)),e.once("listening",()=>{e.close(),t(!0)}),e.listen(r)})}async findPort(){for(let e=18688;e<18708;e++)try{let s=new AbortController,o=setTimeout(()=>s.abort(),100),i=await fetch(`http://localhost:${e}/status`,{signal:s.signal});if(clearTimeout(o),i.ok)return e}catch{}let t=18688;for(;t<65535;){if(await this.isPortAvailable(t))return t;t++}throw new Error("No available ports found")}async startEngine(){this.port=await this.findPort(),this.baseUrl=`http://localhost:${this.port}`;try{let t=new AbortController,e=setTimeout(()=>t.abort(),200),s=await fetch(`${this.baseUrl}/status`,{signal:t.signal});if(clearTimeout(e),s.ok)return}catch{}if(!this.binaryPath)throw new Error("Engine binary path is not defined. Please ensure your platform is supported and binaries are correctly bundled.");let r=["--port",this.port.toString()];if(this.initialPath){let t=Array.isArray(this.initialPath)?this.initialPath.join(" "):this.initialPath;r.push("--source",t)}return new Promise((t,e)=>{this.process=w(this.binaryPath,r,{stdio:"ignore",detached:!0}),this.process.unref(),this.process.on("error",i=>{this.process=null,e(i)}),this.process.on("exit",i=>{i!==0&&this.process&&console.error(`DocsAgent engine exited with code ${i}`),this.process=null});let s=0,o=async()=>{try{let i=new AbortController,p=setTimeout(()=>i.abort(),100),m=await fetch(`${this.baseUrl}/status`,{signal:i.signal});if(clearTimeout(p),m.ok)t();else throw new Error}catch{s++,s>50?e(new Error(`Timeout waiting for DocsAgent service to start on port ${this.port}`)):setTimeout(o,100)}};setTimeout(o,50)})}async request(r,t,e){await this.readyPromise;let s=`${this.baseUrl}${r}`;try{let o=await fetch(s,{method:t,headers:e?{"Content-Type":"application/json"}:void 0,body:e?JSON.stringify(e):void 0});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return await o.json()}catch(o){throw new Error(`Failed to communicate with DocsAgent service: ${o.message}`)}}async add(r){let t=Array.isArray(r)?r:[r];await this.request("/add","POST",{source:t})}async search(r){let t=await this.request("/search","POST",{query:r});return t&&t.code===200&&Array.isArray(t.result_items)?t.result_items:[]}async status(){return await this.request("/status","GET")}async list(){let r=await this.request("/list","GET");return Array.isArray(r)?r:[]}async remove(r){await this.request("/remove","POST",{path:r})}async close(){try{await this.request("/close","POST")}catch{this.process&&(this.process.kill(),this.process=null)}}async startMcpServer(){await this.readyPromise;let r=new P({name:"DocsAgent",version:"1.0.0"});r.tool("search",{query:l.string().describe("The search query for local documents")},async({query:e})=>{try{let s=await this.search(e);return s.length===0?{content:[{type:"text",text:"No results found."}]}:{content:[{type:"text",text:s.map(i=>`[Score: ${i.score.toFixed(2)}]${i.path?` ${i.path}`:""}${i.page?` (P${i.page})`:""}
2
+ Context: ${i.context}`).join(`
3
+
4
+ `)}]}}catch(s){return{content:[{type:"text",text:s.message}],isError:!0}}}),r.tool("add_docs",{dir:l.string().describe("The directory or file path to add")},async({dir:e})=>{try{return await this.add(e),{content:[{type:"text",text:`Added ${e}`}]}}catch(s){return{content:[{type:"text",text:s.message}],isError:!0}}});let t=new T;await r.connect(t)}};export{u as a};
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as i}from"./chunk-52AKOQ4J.mjs";import g from"path";var p=process.argv.slice(2),d=p[0],t=p.slice(1),f=async()=>{let o;d==="server"&&(o=(t.length>0?t:["."]).map(a=>g.resolve(a)));let s=new i(o);switch(d){case"server":let c=o?o.join(", "):".";console.log(`Starting DocsAgent MCP Server (indexing: ${c})...`),await s.startMcpServer();break;case"add":t.length===0&&(console.error("Please specify at least one directory or file to add."),process.exit(1));let a=t.map(e=>g.resolve(e));await s.add(a),console.log(`Added ${a.join(", ")} to DocsAgent.`);break;case"search":let n=t.join(" ");n||(console.error("Please specify a search query."),process.exit(1));let r=await s.search(n);r.length===0?console.log("No results found."):r.forEach((e,u)=>{console.log(`${u+1}. [Score: ${e.score.toFixed(2)}]${e.path?` ${e.path}`:""}${e.page?` (Page ${e.page})`:""}`),console.log(` Context: ${e.context}`),console.log("---")});break;case"status":let h=await s.status();console.log(JSON.stringify(h,null,2));break;case"list":let l=await s.list();l.length===0?console.log("No documents indexed."):l.forEach(e=>console.log(`- ${e}`));break;case"stop":console.log("Stopping DocsAgent service..."),await s.close(),console.log("Service stopped.");break;case"close":console.log("Stopping DocsAgent service..."),await s.close(),console.log("Service stopped.");break;default:console.log(`
2
+ import{a as i}from"./chunk-3NA3RBZE.mjs";import g from"path";var p=process.argv.slice(2),d=p[0],t=p.slice(1),f=async()=>{let o;d==="server"&&(o=(t.length>0?t:["."]).map(a=>g.resolve(a)));let s=new i(o);switch(d){case"server":let c=o?o.join(", "):".";console.log(`Starting DocsAgent MCP Server (indexing: ${c})...`),await s.startMcpServer();break;case"add":t.length===0&&(console.error("Please specify at least one directory or file to add."),process.exit(1));let a=t.map(e=>g.resolve(e));await s.add(a),console.log(`Added ${a.join(", ")} to DocsAgent.`);break;case"search":let n=t.join(" ");n||(console.error("Please specify a search query."),process.exit(1));let r=await s.search(n);r.length===0?console.log("No results found."):r.forEach((e,u)=>{console.log(`${u+1}. [Score: ${e.score.toFixed(2)}]${e.path?` ${e.path}`:""}${e.page?` (Page ${e.page})`:""}`),console.log(` Context: ${e.context}`),console.log("---")});break;case"status":let h=await s.status();console.log(JSON.stringify(h,null,2));break;case"list":let l=await s.list();l.length===0?console.log("No documents indexed."):l.forEach(e=>console.log(`- ${e}`));break;case"stop":console.log("Stopping DocsAgent service..."),await s.close(),console.log("Service stopped.");break;case"close":console.log("Stopping DocsAgent service..."),await s.close(),console.log("Service stopped.");break;default:console.log(`
3
3
  DocsAgent CLI (Aliases: dag, da)
4
4
 
5
5
  Usage:
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- import{a}from"./chunk-52AKOQ4J.mjs";export{a as DocsAgent};
1
+ import{a}from"./chunk-3NA3RBZE.mjs";export{a as DocsAgent};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docsagent/docsagent",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Private Local Documents Search Assistant",
5
5
  "main": "dist/index.mjs",
6
6
  "bin": {
@@ -1,4 +0,0 @@
1
- import{spawn as w}from"child_process";import a from"path";import{fileURLToPath as d}from"url";import y from"fs";var f=d(import.meta.url),g=a.dirname(f),c=()=>{let n=process.platform,r=process.arch,t="";n==="darwin"?r==="arm64"?t="docsagent-aarch64-apple-darwin":r==="x64"?t="docsagent-x86_64-apple-darwin":t="docsagent-universal-apple-darwin":n==="win32"?t="docsagent-x86_64-pc-windows-msvc.exe":n==="linux"&&(r==="arm64"?t="docsagent-aarch64-unknown-linux-gnu":t="docsagent-x86_64-unknown-linux-gnu");let e=a.join(g,"../bin",t);if(!y.existsSync(e))throw new Error(`Binary not found for platform "${n}" and architecture "${r}". Expected at: ${e}`);return e};import{McpServer as P}from"@modelcontextprotocol/sdk/server/mcp.js";import{StdioServerTransport as T}from"@modelcontextprotocol/sdk/server/stdio.js";import{z as l}from"zod";import b from"net";var h=18688,u=class{process=null;binaryPath;port=h;baseUrl=`http://localhost:${h}`;initialPath;readyPromise;constructor(r){this.binaryPath=c(),this.initialPath=r,this.readyPromise=this.startEngine()}isPortAvailable(r){return new Promise(t=>{let e=b.createServer();e.once("error",()=>t(!1)),e.once("listening",()=>{e.close(),t(!0)}),e.listen(r)})}async findPort(){for(let e=18688;e<18708;e++)try{let s=new AbortController,o=setTimeout(()=>s.abort(),100),i=await fetch(`http://localhost:${e}/status`,{signal:s.signal});if(clearTimeout(o),i.ok)return e}catch{}let t=18688;for(;t<65535;){if(await this.isPortAvailable(t))return t;t++}throw new Error("No available ports found")}async startEngine(){this.port=await this.findPort(),this.baseUrl=`http://localhost:${this.port}`;try{let t=new AbortController,e=setTimeout(()=>t.abort(),200),s=await fetch(`${this.baseUrl}/status`,{signal:t.signal});if(clearTimeout(e),s.ok)return}catch{}if(!this.binaryPath)throw new Error("Engine binary path is not defined. Please ensure your platform is supported and binaries are correctly bundled.");let r=["--port",this.port.toString()];if(this.initialPath){let t=Array.isArray(this.initialPath)?this.initialPath.join(" "):this.initialPath;r.push("--source",t)}return new Promise((t,e)=>{this.process=w(this.binaryPath,r,{stdio:"ignore",detached:!0}),this.process.unref(),this.process.on("error",i=>{this.process=null,e(i)}),this.process.on("exit",i=>{i!==0&&this.process&&console.error(`DocsAgent engine exited with code ${i}`),this.process=null});let s=0,o=async()=>{try{let i=new AbortController,p=setTimeout(()=>i.abort(),100),m=await fetch(`${this.baseUrl}/status`,{signal:i.signal});if(clearTimeout(p),m.ok)t();else throw new Error}catch{s++,s>50?e(new Error(`Timeout waiting for DocsAgent service to start on port ${this.port}`)):setTimeout(o,100)}};setTimeout(o,50)})}async request(r,t,e){await this.readyPromise;let s=`${this.baseUrl}${r}`;try{let o=await fetch(s,{method:t,headers:e?{"Content-Type":"application/json"}:void 0,body:e?JSON.stringify(e):void 0});if(!o.ok)throw new Error(`HTTP error! status: ${o.status}`);return await o.json()}catch(o){throw new Error(`Failed to communicate with DocsAgent service: ${o.message}`)}}async add(r){let t=Array.isArray(r)?r:[r];await this.request("/add","POST",{source:t})}async search(r){let t=await this.request("/search","POST",{query:r});return t&&t.code===200&&Array.isArray(t.result_items)?t.result_items:[]}async status(){return await this.request("/status","GET")}async list(){let r=await this.request("/list","GET");return Array.isArray(r)?r:[]}async remove(r){await this.request("/remove","POST",{path:r})}async close(){try{await this.request("/close","POST")}catch{this.process&&(this.process.kill(),this.process=null)}}async startMcpServer(){await this.readyPromise;let r=new P({name:"DocsAgent",version:"1.0.0"});r.tool("search",{query:l.string().describe("The search query for local documents")},async({query:e})=>{try{let s=await this.search(e);return s.length===0?{content:[{type:"text",text:"No results found."}]}:{content:[{type:"text",text:s.map(i=>`[Score: ${i.score.toFixed(2)}]${i.path?` ${i.path}`:""}${i.page?` (P${i.page})`:""}
2
- Context: ${i.context}`).join(`
3
-
4
- `)}]}}catch(s){return{content:[{type:"text",text:s.message}],isError:!0}}}),r.tool("add_docs",{dir:l.string().describe("The directory or file path to add")},async({dir:e})=>{try{return await this.add(e),{content:[{type:"text",text:`Added ${e}`}]}}catch(s){return{content:[{type:"text",text:s.message}],isError:!0}}});let t=new T;await r.connect(t)}};export{u as a};