wiki-plugin-similarity 0.4.3 → 0.4.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/client/similarity.js +1 -1
- package/package.json +5 -1
- package/server/package.json +3 -0
- package/server/server.js +11 -4
package/client/similarity.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* wiki-plugin-similarity - 0.4.
|
|
1
|
+
/* wiki-plugin-similarity - 0.4.4 - Tue, 07 Jul 2026 19:36:29 GMT */
|
|
2
2
|
(()=>{var F={high:.78,medium:.68,low:.58},O=F.medium,q=10,N=t=>{let e=[],i=null,s=null,o="search",x=!1,y=!1,v=null,b=null,p=(n,c)=>n===c||n.startsWith(c)&&/^[\s:]/.test(n.slice(c.length)),w=(n,c)=>n.slice(c.length).replace(/^\s*:?\s*/,"").trim();for(let n of t.split(`
|
|
3
3
|
`)){let c=n.trim();if(!c||c.startsWith("#"))continue;let h=c.toUpperCase();if(p(h,"LIVE")){x=!0;continue}if(p(h,"AUTHOR")){!e.length&&o==="search"&&(o="author");continue}if(p(h,"REPORT")){o==="search"&&(o="report");continue}if(p(h,"BUILD")){o==="search"&&(o="build");continue}if(p(h,"FORCE")){y=!0;continue}if(p(h,"GHOST")){v=w(c,"GHOST"),o==="search"&&(o="ghost");continue}if(p(h,"BUTTON")){b=w(c,"BUTTON");continue}if(p(h,"LIST")){!e.length&&o==="search"&&(o="list");continue}if(p(h,"SIMILAR")){let k=w(h,"SIMILAR").toLowerCase();i=F[k]||O,!e.length&&o==="search"&&(o="similar");continue}if(p(h,"THRESHOLD")){let k=w(c,"THRESHOLD");i=F[k.toLowerCase()]??(parseFloat(k)||O);continue}if(p(h,"LIMIT")){s=parseInt(w(c,"LIMIT"))||q;continue}e.push(["PUBLIC","LOCAL","PRIVATE"].includes(h)?h:c)}return{mode:o,specs:e,threshold:i??O,limit:s??q,live:x,force:y,ghostUrl:v,label:b,thresholdSet:i!==null}},Y=t=>t.includes("*")||t.includes("?"),Q=t=>t==="PUBLIC"||t==="LOCAL"||t==="PRIVATE",X=t=>t.toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,""),M=new Map,Z=async(t,e)=>{if(M.has(t))return M.get(t);let i=`${e}/system/indexed-domains.json?pattern=${encodeURIComponent(t)}`,s=await fetch(i);if(!s.ok)throw new Error(`indexed-domains failed: ${s.status}`);let o=await s.json();return M.set(t,o),o},B=async(t,e)=>{t.length||(t=[window.location.hostname]);let i=new Set,s=[];for(let o of t)if(o==="*"||Y(o)||Q(o))for(let x of await Z(o,e))i.has(x.domain)||(i.add(x.domain),s.push(x));else i.has(o)||(i.add(o),s.push({domain:o,page_count:null}));return s},U=new Map,tt=t=>`${window.location.origin}/system/semantic-vectors.json?domain=${encodeURIComponent(t)}`,V=async t=>{if(U.has(t))return U.get(t);let e=await fetch(tt(t));if(!e.ok)return[];let i=await e.json();return U.set(t,i),i},H=async(t,e)=>{let i=await fetch(`${e}/system/embed.json?text=${encodeURIComponent(t)}`);if(!i.ok)throw new Error(`embed failed: ${i.status}`);return(await i.json()).vector},et=async(t,e)=>{let s=(await V(e)).find(o=>o.slug===t);return s?s.vector:null},P=(t,e,{threshold:i,limit:s,excludeSlug:o,excludeDomain:x})=>{let y=[];for(let{domain:v,pages:b}of e)for(let{slug:p,title:w,vector:n}of b){if(p===o&&v===x)continue;let c=0;for(let h=0;h<t.length;h++)c+=t[h]*n[h];c>=i&&y.push({domain:v,slug:p,title:w,score:c})}return y.sort((v,b)=>b.score-v.score),y.slice(0,s)},A=async(t,e)=>{let i=await B(t,e);return(await Promise.all(i.map(async({domain:o})=>({domain:o,pages:await V(o)})))).filter(o=>o.pages.length>0)},G=t=>`sim-cache-${t}`,st=t=>{try{let e=JSON.parse(localStorage.getItem(G(t.id))||"null");return e?.text===(t.text||"")?e:null}catch{return null}},I=(t,e)=>{try{localStorage.setItem(G(t.id),JSON.stringify({text:t.text||"",ts:Date.now(),...e}))}catch{}},nt=t=>{let e=Math.floor((Date.now()-t)/1e3);return e<60?`${e}s ago`:e<3600?`${Math.floor(e/60)}m ago`:e<86400?`${Math.floor(e/3600)}h ago`:`${Math.floor(e/86400)}d ago`},j=`
|
|
4
4
|
.sim-form { display:flex; gap:6px; margin-bottom:8px; }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-plugin-similarity",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"description": "Federated Wiki plugin — semantic similarity search across wiki domains using prebuilt vector indexes",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"wiki",
|
|
@@ -26,6 +26,10 @@
|
|
|
26
26
|
"type": "git",
|
|
27
27
|
"url": "git+https://github.com/Hitchhikers-Guide-to-the-Galaxy/wiki-plugin-similarity.git"
|
|
28
28
|
},
|
|
29
|
+
"bugs": {
|
|
30
|
+
"url": "https://github.com/Hitchhikers-Guide-to-the-Galaxy/wiki-plugin-similarity/issues"
|
|
31
|
+
},
|
|
32
|
+
"homepage": "https://github.com/Hitchhikers-Guide-to-the-Galaxy/wiki-plugin-similarity#readme",
|
|
29
33
|
"engines": {
|
|
30
34
|
"node": ">=18.x"
|
|
31
35
|
},
|
package/server/server.js
CHANGED
|
@@ -17,10 +17,15 @@
|
|
|
17
17
|
// Requires the FastAPI server to be running on EMBED_URL (default localhost:8000).
|
|
18
18
|
//
|
|
19
19
|
// Farm root is derived from argv.status which is {farm}/{domain}/status.
|
|
20
|
+
//
|
|
21
|
+
// CommonJS on purpose (see sibling server/package.json): wiki-server's older
|
|
22
|
+
// require() loader throws ERR_REQUIRE_ESM on an ESM server.js and swallows the
|
|
23
|
+
// error, silently dropping these routes. CJS loads under every Node / wiki
|
|
24
|
+
// version, while the plugin's root package stays "type":"module".
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
26
|
+
const fs = require('node:fs')
|
|
27
|
+
const path = require('node:path')
|
|
28
|
+
const http = require('node:http')
|
|
24
29
|
|
|
25
30
|
const EMBED_URL = process.env.WIKI_EMBED_URL || 'http://localhost:8000/embed'
|
|
26
31
|
// Optional additional farm roots to search when a domain's vectors aren't found
|
|
@@ -164,7 +169,7 @@ const postJson = (url, body) =>
|
|
|
164
169
|
|
|
165
170
|
// ── startServer — called by wiki-server/lib/plugins.js ────────────────────────
|
|
166
171
|
|
|
167
|
-
|
|
172
|
+
const startServer = ({ argv, app }) => {
|
|
168
173
|
// Farm root: argv.status = {farm}/{thisDomain}/status → go up two levels
|
|
169
174
|
const farmRoot = path.dirname(path.dirname(argv.status))
|
|
170
175
|
|
|
@@ -237,3 +242,5 @@ export const startServer = ({ argv, app }) => {
|
|
|
237
242
|
|
|
238
243
|
console.log('[wiki-plugin-similarity] routes registered')
|
|
239
244
|
}
|
|
245
|
+
|
|
246
|
+
module.exports = { startServer }
|