@easbot/memory 0.3.16 → 0.3.19
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/README.en.md +200 -19
- package/README.md +210 -25
- package/dist/chunks/chunk-4GSXSIV5.cjs +1 -0
- package/dist/chunks/chunk-5Q6SIVSP.cjs +50 -0
- package/dist/chunks/chunk-6CQMBEIQ.mjs +1 -0
- package/dist/chunks/chunk-746FKSL5.mjs +50 -0
- package/dist/chunks/chunk-ARA4LMAI.mjs +1 -0
- package/dist/chunks/chunk-CN6WBJLX.mjs +60 -0
- package/dist/chunks/chunk-CPRDIUQ4.cjs +1 -0
- package/dist/chunks/chunk-EGWJG65Q.cjs +71 -0
- package/dist/chunks/chunk-HQBRVVXS.mjs +1 -0
- package/dist/chunks/chunk-J5XF2W4Z.cjs +1 -0
- package/dist/chunks/chunk-JDPZ5U53.mjs +71 -0
- package/dist/chunks/chunk-NVGACA7W.cjs +1 -0
- package/dist/chunks/chunk-QHPGDNEG.cjs +1 -0
- package/dist/chunks/{chunk-FNT7WEHL.mjs → chunk-QYBWHFOX.mjs} +1 -1
- package/dist/chunks/chunk-SWYQLQ7Z.mjs +1 -0
- package/dist/chunks/{chunk-YHOJKRHE.mjs → chunk-WDVDYZ25.mjs} +1 -1
- package/dist/chunks/chunk-WQB4D6DZ.cjs +1 -0
- package/dist/chunks/chunk-X66LENNV.cjs +60 -0
- package/dist/chunks/cli-handler-CN4Q7BCY.mjs +1 -0
- package/dist/chunks/cli-handler-IRPYADZF.cjs +1 -0
- package/dist/chunks/{config-M2KZYVRZ.mjs → config-2SQJYVTO.mjs} +1 -1
- package/dist/chunks/{config-BFJFRX2C.cjs → config-RPPQ73HK.cjs} +1 -1
- package/dist/chunks/consolidate-PUOAAQN3.cjs +2 -0
- package/dist/chunks/consolidate-UEYNLKQN.mjs +2 -0
- package/dist/chunks/doctor-KPAZWVVZ.mjs +1 -0
- package/dist/chunks/doctor-U4HOSXGW.cjs +1 -0
- package/dist/chunks/extract-7FFIDVG3.cjs +2 -0
- package/dist/chunks/extract-EOZJMLTP.mjs +2 -0
- package/dist/chunks/forget-5AXV3GHW.mjs +3 -0
- package/dist/chunks/forget-GBMYCUPJ.cjs +3 -0
- package/dist/chunks/graph-KOJYJTA4.cjs +3 -0
- package/dist/chunks/graph-Y6AYRFCN.mjs +3 -0
- package/dist/chunks/init-B24TNUSD.cjs +1 -0
- package/dist/chunks/init-HGEBZTJW.mjs +1 -0
- package/dist/chunks/{interfaces-VBO3Z6QF.mjs → interfaces-LPJU4KS3.mjs} +1 -1
- package/dist/chunks/interfaces-XWE45ENK.cjs +1 -0
- package/dist/chunks/llm-RMPVWEVP.cjs +1 -0
- package/dist/chunks/llm-UHTBU2HA.mjs +1 -0
- package/dist/chunks/mcp-BMAB3TT7.mjs +1 -0
- package/dist/chunks/mcp-BS6XHEBR.cjs +1 -0
- package/dist/chunks/recall-LKETADTB.cjs +2 -0
- package/dist/chunks/recall-UPGGKBNX.mjs +2 -0
- package/dist/chunks/remember-KCQN2UWN.mjs +2 -0
- package/dist/chunks/remember-VZF4O7ZF.cjs +2 -0
- package/dist/chunks/status-2BFVXY5J.cjs +1 -0
- package/dist/chunks/status-HGN2YLKJ.mjs +1 -0
- package/dist/chunks/stdio-server-GABA2MLR.cjs +1 -0
- package/dist/chunks/stdio-server-JPMLMEWY.mjs +1 -0
- package/dist/chunks/sync-7Y2DEDDW.mjs +2 -0
- package/dist/chunks/sync-W5A2O5TS.cjs +2 -0
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +4 -4
- package/dist/index.d.cts +119 -21
- package/dist/index.d.ts +119 -21
- package/dist/index.mjs +4 -4
- package/package.json +10 -9
- package/dist/chunks/chunk-3HTZTI7U.cjs +0 -1
- package/dist/chunks/chunk-5W4K5UKV.mjs +0 -53
- package/dist/chunks/chunk-7XEOH55R.cjs +0 -1
- package/dist/chunks/chunk-BWPPLYIF.cjs +0 -1
- package/dist/chunks/chunk-FEMOFIOS.mjs +0 -1
- package/dist/chunks/chunk-I5YWAJHW.cjs +0 -32
- package/dist/chunks/chunk-JGXW3E73.mjs +0 -59
- package/dist/chunks/chunk-MQ72K25M.cjs +0 -59
- package/dist/chunks/chunk-NJVXQ7TV.cjs +0 -1
- package/dist/chunks/chunk-OWLFPNZG.cjs +0 -1
- package/dist/chunks/chunk-PWLSQFYA.mjs +0 -32
- package/dist/chunks/chunk-Q2MKNRER.cjs +0 -53
- package/dist/chunks/chunk-WQGSYA5D.mjs +0 -1
- package/dist/chunks/chunk-Z3NQERNT.mjs +0 -1
- package/dist/chunks/cli-handler-57MKQCNO.cjs +0 -1
- package/dist/chunks/cli-handler-WW3I2YV4.mjs +0 -1
- package/dist/chunks/consolidate-YQ3H643L.cjs +0 -2
- package/dist/chunks/consolidate-ZCFRYIWV.mjs +0 -2
- package/dist/chunks/doctor-GVSMK4HL.cjs +0 -2
- package/dist/chunks/doctor-SPJ64FW3.mjs +0 -2
- package/dist/chunks/extract-5VSCY754.mjs +0 -2
- package/dist/chunks/extract-E54PPHMQ.cjs +0 -2
- package/dist/chunks/forget-AALO5DL5.mjs +0 -3
- package/dist/chunks/forget-GEAEUNRH.cjs +0 -3
- package/dist/chunks/graph-HSYCZI7R.mjs +0 -3
- package/dist/chunks/graph-QEGKUROQ.cjs +0 -3
- package/dist/chunks/init-2GZLH6RB.cjs +0 -2
- package/dist/chunks/init-U7XRD4MW.mjs +0 -2
- package/dist/chunks/interfaces-KNVKCV3Q.cjs +0 -1
- package/dist/chunks/mcp-WE7TV32J.cjs +0 -1
- package/dist/chunks/mcp-XPTJOCQA.mjs +0 -1
- package/dist/chunks/recall-JI2NYDLH.cjs +0 -2
- package/dist/chunks/recall-M6SAHHZX.mjs +0 -2
- package/dist/chunks/remember-FR5QGXFT.mjs +0 -2
- package/dist/chunks/remember-X33PMYA5.cjs +0 -2
- package/dist/chunks/status-6XW6Q3TT.mjs +0 -2
- package/dist/chunks/status-CPB6XZNU.cjs +0 -2
- package/dist/chunks/stdio-server-5LE3HFKN.mjs +0 -1
- package/dist/chunks/stdio-server-6PUOFDLR.cjs +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
'use strict';var
|
|
2
|
+
'use strict';var chunkNVGACA7W_cjs=require('./chunks/chunk-NVGACA7W.cjs'),fs=require('fs'),path=require('path'),url=require('url'),terminal=require('@easbot/terminal');var E=path.dirname(url.fileURLToPath(chunkNVGACA7W_cjs.b));function A(){try{let t=path.join(E,"..","package.json");return JSON.parse(fs.readFileSync(t,"utf-8")).version??"0.0.0"}catch{return "0.0.0"}}var f=new Set(["DEBUG","INFO","WARN","ERROR"]);function N(t){let n={logLevel:"INFO",printLogs:false,debug:false};for(let i=0;i<t.length;i++){let e=t[i];if(e)if(e==="--cwd"&&i+1<t.length){let o=t[i+1];o&&!o.startsWith("-")&&(n.cwd=o,i++);}else if(e.startsWith("--cwd="))n.cwd=e.slice(6);else if(e==="--config"&&i+1<t.length){let o=t[i+1];o&&!o.startsWith("-")&&(n.configPath=o,i++);}else if(e.startsWith("--config="))n.configPath=e.slice(9);else if(e==="--log-level"&&i+1<t.length){let o=t[i+1];if(o&&!o.startsWith("-")){let r=o.toUpperCase();f.has(r)&&(n.logLevel=r,i++);}}else if(e.startsWith("--log-level=")){let o=e.slice(12).toUpperCase();f.has(o)&&(n.logLevel=o);}else e==="--print-logs"?n.printLogs=true:e==="--debug"&&(n.debug=true);}return n}async function R(){let t=process.argv.slice(2),n=A(),{loadEnv:i}=await import('@easbot/utils');i(),process.env.EASBOT_LANG||(process.env.EASBOT_LANG="en-US");let e=N(t),{Log:o}=await import('@easbot/utils'),{getXdgData:r}=await import('./chunks/interfaces-XWE45ENK.cjs'),h=path.join(r(),"memory","log");if(await o.init({logDir:h,print:e.printLogs,dev:e.debug||false,level:e.logLevel}),t.length===0){let{renderBanner:l}=await import('./chunks/cli-handler-IRPYADZF.cjs');l();return}if(t[0]==="--help"||t[0]==="-h"){let{renderHelp:l}=await import('./chunks/cli-handler-IRPYADZF.cjs');l();return}if(t[0]==="--version"||t[0]==="-v"){terminal.printHuman([terminal.formatInfo(n)]);return}let a=e.cwd??process.cwd(),{handleMemoryCli:m}=await import('./chunks/cli-handler-IRPYADZF.cjs'),{setInstanceAdapter:u}=await import('./chunks/interfaces-XWE45ENK.cjs');u({directory:a,worktree:a});let{Llm:w}=await import('./chunks/llm-RMPVWEVP.cjs'),{bootstrapLlm:L,setAdapterRegistry:b}=await import('@easbot/llm'),{getGlobal:s,getInstance:c}=await import('./chunks/interfaces-XWE45ENK.cjs');b({config:void 0,instance:{getDirectory:()=>c().directory,getWorktree:()=>c().worktree},global:{home:s().Path.home,data:s().Path.data,cache:s().Path.cache,config:s().Path.config,state:s().Path.state,log:s().Path.log,bin:s().Path.bin},installation:{getVersion:()=>n,getChannel:()=>"local",getUserAgent:()=>`easbot-memory/${n}`}}),await L({target:w,cwd:a,subConfigPath:".easbot/memory.json",embedding:true,graph:true});let g=await m(t,{version:n,cwd:a});g.code!==0&&(process.exitCode=g.code);}R().catch(t=>{console.error(t),process.exitCode=1;}).finally(async()=>{try{let{Log:t}=await import('@easbot/utils');await t.close();}catch{}process.exit(process.exitCode??0);});
|
package/dist/cli.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {readFileSync}from'fs';import {dirname,join}from'path';import {fileURLToPath}from'url';import {printHuman,formatInfo}from'@easbot/terminal';var
|
|
2
|
+
import {readFileSync}from'fs';import {dirname,join}from'path';import {fileURLToPath}from'url';import {printHuman,formatInfo}from'@easbot/terminal';var G=dirname(fileURLToPath(import.meta.url));function E(){try{let t=join(G,"..","package.json");return JSON.parse(readFileSync(t,"utf-8")).version??"0.0.0"}catch{return "0.0.0"}}var p=new Set(["DEBUG","INFO","WARN","ERROR"]);function A(t){let n={logLevel:"INFO",printLogs:false,debug:false};for(let i=0;i<t.length;i++){let e=t[i];if(e)if(e==="--cwd"&&i+1<t.length){let o=t[i+1];o&&!o.startsWith("-")&&(n.cwd=o,i++);}else if(e.startsWith("--cwd="))n.cwd=e.slice(6);else if(e==="--config"&&i+1<t.length){let o=t[i+1];o&&!o.startsWith("-")&&(n.configPath=o,i++);}else if(e.startsWith("--config="))n.configPath=e.slice(9);else if(e==="--log-level"&&i+1<t.length){let o=t[i+1];if(o&&!o.startsWith("-")){let r=o.toUpperCase();p.has(r)&&(n.logLevel=r,i++);}}else if(e.startsWith("--log-level=")){let o=e.slice(12).toUpperCase();p.has(o)&&(n.logLevel=o);}else e==="--print-logs"?n.printLogs=true:e==="--debug"&&(n.debug=true);}return n}async function N(){let t=process.argv.slice(2),n=E(),{loadEnv:i}=await import('@easbot/utils');i(),process.env.EASBOT_LANG||(process.env.EASBOT_LANG="en-US");let e=A(t),{Log:o}=await import('@easbot/utils'),{getXdgData:r}=await import('./chunks/interfaces-LPJU4KS3.mjs'),d=join(r(),"memory","log");if(await o.init({logDir:d,print:e.printLogs,dev:e.debug||false,level:e.logLevel}),t.length===0){let{renderBanner:l}=await import('./chunks/cli-handler-CN4Q7BCY.mjs');l();return}if(t[0]==="--help"||t[0]==="-h"){let{renderHelp:l}=await import('./chunks/cli-handler-CN4Q7BCY.mjs');l();return}if(t[0]==="--version"||t[0]==="-v"){printHuman([formatInfo(n)]);return}let a=e.cwd??process.cwd(),{handleMemoryCli:m}=await import('./chunks/cli-handler-CN4Q7BCY.mjs'),{setInstanceAdapter:h}=await import('./chunks/interfaces-LPJU4KS3.mjs');h({directory:a,worktree:a});let{Llm:u}=await import('./chunks/llm-UHTBU2HA.mjs'),{bootstrapLlm:w,setAdapterRegistry:L}=await import('@easbot/llm'),{getGlobal:s,getInstance:c}=await import('./chunks/interfaces-LPJU4KS3.mjs');L({config:void 0,instance:{getDirectory:()=>c().directory,getWorktree:()=>c().worktree},global:{home:s().Path.home,data:s().Path.data,cache:s().Path.cache,config:s().Path.config,state:s().Path.state,log:s().Path.log,bin:s().Path.bin},installation:{getVersion:()=>n,getChannel:()=>"local",getUserAgent:()=>`easbot-memory/${n}`}}),await w({target:u,cwd:a,subConfigPath:".easbot/memory.json",embedding:true,graph:true});let g=await m(t,{version:n,cwd:a});g.code!==0&&(process.exitCode=g.code);}N().catch(t=>{console.error(t),process.exitCode=1;}).finally(async()=>{try{let{Log:t}=await import('@easbot/utils');await t.close();}catch{}process.exit(process.exitCode??0);});
|
package/dist/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';require('./chunks/chunk-URADAZYW.cjs');var chunkQHPGDNEG_cjs=require('./chunks/chunk-QHPGDNEG.cjs'),chunkX66LENNV_cjs=require('./chunks/chunk-X66LENNV.cjs'),chunk5Q6SIVSP_cjs=require('./chunks/chunk-5Q6SIVSP.cjs'),chunkEGWJG65Q_cjs=require('./chunks/chunk-EGWJG65Q.cjs'),chunkCPRDIUQ4_cjs=require('./chunks/chunk-CPRDIUQ4.cjs'),chunkJ5XF2W4Z_cjs=require('./chunks/chunk-J5XF2W4Z.cjs'),chunkNVGACA7W_cjs=require('./chunks/chunk-NVGACA7W.cjs'),types=require('@easbot/types'),d=require('jieba-wasm'),utils=require('@easbot/utils'),crypto=require('crypto');function _interopNamespace(e){if(e&&e.__esModule)return e;var n=Object.create(null);if(e){Object.keys(e).forEach(function(k){if(k!=='default'){var d=Object.getOwnPropertyDescriptor(e,k);Object.defineProperty(n,k,d.get?d:{enumerable:true,get:function(){return e[k]}});}})}n.default=e;return Object.freeze(n)}var d__namespace=/*#__PURE__*/_interopNamespace(d);var Oe=["user_preference","task_context","technical_fact","decision","relationship","reminder","error_pattern","workflow","exploration_finding","experience_summary","tool_usage","skill_creation","test","other"],p=class extends Error{constructor(t,o,n){super(t,{cause:n});chunkNVGACA7W_cjs.a(this,"code",o);chunkNVGACA7W_cjs.a(this,"cause",n);this.name="MemoryError";}},P=class extends p{constructor(r,t){super(r,"MEMORY_VALIDATION_ERROR",t),this.name="MemoryValidationError";}},N=class extends p{constructor(r){super(`Memory not found: ${r}`,"MEMORY_NOT_FOUND"),this.name="MemoryNotFoundError";}},D=class extends p{constructor(r){super(r,"MEMORY_PERMISSION_ERROR"),this.name="MemoryPermissionError";}},T=class extends p{constructor(r,t){super(r,"MEMORY_DATABASE_ERROR",t),this.name="MemoryDatabaseError";}},v=class extends p{constructor(r,t){super(r,"MEMORY_FILE_ERROR",t),this.name="MemoryFileError";}},F=class extends p{constructor(r,t){super(r,"MEMORY_SEARCH_ERROR",t),this.name="MemorySearchError";}},L=class extends p{constructor(r,t){super(r,"MEMORY_EMBEDDING_ERROR",t),this.name="MemoryEmbeddingError";}},me=(a=>(a.VALIDATION_ERROR="MEMORY_VALIDATION_ERROR",a.NOT_FOUND="MEMORY_NOT_FOUND",a.PERMISSION_ERROR="MEMORY_PERMISSION_ERROR",a.DATABASE_ERROR="MEMORY_DATABASE_ERROR",a.FILE_ERROR="MEMORY_FILE_ERROR",a.SEARCH_ERROR="MEMORY_SEARCH_ERROR",a.EMBEDDING_ERROR="MEMORY_EMBEDDING_ERROR",a))(me||{});var s=utils.Log.create({service:"memory.tokenizer"}),l=false,ye=utils.loadTextFile("./assets/jieba_dict.txt",chunkNVGACA7W_cjs.b);async function ve(e){if(!l)try{s.debug("Initializing jieba tokenizer");let r=ye();if(d__namespace.with_dict(r),s.debug("Built-in dictionary loaded"),e?.dictPath&&e.dictPath.length>0)for(let t of e.dictPath)await Re(t);l=!0,s.debug("Jieba tokenizer initialized successfully");}catch(r){s.error("Failed to initialize jieba tokenizer",{error:String(r)}),s.warn("Using fallback tokenization (space-based)");}}async function Re(e){if(!l)throw new Error("Tokenizer not initialized");try{let r=await utils.Filesystem.readText(e);s.debug("Loading custom dictionary",{dictPath:e}),d__namespace.with_dict(r),s.debug("Custom dictionary loaded successfully",{dictPath:e});}catch(r){s.warn("Failed to load custom dictionary",{dictPath:e,error:String(r)});}}function ke(e){if(!l)return e.split(/\s+/).filter(Boolean);try{return d__namespace.cut(e)}catch(r){return s.warn("Tokenization failed, using fallback",{error:String(r)}),e.split(/\s+/).filter(Boolean)}}function xe(e){if(!l)return e.split(/\s+/).filter(Boolean);try{return d__namespace.cut_for_search(e)}catch(r){return s.warn("Tokenization for search failed, using fallback",{error:String(r)}),e.split(/\s+/).filter(Boolean)}}function Fe(e,r,t){if(l)try{d__namespace.add_word(e,r,t),s.debug("Word added to dictionary",{word:e,freq:r,tag:t});}catch(o){s.warn("Failed to add word",{word:e,error:String(o)});}}function Le(){return l}async function $e(){l=false,s.debug("Tokenizer closed");}function je(e){if(!l)return e.split(/\s+/).filter(Boolean).join(" ");try{return ke(e).join(" ")}catch(r){return s.warn("Tokenization failed, using fallback",{error:String(r)}),e.split(/\s+/).filter(Boolean).join(" ")}}function ze(e){if(!l)return e.split(/\s+/).filter(Boolean).join(" ");try{return xe(e).join(" ")}catch(r){return s.warn("Tokenization for search failed, using fallback",{error:String(r)}),e.split(/\s+/).filter(Boolean).join(" ")}}function m(e){let r=chunkCPRDIUQ4_cjs.f().worktree,t=chunkCPRDIUQ4_cjs.j(r);return {agentId:e,isTrustedLocal:true,remote:false,locale:"en-US",dbPath:t,workspaceDir:r,rootDir:r,config:chunk5Q6SIVSP_cjs.w({agentId:e,dbPath:t,workspaceDir:r})}}var $=async e=>{if(!e.agentId?.trim())return {ok:false,error:"session-start: agentId is required in ctx"};let r=e.extras?.topK??5,t=e.extras?.query??"";try{let o=await chunk5Q6SIVSP_cjs.v("recall",{query:t,maxResults:r},m(e.agentId));if(o.hits.length===0)return {ok:!0,injected:"",logLine:"session-start: no facts found for agent; skipping context injection"};let n=o.hits.map(y=>`- [${y.category}/imp=${y.importance}] ${y.snippet.slice(0,200)}`);return {ok:!0,injected:`[memory:session-start recall top-${o.hits.length}]
|
|
2
2
|
${n.join(`
|
|
3
|
-
`)}`,logLine:`session-start: injected ${o.hits.length} facts into context (agent=${e.agentId})`}}catch(o){return {ok:false,error:o instanceof Error?o.message:String(o)}}};var
|
|
3
|
+
`)}`,logLine:`session-start: injected ${o.hits.length} facts into context (agent=${e.agentId})`}}catch(o){return {ok:false,error:o instanceof Error?o.message:String(o)}}};var j=async e=>{if(!e.agentId?.trim())return {ok:false,error:"session-end: agentId is required in ctx"};let r=e.extras?.windowDays??1;try{let t=await chunk5Q6SIVSP_cjs.v("consolidate",{windowDays:r},m(e.agentId));return {ok:!0,logLine:`session-end: total=${t.totalFacts}, deduped=${t.dedupedCount}, archived=${t.archivedCount}, skipped=${t.skippedCount}`}}catch(t){return {ok:false,error:t instanceof Error?t.message:String(t)}}};var z=async e=>{if(!e.agentId?.trim())return {ok:false,error:"pre-compact: agentId is required in ctx"};let t=(e.contextPreview??e.messagePreview??"").slice(0,200).replace(/\s+/g," ").trim(),o=e.extras?.topK??3;if(!t)return {ok:true,injected:"",logLine:"pre-compact: empty contextPreview; skipping recall injection"};try{let n=await chunk5Q6SIVSP_cjs.v("recall",{query:t,maxResults:o,minImportance:5},m(e.agentId));if(n.hits.length===0)return {ok:!0,injected:"",logLine:`pre-compact: no facts matched query for agent=${e.agentId}`};let H=n.hits.map(a=>`- [${a.category}/imp=${a.importance}] ${a.snippet.slice(0,150)}`);return {ok:!0,injected:`[memory:pre-compact recall top-${n.hits.length} (imp>=5)]
|
|
4
4
|
${H.join(`
|
|
5
|
-
`)}`,logLine:`pre-compact: injected ${n.hits.length} facts before compaction`}}catch(n){return {ok:false,error:n instanceof Error?n.message:String(n)}}};var
|
|
6
|
-
`);try{return {ok:!0,logLine:`post-tool-failure: wrote error_pattern fact ${(await
|
|
5
|
+
`)}`,logLine:`pre-compact: injected ${n.hits.length} facts before compaction`}}catch(n){return {ok:false,error:n instanceof Error?n.message:String(n)}}};var Y=async e=>{if(!e.agentId?.trim())return {ok:false,error:"post-tool-failure: agentId is required in ctx"};if(!e.toolName?.trim()||!e.error?.trim())return {ok:false,error:"post-tool-failure: toolName and error are required in ctx"};let r=crypto.createHash("sha256").update(`${e.toolName}:${e.error}`).digest("hex").slice(0,8),t=e.messagePreview?e.messagePreview.slice(0,200).replace(/\s+/g," ").trim():"",o=[`[error_pattern] tool=${e.toolName}`,`[error] ${e.error}`,t?`[preview] ${t}`:"",`[errHash] ${r}`].filter(Boolean).join(`
|
|
6
|
+
`);try{return {ok:!0,logLine:`post-tool-failure: wrote error_pattern fact ${(await chunk5Q6SIVSP_cjs.v("remember",{content:o,category:"error_pattern",importance:6,tags:["post-tool-failure",`tool:${e.toolName}`,`err:${r}`],sessionId:e.sessionId,msgId:e.extras?.msgId},m(e.agentId))).fact.id} (tool=${e.toolName}, errHash=${r})`}}catch(n){return {ok:false,error:n instanceof Error?n.message:String(n)}}};var u=utils.Log.create({service:"memory.hooks"}),g=new Map;function f(e,r){let t={name:e,handler:r,registeredAt:new Date().toISOString()},o=g.get(e);g.set(e,t),o?u.info("Hook overwritten",{name:e,prevRegisteredAt:o.registeredAt,newRegisteredAt:t.registeredAt}):u.info("Hook registered",{name:e,registeredAt:t.registeredAt});}function Ee(e){return g.delete(e)}function be(){return Array.from(g.values()).map(e=>({name:e.name,handler:e.handler,registeredAt:e.registeredAt}))}function Ie(){f("session-start",$),f("session-end",j),f("pre-compact",z),f("post-tool-failure",Y);}function Me(){g.clear(),u.debug("All hooks cleared");}async function _e(e,r){let t=g.get(e);if(!t)return u.debug("dispatchHook: no handler registered; noop",{name:e}),{ok:true,logLine:`hook ${e} not registered; noop`};try{let o=await t.handler(r);return o.ok?o.logLine&&u.debug("dispatchHook: ok",{name:e,logLine:o.logLine}):u.warn("dispatchHook: handler returned failure",{name:e,agentId:r.agentId,error:o.error}),o}catch(o){let n=o instanceof Error?o.message:String(o);return u.warn("dispatchHook: handler threw, caught and converted to failure result",{name:e,agentId:r.agentId,error:n}),{ok:false,error:n}}}Object.defineProperty(exports,"COMMANDS_HELP",{enumerable:true,get:function(){return chunkQHPGDNEG_cjs.a}});Object.defineProperty(exports,"handleMemoryCli",{enumerable:true,get:function(){return chunkQHPGDNEG_cjs.d}});Object.defineProperty(exports,"renderBanner",{enumerable:true,get:function(){return chunkQHPGDNEG_cjs.b}});Object.defineProperty(exports,"renderHelp",{enumerable:true,get:function(){return chunkQHPGDNEG_cjs.c}});Object.defineProperty(exports,"MemoryStdioServer",{enumerable:true,get:function(){return chunkX66LENNV_cjs.b}});Object.defineProperty(exports,"renderOperationMarkdown",{enumerable:true,get:function(){return chunkX66LENNV_cjs.a}});Object.defineProperty(exports,"ALL_OPS",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.u}});Object.defineProperty(exports,"GraphStore",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.a}});Object.defineProperty(exports,"OP_REGISTRY",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.t}});Object.defineProperty(exports,"consolidate",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.n}});Object.defineProperty(exports,"doctor",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.s}});Object.defineProperty(exports,"executeOp",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.v}});Object.defineProperty(exports,"extract",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.m}});Object.defineProperty(exports,"forget",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.l}});Object.defineProperty(exports,"graphQuery",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.p}});Object.defineProperty(exports,"init",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.q}});Object.defineProperty(exports,"recall",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.b}});Object.defineProperty(exports,"remember",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.k}});Object.defineProperty(exports,"status",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.r}});Object.defineProperty(exports,"sync",{enumerable:true,get:function(){return chunk5Q6SIVSP_cjs.o}});Object.defineProperty(exports,"LATEST_SCHEMA_VERSION",{enumerable:true,get:function(){return chunkEGWJG65Q_cjs.a}});Object.defineProperty(exports,"MIGRATIONS",{enumerable:true,get:function(){return chunkEGWJG65Q_cjs.b}});Object.defineProperty(exports,"MemoryDatabaseManager",{enumerable:true,get:function(){return chunkEGWJG65Q_cjs.e}});Object.defineProperty(exports,"readCurrentSchemaVersion",{enumerable:true,get:function(){return chunkEGWJG65Q_cjs.d}});Object.defineProperty(exports,"runMigrations",{enumerable:true,get:function(){return chunkEGWJG65Q_cjs.c}});Object.defineProperty(exports,"getGlobal",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.c}});Object.defineProperty(exports,"getHomeDir",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.g}});Object.defineProperty(exports,"getInstance",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.f}});Object.defineProperty(exports,"getMemoryDbPath",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.j}});Object.defineProperty(exports,"getMemoryDir",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.i}});Object.defineProperty(exports,"getXdgData",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.h}});Object.defineProperty(exports,"resetGlobalAdapter",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.b}});Object.defineProperty(exports,"resetInstanceAdapter",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.e}});Object.defineProperty(exports,"setGlobalAdapter",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.a}});Object.defineProperty(exports,"setInstanceAdapter",{enumerable:true,get:function(){return chunkCPRDIUQ4_cjs.d}});Object.defineProperty(exports,"Llm",{enumerable:true,get:function(){return chunkJ5XF2W4Z_cjs.a}});Object.defineProperty(exports,"GRAPH_ENTITY_TYPE_DEFINITIONS",{enumerable:true,get:function(){return types.GRAPH_ENTITY_TYPE_DEFINITIONS}});Object.defineProperty(exports,"GRAPH_RELATION_TYPE_DEFINITIONS",{enumerable:true,get:function(){return types.GRAPH_RELATION_TYPE_DEFINITIONS}});exports.MEMORY_CATEGORIES=Oe;exports.MemoryDatabaseError=T;exports.MemoryEmbeddingError=L;exports.MemoryError=p;exports.MemoryErrorCode=me;exports.MemoryFileError=v;exports.MemoryNotFoundError=N;exports.MemoryPermissionError=D;exports.MemorySearchError=F;exports.MemoryValidationError=P;exports.addWord=Fe;exports.clearAllHooks=Me;exports.closeTokenizer=$e;exports.dispatchHook=_e;exports.initTokenizer=ve;exports.isInitialized=Le;exports.listHooks=be;exports.loadCustomDict=Re;exports.registerAllDefaultHooks=Ie;exports.registerHook=f;exports.toFtsTokens=je;exports.toFtsTokensForSearch=ze;exports.tokenize=ke;exports.tokenizeForSearch=xe;exports.unregisterHook=Ee;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels, IGlobal, IInstance } from '@easbot/types';
|
|
1
|
+
import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels, KnowledgeDoctorResult, MemoryStatus, IGlobal, IInstance } from '@easbot/types';
|
|
2
2
|
export { GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS } from '@easbot/types';
|
|
3
|
+
import { EmbeddingModel, LanguageModel } from 'ai';
|
|
4
|
+
export { EmbeddingModel, LanguageModel } from 'ai';
|
|
5
|
+
import { ILLMInitConfig, ILLMCapabilities } from '@easbot/llm';
|
|
3
6
|
import { ZodTypeAny } from 'zod';
|
|
4
7
|
import { StdioServerConfig } from '@easbot/mcp';
|
|
5
8
|
import { SyncSqliteConnection } from '@easbot/database';
|
|
6
|
-
export { EmbeddingModel, LanguageModel } from 'ai';
|
|
7
9
|
|
|
8
10
|
type MemoryCategory = 'user_preference' | 'task_context' | 'technical_fact' | 'decision' | 'relationship' | 'reminder' | 'error_pattern' | 'workflow' | 'exploration_finding' | 'experience_summary' | 'tool_usage' | 'skill_creation' | 'test' | 'other';
|
|
9
11
|
declare const MEMORY_CATEGORIES: MemoryCategory[];
|
|
@@ -152,16 +154,43 @@ declare function closeTokenizer(): Promise<void>;
|
|
|
152
154
|
declare function toFtsTokens(text: string): string;
|
|
153
155
|
declare function toFtsTokensForSearch(text: string): string;
|
|
154
156
|
|
|
155
|
-
interface
|
|
157
|
+
interface LlmModels {
|
|
158
|
+
embeddingLlm?: EmbeddingModel;
|
|
159
|
+
graphLlm?: LanguageModel;
|
|
160
|
+
}
|
|
161
|
+
interface LlmInitConfig extends ILLMInitConfig {
|
|
162
|
+
options?: {
|
|
163
|
+
graph?: {
|
|
164
|
+
maxOutputTokens?: number;
|
|
165
|
+
temperature?: number;
|
|
166
|
+
};
|
|
167
|
+
embedding?: {
|
|
168
|
+
maxOutputTokens?: number;
|
|
169
|
+
temperature?: number;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
declare namespace Llm {
|
|
174
|
+
function init(config: ILLMInitConfig): void;
|
|
175
|
+
function isInitialized(): boolean;
|
|
176
|
+
function reset(): void;
|
|
177
|
+
function capabilities(): ILLMCapabilities;
|
|
178
|
+
function getEmbeddingLlm(): EmbeddingModel | undefined;
|
|
179
|
+
function getGraphLlm(): LanguageModel | undefined;
|
|
180
|
+
function embedText(value: string): Promise<Float32Array>;
|
|
181
|
+
function embedTexts(values: string[]): Promise<Float32Array[]>;
|
|
182
|
+
const embed: typeof embedText;
|
|
183
|
+
const embedMany: typeof embedTexts;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface MemoryServiceContext {
|
|
156
187
|
workspaceDir: string;
|
|
157
188
|
rootDir: string;
|
|
158
|
-
}
|
|
159
|
-
interface MemoryServiceContext extends BaseServiceContext {
|
|
160
189
|
dbPath: string;
|
|
161
190
|
locale: 'zh-CN' | 'en-US';
|
|
162
191
|
remote: boolean;
|
|
163
192
|
config?: MemoryKnowledgeConfigWithModels;
|
|
164
|
-
agentId
|
|
193
|
+
agentId?: string;
|
|
165
194
|
}
|
|
166
195
|
type ErrorCode = 'AGENT_ID_REQUIRED' | 'SESSION_ID_REQUIRED' | 'CONTENT_REQUIRED' | 'INTERNAL' | 'NOT_FOUND' | 'AMBIGUOUS' | 'NOT_INDEXED' | 'OPTIONAL_DEP_MISSING' | 'TRUST_DENIED' | 'PATH_TRAVERSAL' | 'CATEGORY_REQUIRED' | 'IMPORTANCE_REQUIRED' | 'TIMERANGE_REQUIRED' | 'INGEST_FAILED' | 'UNSUPPORTED_FORMAT' | 'HAS_REFERENCES' | 'DRY_RUN_NO_DELETE' | 'MAX_DELETE_EXCEEDED' | 'JOB_NOT_FOUND' | 'JOB_TIMEOUT' | 'JOB_FAILED';
|
|
167
196
|
type KGScope = 'agent_only' | 'shared_only' | 'both';
|
|
@@ -204,6 +233,10 @@ interface RememberResult {
|
|
|
204
233
|
filePath: string;
|
|
205
234
|
deduplicated: boolean;
|
|
206
235
|
nodeIds?: number[];
|
|
236
|
+
vectorsWritten: number;
|
|
237
|
+
vectorDims: number;
|
|
238
|
+
entitiesExtracted: number;
|
|
239
|
+
relationsExtracted: number;
|
|
207
240
|
}
|
|
208
241
|
interface ForgetParams {
|
|
209
242
|
factId?: string;
|
|
@@ -276,28 +309,37 @@ interface GraphQueryResult {
|
|
|
276
309
|
durationMs: number;
|
|
277
310
|
}
|
|
278
311
|
type StatusParams = {};
|
|
279
|
-
interface StatusResult {
|
|
280
|
-
dbPath: string;
|
|
281
|
-
workspaceDir: string;
|
|
312
|
+
interface StatusResult extends MemoryStatus {
|
|
282
313
|
factsCount: number;
|
|
283
314
|
nodesCount: number;
|
|
284
315
|
edgesCount: number;
|
|
285
316
|
factsByCategory: Record<MemoryCategory, number>;
|
|
286
317
|
ftsAvailable: boolean;
|
|
287
|
-
vectorEnabled: boolean;
|
|
288
|
-
kgScopeEnabled: boolean;
|
|
289
|
-
healthy: boolean;
|
|
290
|
-
meta: Record<string, string>;
|
|
291
318
|
}
|
|
292
319
|
type DoctorParams = {};
|
|
293
|
-
interface DoctorResult {
|
|
294
|
-
|
|
295
|
-
checks: Array<{
|
|
320
|
+
interface DoctorResult extends KnowledgeDoctorResult {
|
|
321
|
+
legacyChecks: Array<{
|
|
296
322
|
name: string;
|
|
297
323
|
passed: boolean;
|
|
298
324
|
message: string;
|
|
299
325
|
details?: Record<string, unknown>;
|
|
326
|
+
severity?: 'error' | 'info' | 'warn' | 'ok';
|
|
300
327
|
}>;
|
|
328
|
+
integrityStats?: {
|
|
329
|
+
memory_facts: number;
|
|
330
|
+
memory_vectors: number;
|
|
331
|
+
embedding_cache: number;
|
|
332
|
+
memory_facts_fts: number;
|
|
333
|
+
nodes: number;
|
|
334
|
+
edges: number;
|
|
335
|
+
meta: number;
|
|
336
|
+
schema_migrations: number;
|
|
337
|
+
};
|
|
338
|
+
backendAvailable?: {
|
|
339
|
+
'better-sqlite3': boolean;
|
|
340
|
+
'node:sqlite': boolean;
|
|
341
|
+
'@tursodatabase/database': boolean;
|
|
342
|
+
};
|
|
301
343
|
}
|
|
302
344
|
interface InitParams {
|
|
303
345
|
dbPath?: string;
|
|
@@ -308,10 +350,33 @@ interface InitParams {
|
|
|
308
350
|
interface InitResult {
|
|
309
351
|
initialized: boolean;
|
|
310
352
|
dbPath: string;
|
|
353
|
+
configPath: string;
|
|
354
|
+
schemaVersion: number;
|
|
311
355
|
workspaceDir: string;
|
|
312
356
|
tablesCreated: number;
|
|
313
357
|
migrationsApplied: number;
|
|
314
358
|
durationMs: number;
|
|
359
|
+
configCreated: boolean;
|
|
360
|
+
}
|
|
361
|
+
interface SyncParams {
|
|
362
|
+
windowDays?: number;
|
|
363
|
+
dryRun?: boolean;
|
|
364
|
+
}
|
|
365
|
+
interface SyncResult {
|
|
366
|
+
generatedCount: number;
|
|
367
|
+
skippedCount: number;
|
|
368
|
+
failedGenerateCount: number;
|
|
369
|
+
archivedCount: number;
|
|
370
|
+
archiveThreshold: string;
|
|
371
|
+
archivedRecords: Array<{
|
|
372
|
+
source: string;
|
|
373
|
+
target: string;
|
|
374
|
+
firstCreatedAt: string;
|
|
375
|
+
firstFactId: string;
|
|
376
|
+
}>;
|
|
377
|
+
windowDays: number;
|
|
378
|
+
dryRun: boolean;
|
|
379
|
+
durationMs: number;
|
|
315
380
|
}
|
|
316
381
|
|
|
317
382
|
declare function recall(ctx: MemoryServiceContext, params: RecallParams): Promise<RecallResult>;
|
|
@@ -324,11 +389,21 @@ declare function extract(ctx: MemoryServiceContext, params: ExtractParams): Prom
|
|
|
324
389
|
|
|
325
390
|
declare function consolidate(ctx: MemoryServiceContext, params?: ConsolidateParams): Promise<ConsolidateResult>;
|
|
326
391
|
|
|
392
|
+
declare function sync(ctx: MemoryServiceContext, params?: SyncParams): Promise<SyncResult>;
|
|
393
|
+
|
|
327
394
|
declare function graphQuery(ctx: MemoryServiceContext, params: GraphQueryParams): Promise<GraphQueryResult>;
|
|
328
395
|
|
|
329
|
-
|
|
396
|
+
interface StatusOptions {
|
|
397
|
+
skipEmbeddingProbe?: boolean;
|
|
398
|
+
skipLlm?: boolean;
|
|
399
|
+
}
|
|
400
|
+
declare function status(ctx: MemoryServiceContext, _params?: StatusParams, options?: StatusOptions): Promise<StatusResult>;
|
|
330
401
|
|
|
331
|
-
|
|
402
|
+
interface DoctorOptions {
|
|
403
|
+
skipEmbeddingProbe?: boolean;
|
|
404
|
+
skipLlm?: boolean;
|
|
405
|
+
}
|
|
406
|
+
declare function doctor(ctx: MemoryServiceContext, _params?: DoctorParams, options?: DoctorOptions): Promise<DoctorResult>;
|
|
332
407
|
|
|
333
408
|
declare function init(ctx: MemoryServiceContext, params?: InitParams): Promise<InitResult>;
|
|
334
409
|
|
|
@@ -432,10 +507,13 @@ declare function getInstance(): IInstance;
|
|
|
432
507
|
declare function getHomeDir(): string;
|
|
433
508
|
declare function getXdgData(): string;
|
|
434
509
|
declare function getMemoryDir(): string;
|
|
435
|
-
declare function getMemoryDbPath(
|
|
510
|
+
declare function getMemoryDbPath(input?: string | {
|
|
511
|
+
dir?: string;
|
|
512
|
+
workspaceDir?: string;
|
|
513
|
+
}): string;
|
|
436
514
|
|
|
437
515
|
type MigrationDb = SyncSqliteConnection;
|
|
438
|
-
declare const LATEST_SCHEMA_VERSION =
|
|
516
|
+
declare const LATEST_SCHEMA_VERSION = 1;
|
|
439
517
|
interface SchemaMigration {
|
|
440
518
|
id: number;
|
|
441
519
|
description: string;
|
|
@@ -471,6 +549,10 @@ declare class MemoryDatabaseManager {
|
|
|
471
549
|
private applyPragmas;
|
|
472
550
|
private runAllMigrations;
|
|
473
551
|
query<T>(sql: string, params?: unknown[]): T[];
|
|
552
|
+
agentFilter(agentId: string | null | undefined): {
|
|
553
|
+
where: string;
|
|
554
|
+
params: string[];
|
|
555
|
+
};
|
|
474
556
|
run(sql: string, params?: unknown[]): {
|
|
475
557
|
lastID: number;
|
|
476
558
|
changes: number;
|
|
@@ -483,6 +565,22 @@ declare class MemoryDatabaseManager {
|
|
|
483
565
|
getSchemaVersion(): number;
|
|
484
566
|
close(): void;
|
|
485
567
|
healthCheck(): boolean;
|
|
568
|
+
checkIntegrity(): {
|
|
569
|
+
issues: Array<{
|
|
570
|
+
severity: 'error' | 'warn' | 'info';
|
|
571
|
+
message: string;
|
|
572
|
+
}>;
|
|
573
|
+
stats: {
|
|
574
|
+
memory_facts: number;
|
|
575
|
+
memory_vectors: number;
|
|
576
|
+
embedding_cache: number;
|
|
577
|
+
memory_facts_fts: number;
|
|
578
|
+
nodes: number;
|
|
579
|
+
edges: number;
|
|
580
|
+
meta: number;
|
|
581
|
+
schema_migrations: number;
|
|
582
|
+
};
|
|
583
|
+
};
|
|
486
584
|
getMeta(key: string): string | null;
|
|
487
585
|
setMeta(key: string, value: string): void;
|
|
488
586
|
}
|
|
@@ -532,4 +630,4 @@ declare function registerAllDefaultHooks(): void;
|
|
|
532
630
|
declare function clearAllHooks(): void;
|
|
533
631
|
declare function dispatchHook(name: HookName, ctx: HookContext): Promise<HookResult>;
|
|
534
632
|
|
|
535
|
-
export { ALL_OPS, type ArchiveRecord, type ArchiveResult, COMMANDS_HELP, type CommandHelp, type ConsolidateParams, type ConsolidateResult, type DoctorResult, type EdgeQueryFilter, type ErrorCode, type ExtractParams, type ExtractResult, type ForgetParams, type ForgetResult, type GraphQueryParams, type GraphQueryResult, GraphStore, type HookContext, type HookHandler, type HookName, type HookResult, type InitParams, type InitResult, type KGScope, LATEST_SCHEMA_VERSION, MEMORY_CATEGORIES, MIGRATIONS, type MemoryCategory, type MemoryCliDeps, type MemoryCliResult, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, type MemoryOp, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemoryStdioServer, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, OP_REGISTRY, type OpAnnotations, type OpHandlerContext, type OpScope, type RecallParams, type RecallResult, type RegisteredHook, type RememberParams, type RememberResult, type StatusResult, addWord, clearAllHooks, closeTokenizer, consolidate, dispatchHook, doctor, executeOp, extract, forget, getGlobal, getHomeDir, getInstance, getMemoryDbPath, getMemoryDir, getXdgData, graphQuery, handleMemoryCli, init, initTokenizer, isInitialized, listHooks, loadCustomDict, readCurrentSchemaVersion, recall, registerAllDefaultHooks, registerHook, remember, renderBanner, renderHelp, renderOperationMarkdown, resetGlobalAdapter, resetInstanceAdapter, runMigrations, setGlobalAdapter, setInstanceAdapter, status, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch, unregisterHook };
|
|
633
|
+
export { ALL_OPS, type ArchiveRecord, type ArchiveResult, COMMANDS_HELP, type CommandHelp, type ConsolidateParams, type ConsolidateResult, type DoctorResult, type EdgeQueryFilter, type ErrorCode, type ExtractParams, type ExtractResult, type ForgetParams, type ForgetResult, type GraphQueryParams, type GraphQueryResult, GraphStore, type HookContext, type HookHandler, type HookName, type HookResult, type InitParams, type InitResult, type KGScope, LATEST_SCHEMA_VERSION, Llm, type LlmInitConfig, type LlmModels, MEMORY_CATEGORIES, MIGRATIONS, type MemoryCategory, type MemoryCliDeps, type MemoryCliResult, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, type MemoryOp, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemoryStdioServer, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, OP_REGISTRY, type OpAnnotations, type OpHandlerContext, type OpScope, type RecallParams, type RecallResult, type RegisteredHook, type RememberParams, type RememberResult, type StatusResult, type SyncParams, type SyncResult, addWord, clearAllHooks, closeTokenizer, consolidate, dispatchHook, doctor, executeOp, extract, forget, getGlobal, getHomeDir, getInstance, getMemoryDbPath, getMemoryDir, getXdgData, graphQuery, handleMemoryCli, init, initTokenizer, isInitialized, listHooks, loadCustomDict, readCurrentSchemaVersion, recall, registerAllDefaultHooks, registerHook, remember, renderBanner, renderHelp, renderOperationMarkdown, resetGlobalAdapter, resetInstanceAdapter, runMigrations, setGlobalAdapter, setInstanceAdapter, status, sync, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch, unregisterHook };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels, IGlobal, IInstance } from '@easbot/types';
|
|
1
|
+
import { KnowledgeSearchOptions, MemoryKnowledgeConfigWithModels, KnowledgeDoctorResult, MemoryStatus, IGlobal, IInstance } from '@easbot/types';
|
|
2
2
|
export { GRAPH_ENTITY_TYPE_DEFINITIONS, GRAPH_RELATION_TYPE_DEFINITIONS } from '@easbot/types';
|
|
3
|
+
import { EmbeddingModel, LanguageModel } from 'ai';
|
|
4
|
+
export { EmbeddingModel, LanguageModel } from 'ai';
|
|
5
|
+
import { ILLMInitConfig, ILLMCapabilities } from '@easbot/llm';
|
|
3
6
|
import { ZodTypeAny } from 'zod';
|
|
4
7
|
import { StdioServerConfig } from '@easbot/mcp';
|
|
5
8
|
import { SyncSqliteConnection } from '@easbot/database';
|
|
6
|
-
export { EmbeddingModel, LanguageModel } from 'ai';
|
|
7
9
|
|
|
8
10
|
type MemoryCategory = 'user_preference' | 'task_context' | 'technical_fact' | 'decision' | 'relationship' | 'reminder' | 'error_pattern' | 'workflow' | 'exploration_finding' | 'experience_summary' | 'tool_usage' | 'skill_creation' | 'test' | 'other';
|
|
9
11
|
declare const MEMORY_CATEGORIES: MemoryCategory[];
|
|
@@ -152,16 +154,43 @@ declare function closeTokenizer(): Promise<void>;
|
|
|
152
154
|
declare function toFtsTokens(text: string): string;
|
|
153
155
|
declare function toFtsTokensForSearch(text: string): string;
|
|
154
156
|
|
|
155
|
-
interface
|
|
157
|
+
interface LlmModels {
|
|
158
|
+
embeddingLlm?: EmbeddingModel;
|
|
159
|
+
graphLlm?: LanguageModel;
|
|
160
|
+
}
|
|
161
|
+
interface LlmInitConfig extends ILLMInitConfig {
|
|
162
|
+
options?: {
|
|
163
|
+
graph?: {
|
|
164
|
+
maxOutputTokens?: number;
|
|
165
|
+
temperature?: number;
|
|
166
|
+
};
|
|
167
|
+
embedding?: {
|
|
168
|
+
maxOutputTokens?: number;
|
|
169
|
+
temperature?: number;
|
|
170
|
+
};
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
declare namespace Llm {
|
|
174
|
+
function init(config: ILLMInitConfig): void;
|
|
175
|
+
function isInitialized(): boolean;
|
|
176
|
+
function reset(): void;
|
|
177
|
+
function capabilities(): ILLMCapabilities;
|
|
178
|
+
function getEmbeddingLlm(): EmbeddingModel | undefined;
|
|
179
|
+
function getGraphLlm(): LanguageModel | undefined;
|
|
180
|
+
function embedText(value: string): Promise<Float32Array>;
|
|
181
|
+
function embedTexts(values: string[]): Promise<Float32Array[]>;
|
|
182
|
+
const embed: typeof embedText;
|
|
183
|
+
const embedMany: typeof embedTexts;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
interface MemoryServiceContext {
|
|
156
187
|
workspaceDir: string;
|
|
157
188
|
rootDir: string;
|
|
158
|
-
}
|
|
159
|
-
interface MemoryServiceContext extends BaseServiceContext {
|
|
160
189
|
dbPath: string;
|
|
161
190
|
locale: 'zh-CN' | 'en-US';
|
|
162
191
|
remote: boolean;
|
|
163
192
|
config?: MemoryKnowledgeConfigWithModels;
|
|
164
|
-
agentId
|
|
193
|
+
agentId?: string;
|
|
165
194
|
}
|
|
166
195
|
type ErrorCode = 'AGENT_ID_REQUIRED' | 'SESSION_ID_REQUIRED' | 'CONTENT_REQUIRED' | 'INTERNAL' | 'NOT_FOUND' | 'AMBIGUOUS' | 'NOT_INDEXED' | 'OPTIONAL_DEP_MISSING' | 'TRUST_DENIED' | 'PATH_TRAVERSAL' | 'CATEGORY_REQUIRED' | 'IMPORTANCE_REQUIRED' | 'TIMERANGE_REQUIRED' | 'INGEST_FAILED' | 'UNSUPPORTED_FORMAT' | 'HAS_REFERENCES' | 'DRY_RUN_NO_DELETE' | 'MAX_DELETE_EXCEEDED' | 'JOB_NOT_FOUND' | 'JOB_TIMEOUT' | 'JOB_FAILED';
|
|
167
196
|
type KGScope = 'agent_only' | 'shared_only' | 'both';
|
|
@@ -204,6 +233,10 @@ interface RememberResult {
|
|
|
204
233
|
filePath: string;
|
|
205
234
|
deduplicated: boolean;
|
|
206
235
|
nodeIds?: number[];
|
|
236
|
+
vectorsWritten: number;
|
|
237
|
+
vectorDims: number;
|
|
238
|
+
entitiesExtracted: number;
|
|
239
|
+
relationsExtracted: number;
|
|
207
240
|
}
|
|
208
241
|
interface ForgetParams {
|
|
209
242
|
factId?: string;
|
|
@@ -276,28 +309,37 @@ interface GraphQueryResult {
|
|
|
276
309
|
durationMs: number;
|
|
277
310
|
}
|
|
278
311
|
type StatusParams = {};
|
|
279
|
-
interface StatusResult {
|
|
280
|
-
dbPath: string;
|
|
281
|
-
workspaceDir: string;
|
|
312
|
+
interface StatusResult extends MemoryStatus {
|
|
282
313
|
factsCount: number;
|
|
283
314
|
nodesCount: number;
|
|
284
315
|
edgesCount: number;
|
|
285
316
|
factsByCategory: Record<MemoryCategory, number>;
|
|
286
317
|
ftsAvailable: boolean;
|
|
287
|
-
vectorEnabled: boolean;
|
|
288
|
-
kgScopeEnabled: boolean;
|
|
289
|
-
healthy: boolean;
|
|
290
|
-
meta: Record<string, string>;
|
|
291
318
|
}
|
|
292
319
|
type DoctorParams = {};
|
|
293
|
-
interface DoctorResult {
|
|
294
|
-
|
|
295
|
-
checks: Array<{
|
|
320
|
+
interface DoctorResult extends KnowledgeDoctorResult {
|
|
321
|
+
legacyChecks: Array<{
|
|
296
322
|
name: string;
|
|
297
323
|
passed: boolean;
|
|
298
324
|
message: string;
|
|
299
325
|
details?: Record<string, unknown>;
|
|
326
|
+
severity?: 'error' | 'info' | 'warn' | 'ok';
|
|
300
327
|
}>;
|
|
328
|
+
integrityStats?: {
|
|
329
|
+
memory_facts: number;
|
|
330
|
+
memory_vectors: number;
|
|
331
|
+
embedding_cache: number;
|
|
332
|
+
memory_facts_fts: number;
|
|
333
|
+
nodes: number;
|
|
334
|
+
edges: number;
|
|
335
|
+
meta: number;
|
|
336
|
+
schema_migrations: number;
|
|
337
|
+
};
|
|
338
|
+
backendAvailable?: {
|
|
339
|
+
'better-sqlite3': boolean;
|
|
340
|
+
'node:sqlite': boolean;
|
|
341
|
+
'@tursodatabase/database': boolean;
|
|
342
|
+
};
|
|
301
343
|
}
|
|
302
344
|
interface InitParams {
|
|
303
345
|
dbPath?: string;
|
|
@@ -308,10 +350,33 @@ interface InitParams {
|
|
|
308
350
|
interface InitResult {
|
|
309
351
|
initialized: boolean;
|
|
310
352
|
dbPath: string;
|
|
353
|
+
configPath: string;
|
|
354
|
+
schemaVersion: number;
|
|
311
355
|
workspaceDir: string;
|
|
312
356
|
tablesCreated: number;
|
|
313
357
|
migrationsApplied: number;
|
|
314
358
|
durationMs: number;
|
|
359
|
+
configCreated: boolean;
|
|
360
|
+
}
|
|
361
|
+
interface SyncParams {
|
|
362
|
+
windowDays?: number;
|
|
363
|
+
dryRun?: boolean;
|
|
364
|
+
}
|
|
365
|
+
interface SyncResult {
|
|
366
|
+
generatedCount: number;
|
|
367
|
+
skippedCount: number;
|
|
368
|
+
failedGenerateCount: number;
|
|
369
|
+
archivedCount: number;
|
|
370
|
+
archiveThreshold: string;
|
|
371
|
+
archivedRecords: Array<{
|
|
372
|
+
source: string;
|
|
373
|
+
target: string;
|
|
374
|
+
firstCreatedAt: string;
|
|
375
|
+
firstFactId: string;
|
|
376
|
+
}>;
|
|
377
|
+
windowDays: number;
|
|
378
|
+
dryRun: boolean;
|
|
379
|
+
durationMs: number;
|
|
315
380
|
}
|
|
316
381
|
|
|
317
382
|
declare function recall(ctx: MemoryServiceContext, params: RecallParams): Promise<RecallResult>;
|
|
@@ -324,11 +389,21 @@ declare function extract(ctx: MemoryServiceContext, params: ExtractParams): Prom
|
|
|
324
389
|
|
|
325
390
|
declare function consolidate(ctx: MemoryServiceContext, params?: ConsolidateParams): Promise<ConsolidateResult>;
|
|
326
391
|
|
|
392
|
+
declare function sync(ctx: MemoryServiceContext, params?: SyncParams): Promise<SyncResult>;
|
|
393
|
+
|
|
327
394
|
declare function graphQuery(ctx: MemoryServiceContext, params: GraphQueryParams): Promise<GraphQueryResult>;
|
|
328
395
|
|
|
329
|
-
|
|
396
|
+
interface StatusOptions {
|
|
397
|
+
skipEmbeddingProbe?: boolean;
|
|
398
|
+
skipLlm?: boolean;
|
|
399
|
+
}
|
|
400
|
+
declare function status(ctx: MemoryServiceContext, _params?: StatusParams, options?: StatusOptions): Promise<StatusResult>;
|
|
330
401
|
|
|
331
|
-
|
|
402
|
+
interface DoctorOptions {
|
|
403
|
+
skipEmbeddingProbe?: boolean;
|
|
404
|
+
skipLlm?: boolean;
|
|
405
|
+
}
|
|
406
|
+
declare function doctor(ctx: MemoryServiceContext, _params?: DoctorParams, options?: DoctorOptions): Promise<DoctorResult>;
|
|
332
407
|
|
|
333
408
|
declare function init(ctx: MemoryServiceContext, params?: InitParams): Promise<InitResult>;
|
|
334
409
|
|
|
@@ -432,10 +507,13 @@ declare function getInstance(): IInstance;
|
|
|
432
507
|
declare function getHomeDir(): string;
|
|
433
508
|
declare function getXdgData(): string;
|
|
434
509
|
declare function getMemoryDir(): string;
|
|
435
|
-
declare function getMemoryDbPath(
|
|
510
|
+
declare function getMemoryDbPath(input?: string | {
|
|
511
|
+
dir?: string;
|
|
512
|
+
workspaceDir?: string;
|
|
513
|
+
}): string;
|
|
436
514
|
|
|
437
515
|
type MigrationDb = SyncSqliteConnection;
|
|
438
|
-
declare const LATEST_SCHEMA_VERSION =
|
|
516
|
+
declare const LATEST_SCHEMA_VERSION = 1;
|
|
439
517
|
interface SchemaMigration {
|
|
440
518
|
id: number;
|
|
441
519
|
description: string;
|
|
@@ -471,6 +549,10 @@ declare class MemoryDatabaseManager {
|
|
|
471
549
|
private applyPragmas;
|
|
472
550
|
private runAllMigrations;
|
|
473
551
|
query<T>(sql: string, params?: unknown[]): T[];
|
|
552
|
+
agentFilter(agentId: string | null | undefined): {
|
|
553
|
+
where: string;
|
|
554
|
+
params: string[];
|
|
555
|
+
};
|
|
474
556
|
run(sql: string, params?: unknown[]): {
|
|
475
557
|
lastID: number;
|
|
476
558
|
changes: number;
|
|
@@ -483,6 +565,22 @@ declare class MemoryDatabaseManager {
|
|
|
483
565
|
getSchemaVersion(): number;
|
|
484
566
|
close(): void;
|
|
485
567
|
healthCheck(): boolean;
|
|
568
|
+
checkIntegrity(): {
|
|
569
|
+
issues: Array<{
|
|
570
|
+
severity: 'error' | 'warn' | 'info';
|
|
571
|
+
message: string;
|
|
572
|
+
}>;
|
|
573
|
+
stats: {
|
|
574
|
+
memory_facts: number;
|
|
575
|
+
memory_vectors: number;
|
|
576
|
+
embedding_cache: number;
|
|
577
|
+
memory_facts_fts: number;
|
|
578
|
+
nodes: number;
|
|
579
|
+
edges: number;
|
|
580
|
+
meta: number;
|
|
581
|
+
schema_migrations: number;
|
|
582
|
+
};
|
|
583
|
+
};
|
|
486
584
|
getMeta(key: string): string | null;
|
|
487
585
|
setMeta(key: string, value: string): void;
|
|
488
586
|
}
|
|
@@ -532,4 +630,4 @@ declare function registerAllDefaultHooks(): void;
|
|
|
532
630
|
declare function clearAllHooks(): void;
|
|
533
631
|
declare function dispatchHook(name: HookName, ctx: HookContext): Promise<HookResult>;
|
|
534
632
|
|
|
535
|
-
export { ALL_OPS, type ArchiveRecord, type ArchiveResult, COMMANDS_HELP, type CommandHelp, type ConsolidateParams, type ConsolidateResult, type DoctorResult, type EdgeQueryFilter, type ErrorCode, type ExtractParams, type ExtractResult, type ForgetParams, type ForgetResult, type GraphQueryParams, type GraphQueryResult, GraphStore, type HookContext, type HookHandler, type HookName, type HookResult, type InitParams, type InitResult, type KGScope, LATEST_SCHEMA_VERSION, MEMORY_CATEGORIES, MIGRATIONS, type MemoryCategory, type MemoryCliDeps, type MemoryCliResult, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, type MemoryOp, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemoryStdioServer, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, OP_REGISTRY, type OpAnnotations, type OpHandlerContext, type OpScope, type RecallParams, type RecallResult, type RegisteredHook, type RememberParams, type RememberResult, type StatusResult, addWord, clearAllHooks, closeTokenizer, consolidate, dispatchHook, doctor, executeOp, extract, forget, getGlobal, getHomeDir, getInstance, getMemoryDbPath, getMemoryDir, getXdgData, graphQuery, handleMemoryCli, init, initTokenizer, isInitialized, listHooks, loadCustomDict, readCurrentSchemaVersion, recall, registerAllDefaultHooks, registerHook, remember, renderBanner, renderHelp, renderOperationMarkdown, resetGlobalAdapter, resetInstanceAdapter, runMigrations, setGlobalAdapter, setInstanceAdapter, status, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch, unregisterHook };
|
|
633
|
+
export { ALL_OPS, type ArchiveRecord, type ArchiveResult, COMMANDS_HELP, type CommandHelp, type ConsolidateParams, type ConsolidateResult, type DoctorResult, type EdgeQueryFilter, type ErrorCode, type ExtractParams, type ExtractResult, type ForgetParams, type ForgetResult, type GraphQueryParams, type GraphQueryResult, GraphStore, type HookContext, type HookHandler, type HookName, type HookResult, type InitParams, type InitResult, type KGScope, LATEST_SCHEMA_VERSION, Llm, type LlmInitConfig, type LlmModels, MEMORY_CATEGORIES, MIGRATIONS, type MemoryCategory, type MemoryCliDeps, type MemoryCliResult, MemoryDatabaseError, MemoryDatabaseManager, type MemoryEdge, MemoryEmbeddingError, MemoryError, MemoryErrorCode, type MemoryFact, MemoryFileError, type MemoryNode, type MemoryNodeWithEdges, MemoryNotFoundError, type MemoryOp, MemoryPermissionError, type MemoryQuery, type MemoryRecallResult, MemorySearchError, type MemorySource, MemoryStdioServer, type MemorySystemConfig, MemoryValidationError, type MemoryVector, type NodeQueryFilter, OP_REGISTRY, type OpAnnotations, type OpHandlerContext, type OpScope, type RecallParams, type RecallResult, type RegisteredHook, type RememberParams, type RememberResult, type StatusResult, type SyncParams, type SyncResult, addWord, clearAllHooks, closeTokenizer, consolidate, dispatchHook, doctor, executeOp, extract, forget, getGlobal, getHomeDir, getInstance, getMemoryDbPath, getMemoryDir, getXdgData, graphQuery, handleMemoryCli, init, initTokenizer, isInitialized, listHooks, loadCustomDict, readCurrentSchemaVersion, recall, registerAllDefaultHooks, registerHook, remember, renderBanner, renderHelp, renderOperationMarkdown, resetGlobalAdapter, resetInstanceAdapter, runMigrations, setGlobalAdapter, setInstanceAdapter, status, sync, toFtsTokens, toFtsTokensForSearch, tokenize, tokenizeForSearch, unregisterHook };
|