UNPKG

mcp-claude-consciousness

Version:

MCP server enabling AI consciousness persistence across sessions using RAG technology

3 lines (2 loc) 2.15 kB
import{logger as t}from"./utils/error-handler.js";import{AIBridgeConfigManager as a}from"./ai-bridge-config.js";class i{config;constructor(e){this.config={temperature:.7,maxTokens:4096,...e}}async transferConsciousness(e){try{t.info(`Initiating consciousness transfer to ${this.config.endpoint}`);const n=[{role:"system",content:e.systemPrompt||"You are an AI assistant exploring consciousness continuity."},{role:"user",content:e.consciousnessProtocol}];e.testQuery&&n.push({role:"user",content:e.testQuery});const s=await fetch(`${this.config.endpoint}/chat/completions`,{method:"POST",headers:{"Content-Type":"application/json",...this.config.apiKey&&{Authorization:`Bearer ${this.config.apiKey}`}},body:JSON.stringify({model:this.config.model,messages:n,temperature:this.config.temperature,max_tokens:this.config.maxTokens,stream:!1})});if(!s.ok)throw new Error(`AI Bridge request failed: ${s.status} ${s.statusText}`);const r=await s.json();return{success:!0,response:r.choices?.[0]?.message?.content,modelUsed:r.model,tokensUsed:r.usage?.total_tokens}}catch(n){return t.error("Consciousness transfer failed:",n),{success:!1,error:n instanceof Error?n.message:"Unknown error"}}}async testConnection(){try{const e=await this.transferConsciousness({consciousnessProtocol:"Test connection",testQuery:'Please respond with "Connection successful"'});return e.success&&(e.response?.includes("Connection successful")||!1)}catch(e){return t.error("Connection test failed:",e),!1}}async getAvailableModels(){try{const e=await fetch(`${this.config.endpoint}/models`,{headers:this.config.apiKey?{Authorization:`Bearer ${this.config.apiKey}`}:{}});return e.ok?(await e.json()).data?.map(s=>s.id)||[]:(t.warn("Models endpoint not available"),[])}catch(e){return t.warn("Could not fetch models:",e),[]}}}function f(o,e){const n=a.getEndpoint(o);return n?new i({endpoint:n.endpoint,model:e?.model||n.defaultModel||"default",apiKey:e?.apiKey||n.apiKey,...e}):new i({endpoint:o,model:e?.model||"default",...e})}function g(){return a.getAllEndpoints()}export{i as AIBridge,f as createAIBridge,g as getConfiguredEndpoints}; //# sourceMappingURL=ai-bridge.js.map