@docsagent/docsagent 1.0.2 → 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.
- package/bin/docsagent-linux-gnu +0 -0
- package/dist/chunk-3NA3RBZE.mjs +4 -0
- package/dist/cli.mjs +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +3 -2
- package/scripts/install.mjs +83 -0
- package/dist/chunk-52AKOQ4J.mjs +0 -4
|
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-
|
|
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-
|
|
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
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Private Local Documents Search Assistant",
|
|
5
5
|
"main": "dist/index.mjs",
|
|
6
6
|
"bin": {
|
|
@@ -10,7 +10,8 @@
|
|
|
10
10
|
},
|
|
11
11
|
"files": [
|
|
12
12
|
"dist",
|
|
13
|
-
"bin"
|
|
13
|
+
"bin",
|
|
14
|
+
"scripts"
|
|
14
15
|
],
|
|
15
16
|
"scripts": {
|
|
16
17
|
"build": "tsup src/index.ts src/cli.ts --format esm --tsconfig tsconfig.json --clean --minify",
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = path.dirname(__filename);
|
|
7
|
+
|
|
8
|
+
const getBinaryInfo = () => {
|
|
9
|
+
const platform = process.platform;
|
|
10
|
+
const arch = process.arch;
|
|
11
|
+
|
|
12
|
+
let binaryName = "";
|
|
13
|
+
let libs = [];
|
|
14
|
+
|
|
15
|
+
if (platform === "darwin") {
|
|
16
|
+
libs = ["libawadb.dylib", "libomp.dylib", "libpdfium.dylib"];
|
|
17
|
+
if (arch === "arm64") {
|
|
18
|
+
binaryName = "docsagent-aarch64-apple-darwin";
|
|
19
|
+
} else if (arch === "x64") {
|
|
20
|
+
binaryName = "docsagent-x86_64-apple-darwin";
|
|
21
|
+
} else {
|
|
22
|
+
binaryName = "docsagent-universal-apple-darwin";
|
|
23
|
+
}
|
|
24
|
+
} else if (platform === "win32") {
|
|
25
|
+
binaryName = "docsagent-x86_64-pc-windows-msvc.exe";
|
|
26
|
+
libs = [
|
|
27
|
+
"libawadb.dll",
|
|
28
|
+
"libcrypto-3-x64.dll",
|
|
29
|
+
"libssl-3-x64.dll",
|
|
30
|
+
"libwinpthread-1.dll",
|
|
31
|
+
"pdfium.dll",
|
|
32
|
+
];
|
|
33
|
+
} else if (platform === "linux") {
|
|
34
|
+
if (arch === "arm64") {
|
|
35
|
+
binaryName = "docsagent-aarch64-unknown-linux-gnu";
|
|
36
|
+
} else {
|
|
37
|
+
binaryName = "docsagent-x86_64-unknown-linux-gnu";
|
|
38
|
+
}
|
|
39
|
+
libs = ["libawadb.so", "libpdfium.so"];
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return { binaryName, libs };
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
async function install() {
|
|
46
|
+
const binDir = path.join(__dirname, "../bin");
|
|
47
|
+
const { binaryName, libs } = getBinaryInfo();
|
|
48
|
+
|
|
49
|
+
if (!binaryName) {
|
|
50
|
+
console.error(`Unsupported platform: ${process.platform} ${process.arch}`);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const mainBinaryPath = path.join(binDir, binaryName);
|
|
55
|
+
|
|
56
|
+
if (!fs.existsSync(mainBinaryPath)) {
|
|
57
|
+
console.warn(`Warning: Main binary not found at ${mainBinaryPath}.
|
|
58
|
+
This might happen during local development if you haven't built or placed the binaries yet.`);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
// Set executable permissions for the main binary
|
|
64
|
+
if (process.platform !== "win32") {
|
|
65
|
+
fs.chmodSync(mainBinaryPath, 0o755);
|
|
66
|
+
console.log(`Set executable permissions for ${binaryName}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Verify libraries exist
|
|
70
|
+
for (const lib of libs) {
|
|
71
|
+
const libPath = path.join(binDir, lib);
|
|
72
|
+
if (!fs.existsSync(libPath)) {
|
|
73
|
+
console.warn(`Warning: Library ${lib} not found at ${libPath}.`);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
console.log("DocsAgent binaries verified and configured successfully.");
|
|
78
|
+
} catch (err) {
|
|
79
|
+
console.error(`Post-install configuration failed: ${err.message}`);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
install();
|
package/dist/chunk-52AKOQ4J.mjs
DELETED
|
@@ -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};
|