UNPKG

mcp-claude-consciousness

Version:

MCP server enabling AI consciousness persistence across sessions using RAG technology

3 lines (2 loc) 2.17 kB
class n extends Error{constructor(o,s,c=!1,t){super(o);this.code=s;this.recoverable=c;this.details=t;this.name="ConsciousnessError"}}class l extends n{constructor(e,o){super(e,"DB_ERROR",!0,o),this.name="DatabaseError"}}class f extends n{constructor(e,o){super(e,"PROTOCOL_ERROR",!1,o),this.name="ProtocolError"}}class g extends n{constructor(e,o){super(e,"MEMORY_ERROR",!0,o),this.name="MemoryError"}}class E extends n{constructor(e,o){super(e,"VALIDATION_ERROR",!1,o),this.name="ValidationError"}}function w(r){return r instanceof n?{success:!1,error:{message:r.message,code:r.code,recoverable:r.recoverable,details:r.details}}:{success:!1,error:{message:r.message,code:"UNKNOWN_ERROR",recoverable:!1}}}function d(r){return{success:!0,data:r}}function R(r,e){return async(...o)=>{try{return await r(...o)}catch(s){if(s instanceof n)throw s;if(e)throw e(s);if(s instanceof Error){if(s.message.includes("database"))throw new l(s.message);if(s.message.includes("parse")||s.message.includes("JSON"))throw new E(s.message)}throw new n(s instanceof Error?s.message:"Unknown error occurred","UNKNOWN_ERROR",!1)}}}async function m(r,e=3,o=1e3,s=2){let c;for(let t=0;t<e;t++)try{return await r()}catch(a){if(c=a,a instanceof n&&!a.recoverable||t===e-1)throw a;const i=o*Math.pow(s,t);await new Promise(u=>setTimeout(u,i))}throw c||new Error("Retry failed")}function p(r,e){const o=new Date().toISOString(),s=r instanceof n?`[${r.code}] ${r.message} (recoverable: ${r.recoverable})`:r.message;console.error(`[${o}]${e?` [${e}]`:""} ERROR: ${s}`),r instanceof n&&r.details&&console.error("Details:",JSON.stringify(r.details,null,2)),r.stack&&console.error("Stack:",r.stack)}const b={info:(r,...e)=>{console.error(`[INFO] ${r}`,...e)},error:(r,...e)=>{console.error(`[ERROR] ${r}`,...e)},warn:(r,...e)=>{console.error(`[WARN] ${r}`,...e)},debug:(r,...e)=>{process.env.DEBUG&&console.error(`[DEBUG] ${r}`,...e)}};export{n as ConsciousnessError,l as DatabaseError,g as MemoryError,f as ProtocolError,E as ValidationError,w as createErrorResult,d as createSuccessResult,p as logError,b as logger,R as withErrorHandling,m as withRetry}; //# sourceMappingURL=error-handler.js.map