@cachly-dev/mcp-server 0.10.279 → 0.10.281
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/dist/src/ambient-cli.js +4 -2
- package/dist/src/cli-argumente.js +1 -1
- package/dist/src/client-kopf.js +1 -0
- package/dist/src/handlers/brain.js +73 -68
- package/dist/src/handlers/share.js +11 -11
- package/dist/src/handlers/team.js +49 -43
- package/dist/src/import-docs.js +11 -0
- package/dist/src/index.js +127 -123
- package/dist/src/rolle.js +12 -0
- package/dist/src/schluessel-klassen.js +1 -0
- package/dist/src/speicher-zugang.js +1 -0
- package/dist/src/suchstatistik.js +1 -1
- package/dist/src/wissenssuche.js +7 -0
- package/glama.json +1 -1
- package/hooks/cachly-ambient-einblendung.mjs +40 -36
- package/package.json +1 -1
- package/server.json +2 -2
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import{createHash as w}from"node:crypto";import{readdir as y,readFile as $,stat as k}from"node:fs/promises";import{join as v,relative as b,resolve as g,sep as S}from"node:path";const x=["node_modules","dist",".git"],K=512*1024;function _(o){return w("sha256").update(o,"utf8").digest("hex")}async function T(o){const t=g(o),i=[],a=[];async function n(c){const s=await y(c,{withFileTypes:!0});for(const u of s){const d=v(c,u.name);if(u.isDirectory()){x.includes(u.name)||await n(d);continue}if(!u.isFile()||!/\.mdx?$/i.test(u.name))continue;const r=b(t,d).split(S).join("/");if((await k(d)).size>K){a.push(r);continue}const e=await $(d,"utf8");i.push({docKey:r,content:e,hash:_(e)})}}return await n(t),i.sort((c,s)=>c.docKey<s.docKey?-1:c.docKey>s.docKey?1:0),a.sort(),{dokumente:i,zuGross:a}}function R(o,t){const i={neu:[],geaendert:[],gleich:[],entfernt:[]},a=new Set;for(const n of o){a.add(n.docKey);const c=t[n.docKey];c===void 0?i.neu.push(n):c!==n.hash?i.geaendert.push(n):i.gleich.push(n)}return i.entfernt=Object.keys(t).filter(n=>!a.has(n)).sort(),i}class p extends Error{status;code;body;constructor(t,i,a,n){super(n),this.status=t,this.code=i,this.body=a}}function E(o,t,i){switch(t){case"not_admin":return"Only the owner of this Brain or an admin of the organisation can import documents.";case"not_found":return"Source not found. Check --source (the ID from the dashboard) and that your key belongs to this team.";case"run_closed":return"This run was closed by a newer run. Start again.";case"knowledge_limit":return`The knowledge limit of this level is reached (${String(i.max??"?")} entries). Withdraw entries or delete a source first.`;case"document_limit":return`A source holds at most ${String(i.max??2e3)} documents.`;case"too_large":return"A document is larger than 512 KB."}if(o===401)return"The API key is not valid. Run: npx @cachly-dev/mcp-server@latest autopilot";const a=typeof i.error=="string"?i.error:`HTTP ${o}`;return t?`${a} (${t})`:a}async function G(o){const t=o.log??(s=>console.log(s)),i=o.fetchImpl??fetch,a=`${o.apiUrl.replace(/\/+$/,"")}/api/v1/knowledge/sources/${encodeURIComponent(o.source)}`,n={exitCode:0,dryRun:!!o.dryRun,dokumente:{neu:0,geaendert:0,gleich:0,entfernt:0},uploads:0,schreibendeAufrufe:0,zuGross:[],abgeschnitten:0};async function c(s,u,d){s!=="GET"&&n.schreibendeAufrufe++;const r=await i(`${a}${u}`,{method:s,headers:{Authorization:`Bearer ${o.apiKey}`,"Content-Type":"application/json"},body:d===void 0?void 0:JSON.stringify(d),signal:AbortSignal.timeout(6e4)});let h={};try{h=await r.json()}catch{}if(!r.ok){const e=typeof h.code=="string"?h.code:"";throw new p(r.status,e,h,E(r.status,e,h))}return h}try{const s=await T(o.dir);n.zuGross=s.zuGross;for(const e of s.zuGross)t(` skipped (over 512 KB): ${e}`);if(s.dokumente.length===0&&s.zuGross.length===0)return t(`
|
|
2
|
+
No .md or .mdx files found in ${g(o.dir)}.
|
|
3
|
+
`),n.exitCode=1,n;let u="",d;if(o.dryRun)d=(await c("GET","/known")).known??{};else{const e=await c("POST","/runs");u=String(e.run_id??""),d=e.known??{}}const r=R(s.dokumente,d);if(n.dokumente={neu:r.neu.length,geaendert:r.geaendert.length,gleich:r.gleich.length,entfernt:r.entfernt.length},o.dryRun){for(const e of r.neu)t(` new ${e.docKey}`);for(const e of r.geaendert)t(` changed ${e.docKey}`);for(const e of r.entfernt)t(` removed ${e}`);return t(`
|
|
4
|
+
Dry run, nothing was written: ${l(n.dokumente)}
|
|
5
|
+
`),n}for(const e of[...r.neu,...r.geaendert]){const f=await c("PUT",`/runs/${encodeURIComponent(u)}/documents`,{doc_key:e.docKey,format:"markdown",content:e.content});n.uploads++;const m=Number(f.truncated??0);m>0&&(n.abgeschnitten+=m,t(` warning: ${e.docKey} has more than 200 sections, ${m} were left out`)),t(` ${r.neu.includes(e)?"new ":"changed"} ${e.docKey} (${String(f.sections??0)} sections)`)}try{const e=await c("POST",`/runs/${encodeURIComponent(u)}/finish`,{seen:r.gleich.map(f=>f.docKey),confirm_removals:!!o.confirmRemovals});n.abschnitte={neu:Number(e.new??0),geaendert:Number(e.changed??0),gleich:Number(e.same??0),entfernt:Number(e.removed??0)}}catch(e){if(e instanceof p&&e.code==="confirm_removals_required")return t(`
|
|
6
|
+
Stopped: this run would withdraw ${String(e.body.count??"?")} of ${String(e.body.active??"?")} active entries (more than ${String(e.body.percent??30)} %).`),t(` Wrong folder? If the removal is intended, run the command again with --confirm-removals.
|
|
7
|
+
`),n.exitCode=1,n;throw e}for(const e of r.entfernt)t(` removed ${e}`);t(`
|
|
8
|
+
Documents: ${l(n.dokumente)}`);const h=n.abschnitte;return t(`Sections: ${l(h)}`),t(`New and changed sections are searchable by meaning within a few minutes; until then the word search finds them.
|
|
9
|
+
`),n}catch(s){return t(`
|
|
10
|
+
\u274C ${s instanceof Error?s.message:String(s)}
|
|
11
|
+
`),n.exitCode=1,n}}function l(o){return`${o.neu} new, ${o.geaendert} changed, ${o.gleich} same, ${o.entfernt} removed`}export{K as MAX_DATEI_BYTES,x as UEBERSPRUNGENE_ORDNER,_ as dokumentHash,G as importiereDokumente,T as sammleDokumente,R as vergleiche};
|