botdocs 0.4.0 → 0.6.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.
Files changed (36) hide show
  1. package/README.md +21 -2
  2. package/dist/src/builder/chunker.d.ts +18 -0
  3. package/dist/src/builder/chunker.js +62 -1
  4. package/dist/src/builder/embedder.js +4 -1
  5. package/dist/src/builder/index-size.d.ts +3 -0
  6. package/dist/src/builder/index-size.js +16 -0
  7. package/dist/src/builder/index.js +16 -3
  8. package/dist/src/builder/paths.d.ts +6 -0
  9. package/dist/src/builder/paths.js +13 -0
  10. package/dist/src/builder/site-generator.d.ts +4 -0
  11. package/dist/src/builder/site-generator.js +63 -11
  12. package/dist/src/builder/template-engine.d.ts +4 -4
  13. package/dist/src/builder/template-engine.js +5 -1
  14. package/dist/src/builder/vector-db-builder.d.ts +1 -0
  15. package/dist/src/builder/vector-db-builder.js +1 -0
  16. package/dist/src/cli/index.js +60 -17
  17. package/dist/src/cli/options.d.ts +2 -0
  18. package/dist/src/cli/options.js +2 -0
  19. package/dist/src/cli/server.d.ts +6 -0
  20. package/dist/src/cli/server.js +79 -0
  21. package/dist/src/cli/watcher.d.ts +7 -0
  22. package/dist/src/cli/watcher.js +40 -0
  23. package/dist/src/shared/site-root.d.ts +2 -0
  24. package/dist/src/shared/site-root.js +9 -0
  25. package/dist/src/types/config.d.ts +3 -0
  26. package/dist/src/types/config.js +2 -0
  27. package/dist/src/types/document.d.ts +1 -1
  28. package/dist-client/assets/chatbox-Dw_HFrfR.js +8 -0
  29. package/dist-client/assets/rag-engine-B9wYRzqT.js +1 -0
  30. package/dist-client/bundle.js +1 -1
  31. package/man/botdocs.1 +84 -3
  32. package/package.json +10 -1
  33. package/src/styles/chat.css +13 -0
  34. package/src/templates/layout.html +14 -2
  35. package/dist-client/assets/chatbox-P1j6YP1y.js +0 -7
  36. package/dist-client/assets/rag-engine-CU9vjCAg.js +0 -1
@@ -1 +0,0 @@
1
- var t=Object.defineProperty,e=(e,n,o)=>((e,n,o)=>n in e?t(e,n,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[n]=o)(e,"symbol"!=typeof n?n+"":n,o);import{g as n}from"./chatbox-P1j6YP1y.js";import"../bundle.js";function o(t,e){if(t.length!==e.length)throw new Error("Vectors must have the same length");let n=0,o=0,r=0;for(let i=0;i<t.length;i++)n+=t[i]*e[i],o+=t[i]*t[i],r+=e[i]*e[i];return o=Math.sqrt(o),r=Math.sqrt(r),0===o||0===r?0:n/(o*r)}class r{constructor(){e(this,"vectorDB",null),e(this,"isLoading",!1)}async loadVectorDB(){if(!this.vectorDB)if(this.isLoading)for(;this.isLoading;)await new Promise(t=>setTimeout(t,100));else{this.isLoading=!0;try{console.log("Loading vector database...");const t=await fetch("/vector-db.json");this.vectorDB=await t.json(),console.log(`Loaded ${this.vectorDB.chunks.length} chunks`)}finally{this.isLoading=!1}}}async search(t,e=5){this.vectorDB||await this.loadVectorDB();const n=this.vectorDB.chunks.map(e=>({chunk:e,score:o(t,e.embedding)}));return n.sort((t,e)=>e.score-t.score),n.slice(0,e)}isReady(){return null!==this.vectorDB}getInfo(){return this.vectorDB?{chunkCount:this.vectorDB.chunks.length,dimension:this.vectorDB.dimension,model:this.vectorDB.model}:null}}let i=null;function s(){return i||(i=new r),i}function a(t){const e=[],n=t.split("\n");let o=[],r=null;const i=()=>{if(0===o.length)return;const t=o.join(" ").trim();if(o=[],t)for(const n of function(t){const e=[],n=t.replace(/`[^`]*`/g,t=>(e.push(t),`\0${e.length-1}\0`));return(n.match(/[^.!?]+[.!?]*(?:\s+|$)/g)||[n]).map(t=>t.replace(/\0(\d+)\0/g,(t,n)=>e[Number(n)])).map(t=>t.trim()).filter(Boolean)}(t))n&&e.push({text:n,kind:"prose"})};let s=0;for(;s<n.length;){const t=n[s];if(t.trim().startsWith("```")){i(),r=null;const o=[t];for(s++;s<n.length&&!n[s].trim().startsWith("```");)o.push(n[s]),s++;s<n.length&&o.push(n[s]),e.push({text:o.join("\n"),kind:"code"}),s++;continue}if(/^#{1,6}\s+/.test(t.trim()))i(),r=null,s++;else{if(/^\s*([-*+]|\d+\.)\s+/.test(t)){i();const n=t.trim();n&&(e.push({text:n,kind:"list"}),r=e.length-1),s++;continue}""!==t.trim()?null===r?(o.push(t.trim()),s++):(e[r].text+=" "+t.trim(),s++):(i(),r=null,s++)}}return i(),e}let c=!1,l=5;const h=.7;async function u(){return n().isModelCached()}async function d(t){if(!c)try{const e=s();await e.loadVectorDB(),t&&t(5);const o=n();await o.initialize(e=>{t&&t(5+.95*e)}),c=!0,t&&t(100)}catch(e){throw console.error("Search initialization failed:",e),e}}async function m(t,e={}){if(!c)throw new Error("Search system not initialized");const r=e.topK||l;try{const e=n(),i=await e.embed(t),c=s(),l=await c.search(i,r),u=l.slice(0,3),d=await Promise.all(u.map(t=>async function(t,e,n,r=3){const i=t.trim(),s=a(i);if(0===s.length)return{snippet:i,topSegment:i,topScore:0};const c=await n(s.map(t=>t.text)),l=s.map((t,n)=>({...t,index:n,score:o(e,c[n])})).sort((t,e)=>e.score-t.score);return{snippet:l.slice(0,Math.min(r,l.length)).sort((t,e)=>t.index-e.index).map(t=>t.text).join("\n\n"),topSegment:l[0].text,topScore:l[0].score}}(t.chunk.text,i,t=>e.embedBatch(t)))),m=function(t,e,n,o){if(0===e.length)return"I couldn't find anything about that in the documentation. Try rephrasing your question or browse the navigation menu to explore available topics.";const r=/^how (to|do|can)/i.test(t),i=/^what (is|are)/i.test(t),s=/^why/i.test(t);let a="";const c=n.map((t,e)=>({result:t,extract:o[e]})).filter(({result:t,extract:e})=>t.score>h&&e.topScore>h);if(c.length>1){a+="**Quick answer:**\n\n";for(const{result:t,extract:e}of c){const n=f(t.chunk.metadata);a+=`- ${e.topSegment} ([${g(t.chunk.metadata)}](${n}))\n`}a+="\n---\n\n"}r?a+="Here's how you can do that:\n\n":i?a+="Let me explain:\n\n":s?a+="Here's what the docs say about that:\n\n":1===e.length?a+="I found this relevant section:\n\n":a+=`I found ${n.length} relevant sections:\n\n`;if(n.forEach((t,e)=>{const{chunk:n,score:r}=t,i=n.metadata.heading||n.metadata.title,s=f(n.metadata),c=o[e].snippet;e>0&&(a+="\n\n---\n\n"),a+=`**${i}**\n\n`,a+=c,a+=`\n\n→ [View full section](${s})`,r>h&&(a+=" *(highly relevant)*")}),e.length>3){const t=e.length-3;a+=`\n\n---\n\nšŸ’” **Found ${t} more related section${t>1?"s":""}** — check the sources below for more details.`}else 1===e.length&&(a+="\n\n*Have a follow-up question? Just ask!*");return a}(t,l,u,d),p=l.map(t=>({title:g(t.chunk.metadata),url:f(t.chunk.metadata)}));return{answer:m,sources:Array.from(new Map(p.map(t=>[t.url,t])).values())}}catch(i){throw console.error("Search query error:",i),i}}function f(t){let e=t.url;return t.headingId&&(e+=`#${t.headingId}`),e}function g(t){return t.heading?`${t.title} → ${t.heading}`:t.title}function p(){return c}function w(t){l=t}export{d as initializeRAG,u as isModelCached,p as isRAGReady,m as queryRAG,w as setTopK};