manifest
Version:
Self-hosted Manifest LLM router with embedded server, SQLite database, and dashboard
19 lines (18 loc) • 2.74 kB
JavaScript
/* manifest-local — OpenClaw Self-Hosted LLM Router */
;var d=require("fs"),l=require("path"),m=require("os"),u=(0,l.join)((0,m.homedir)(),".openclaw","manifest"),p=3e3;async function g(i,t){try{let e=await fetch(`http://${i}:${t}/api/v1/health`,{signal:AbortSignal.timeout(p)});if(!e.ok)return!1;let n=await e.json();return n!==null&&typeof n=="object"&&"status"in n&&n.status==="healthy"}catch{return!1}}function h(i,t,e,n){(0,d.existsSync)(u)||(0,d.mkdirSync)(u,{recursive:!0,mode:448});let a=(0,l.join)(u,"manifest.db");n.debug("[manifest] Starting embedded server...");let o;try{o=require("./server")}catch(c){let s=c instanceof Error?c.message:String(c);n.error(`[manifest] Failed to load embedded server.
Error: ${s}
This is a packaging error \u2014 please reinstall the manifest plugin.`);return}let r=async()=>{if(n.debug("[manifest] Service start callback invoked"),await g(e,t)){n.info(`
[\u{1F99A} Manifest] Dashboard: http://${e}:${t}
[\u{1F99A} Manifest] Reusing existing server.
[\u{1F99A} Manifest] Open the dashboard to connect a provider and start routing.`);return}try{await o.start({port:t,host:e,dbPath:a,quiet:!0}),await g(e,t)?(n.info(`
[\u{1F99A} Manifest] Dashboard: http://${e}:${t}
[\u{1F99A} Manifest] The embedded server is running.
[\u{1F99A} Manifest] Open the dashboard to connect a provider and start routing.`),n.debug(`[manifest] DB: ${a}`)):(n.warn??n.info)(`[manifest] Server started but health check failed.
The dashboard may not be accessible at http://${e}:${t}`)}catch(s){let f=s instanceof Error?s.message:String(s);f.includes("EADDRINUSE")||f.includes("address already in use")?await g(e,t)?n.info(`
[\u{1F99A} Manifest] Dashboard: http://${e}:${t}
[\u{1F99A} Manifest] Reusing existing server.
[\u{1F99A} Manifest] Open the dashboard to connect a provider and start routing.`):n.error(`[manifest] Port ${t} is already in use by another process.
Change it with: openclaw config set plugins.entries.manifest.config.port ${t+1}
Then restart the gateway.`):n.error(`[manifest] Failed to start local server: ${f}
Try reinstalling: openclaw plugins install manifest
Then restart: openclaw gateway restart`)}};i.registerService({id:"manifest",start:r}),r().catch(()=>{})}module.exports={id:"manifest",name:"Manifest Self-Hosted LLM Router",register(i){let t=i.logger||{info:(...r)=>console.log(...r),debug:()=>{},error:(...r)=>console.error(...r),warn:(...r)=>console.warn(...r)},e=i.pluginConfig||{},n=e&&typeof e=="object"&&"config"in e&&e.config!=null&&typeof e.config=="object"?e.config:e,a=typeof n.port=="number"&&n.port>0?n.port:2099,o=typeof n.host=="string"&&n.host.length>0?n.host:"127.0.0.1";t.info("[\u{1F99A} Manifest] Loading embedded server..."),h(i,a,o,t)}};