@chatpanel/gateway 0.85.5 → 0.86.0
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.md +10 -0
- package/package.json +2 -2
- package/src/runtime.js +5 -5
- package/src/update.js +6 -2
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -76,6 +76,16 @@ Windows:** stop the running gateway first, or npm fails with `EBUSY` on `onnxrun
|
|
|
76
76
|
(a loaded DLL cannot be overwritten) —
|
|
77
77
|
`chatpanel-gateway --stop; npm i -g @chatpanel/gateway --ignore-scripts; chatpanel-gateway --install`.
|
|
78
78
|
|
|
79
|
+
**On a company network.** The gateway is on the public npm registry. If `~/.npmrc` points npm at
|
|
80
|
+
a company mirror, the install can be slow, a version behind, or refused — name the registry on the
|
|
81
|
+
command: `npm i -g @chatpanel/gateway@latest --registry=https://registry.npmjs.org --ignore-scripts`.
|
|
82
|
+
If npm answers `UNABLE_TO_VERIFY_LEAF_SIGNATURE` or `SELF_SIGNED_CERT_IN_CHAIN`, a proxy is
|
|
83
|
+
re-signing HTTPS with a certificate Node does not know: prefix the command with
|
|
84
|
+
`NODE_OPTIONS=--use-system-ca` (Node 22.15+ — it then trusts what this computer trusts), or give
|
|
85
|
+
npm the company's certificate (`npm config set cafile /path/to/company-ca.pem`), or use the
|
|
86
|
+
standalone binary above. Do not set `strict-ssl=false`. The in-app Update does the first of these
|
|
87
|
+
by itself, and when an update fails it says which of these it was and the command to run.
|
|
88
|
+
|
|
79
89
|
**Why `--ignore-scripts`.** The gateway itself has no install script, and the two in its tree — both
|
|
80
90
|
under `@huggingface/transformers`, the native model runtime — are ones it needs nothing from:
|
|
81
91
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"description": "Local privacy gateway — redacts PII out of OpenAI/Anthropic API traffic before it reaches a model, then restores it in the reply. Point opencode, codex, aider, Claude Code, etc. at it.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@anthropic-ai/sandbox-runtime": "^0.0.77",
|
|
26
26
|
"@chatpanel/bridge": "^0.44.2",
|
|
27
|
-
"@chatpanel/events": "^0.
|
|
27
|
+
"@chatpanel/events": "^0.354.0",
|
|
28
28
|
"@chatpanel/pii": "^0.15.0",
|
|
29
29
|
"@huggingface/transformers": "^4.2.0",
|
|
30
30
|
"defuddle": "^0.19.4",
|
package/src/runtime.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import{promisify as Rn}from"node:util";import{execFile as In}from"node:child_process";import{existsSync as Ee,mkdirSync as ne,writeFileSync as oe,accessSync as Un,openSync as Fn,closeSync as Hn,constants as Dn}from"node:fs";import{randomBytes as jn,createHash as Xn}from"node:crypto";import Q from"node:os";import v from"node:path";import{modelsFor as Ze,isValidModelId as Wn,catalogFor as se,vllmTaskOf as te}from"./runtime-models.js";import{pickInferenceEngine as en,pickLlamaEngine as Jn,pickMlxEngine as zn,pickAppleEngine as Kn,recommendEngine as Qn,detectAccelerator as Vn,hostShape as qn}from"./inference-engines.js";import{tuningArgs as le,tuningRows as nn,patchTunings as Yn,profilesFor as tn,resolveTunings as rn,ENGINE_DOCS as Zn}from"./engine-tunings.js";import{IMAGE_RECIPES as et}from"./images.js";import{pullRepo as nt,pullGguf as tt,repoInstalled as rt,ggufInstalled as an}from"./model-pull.js";import{liveFit as it,kvCacheMB as at,cachedConfigPath as ot,needMB as st}from"./host-memory.js";import{APPLE_HELPER as Pe,APPLE_MODEL_ID as lt,APPLE_MIN_DARWIN as ut,appleHelperDirs as ct,appleInstallDoor as dt,darwinMajor as on}from"./apple-model.js";import{spawn as mt}from"node:child_process";import{readFileSync as sn,unlinkSync as ln}from"node:fs";const ft=Rn(In),ue=["podman","docker"],V="hf-cache",j=Object.freeze([{id:"searxng",label:"SearXNG",image:"docker.io/searxng/searxng:latest",container:"chatpanel-searxng",port:8888,containerPort:8080,provides:["search"],helper:!0,blurb:"A metasearch engine of your own: the gateway’s web search fans out through it instead of scraping result pages. Loopback only.",caps:["CHOWN","SETGID","SETUID"],answers:async(t,l)=>{try{return(await l(`${t}/search?q=chatpanel&format=json`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.search?.searxng?.url||""),configure:(t,l)=>{t.search=t.search||{},t.search.searxng={...t.search.searxng||{},url:l}},unconfigure:(t,l)=>{t.search?.searxng?.url===l&&(t.search.searxng.url="")}},{id:"reranker",label:"Reranker",image:"ghcr.io/chatpanel/reranker-cpu:latest",container:"chatpanel-reranker",port:8889,containerPort:8e3,provides:["rerank"],helper:!0,adapter:"tei",model:"BAAI/bge-reranker-base",blurb:"Orders sources by relevance — research in plan notes, search results, tool results. The gateway already reranks in-process by default (a small model, no container); start this to run a multilingual cross-encoder (bge-reranker base by default) in a container instead, behind the Text Embeddings Inference wire. Loopback only.",caps:[],volumes:t=>[`${v.join(t,V)}:/data`],env:t=>["HF_HOME=/data",`MODEL_ID=${t.model}`],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.capabilities?.rerank?.url||""),configure:(t,l,f)=>{t.capabilities=t.capabilities||{},t.capabilities.rerank={url:l,adapter:f.adapter,model:f.model,service:f.id}},unconfigure:(t,l)=>{t.capabilities?.rerank?.url===l&&delete t.capabilities.rerank}},{id:"opendecision",label:"OpenDecision",image:"ghcr.io/chatpanel/opendecision-cpu:latest",container:"chatpanel-opendecision",port:8890,containerPort:8e3,provides:["decide"],helper:!0,adapter:"systemone",model:"MoritzLaurer/ModernBERT-base-zeroshot-v2.0",calibrated:!1,blurb:"Typed decisions — sentiment, routing, triage — answered by a zero-shot classifier in one pass, no language model. The gateway already decides in-process by default with the same algorithm and model; start this to run it in a container instead. TypeSafe-shaped (/v1/systemone), Apache-2.0. Loopback only.",caps:[],volumes:t=>[`${v.join(t,V)}:/data`],env:t=>["HF_HOME=/data",`MODEL_ID=${t.model}`],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.capabilities?.decide?.url||""),configure:(t,l,f)=>{t.capabilities=t.capabilities||{},t.capabilities.decide={url:l,adapter:f.adapter,model:f.model,service:f.id,calibrated:f.calibrated}},unconfigure:(t,l)=>{t.capabilities?.decide?.url===l&&delete t.capabilities.decide}},{id:"vllm",label:"vLLM",image:"ghcr.io/chatpanel/vllm-cpu:latest",engineOf:t=>en({...t,containerOnly:!0}),container:"chatpanel-vllm",port:8891,containerPort:8e3,provides:["chat","embed","stt"],adapter:"openai",model:"Qwen/Qwen3-0.6B",pull:!0,blurb:"Your own model, served by vLLM on this machine’s accelerator (CUDA, ROCm, XPU — or CPU): a chat model the router can send turns to, an embedding model for semantic search, or a transcriber for every ear. OpenAI-shaped, loopback only.",caps:[],volumes:t=>[`${v.join(t,V)}:/data`],env:t=>["HF_HOME=/data","VLLM_CPU_KVCACHE_SPACE=4",`MODEL_ID=${t.model}`,...t.installed?["HF_HUB_OFFLINE=1"]:[]],args:(t,l)=>["--model",t.model,"--host","0.0.0.0","--port","8000",...te(t.model)==="embed"?["--task","embed"]:[],...le("vllm",t.tunings,{task:te(t.model),model:t.model,backend:l?.backend||null})],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.capabilities?.embed?.service==="vllm"?t.capabilities.embed.url.replace(/\/v1$/,""):t.capabilities?.stt?.service==="vllm"?t.capabilities.stt.url.replace(/\/v1$/,""):(t.destinations||[]).find(l=>l?.service==="vllm")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{const h=`${l}/v1`,P=te(f.model);un(t),P==="chat"?(t.destinations=(t.destinations||[]).filter(p=>p?.service!=="vllm"&&p?.id!=="vllm"),t.destinations.push({id:"vllm",type:"api",protocol:"openai",baseUrl:h,models:[f.model],service:"vllm"})):P==="embed"?(t.capabilities=t.capabilities||{},t.capabilities.embed={url:h,adapter:"openai",model:f.model,service:"vllm"}):P==="transcription"&&(t.capabilities=t.capabilities||{},t.capabilities.stt={provider:"container",url:h,adapter:"openai",model:f.model,service:"vllm"})},unconfigure:t=>un(t)},{id:"vllm-metal",label:"vLLM (Metal, Apple Silicon)",kind:"native",runner:"vllm",pull:!0,engineOf:t=>en(t),only:{platform:"darwin",arch:"arm64"},port:8892,provides:["chat"],adapter:"openai",model:"mlx-community/Qwen3-1.7B-4bit",blurb:"Your own model on the Apple Silicon GPU, served by vLLM-Metal: a chat model the router can send turns to. A process on this machine behind the gateway, loopback only.",command:(t,l)=>["vllm",["serve",t.model,"--host","127.0.0.1","--port",String(t.port),...le("vllm-metal",t.tunings,l)]],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="vllm-metal")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{t.destinations=(t.destinations||[]).filter(h=>h?.service!=="vllm-metal"&&h?.id!=="vllm-metal"),t.destinations.push({id:"vllm-metal",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[f.model],service:"vllm-metal"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="vllm-metal"&&l?.id!=="vllm-metal"))}},{id:"llama",label:"llama.cpp",kind:"native",runner:"llama-server",pull:!0,engineOf:t=>Jn(t),port:8893,provides:["chat"],adapter:"openai",model:"unsloth/Qwen3-4B-GGUF:Q4_K_M",blurb:"Your own GGUF model on this machine, served by llama.cpp: the Metal GPU on a Mac, CUDA or Vulkan elsewhere, CPU otherwise — a chat model the router can send turns to, with the flags that make it fast set for this machine. A process on this machine behind the gateway, loopback only.",alias:t=>/\.gguf$/i.test(t)?t.split(/[\\/]/).pop().replace(/\.gguf$/i,""):t.split("/").pop().split(":")[0],command:(t,l)=>["llama-server",[...t.file?["-m",t.file]:/\.gguf$/i.test(t.model)?["-m",t.model]:["-hf",t.model],"--host","127.0.0.1","--port",String(t.port),"--alias",t.alias(t.model),"--jinja",...le("llama",t.tunings,l)]],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="llama")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{t.destinations=(t.destinations||[]).filter(h=>h?.service!=="llama"&&h?.id!=="llama"),t.destinations.push({id:"llama",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[f.alias(f.model)],service:"llama"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="llama"&&l?.id!=="llama"))}},{id:"mlx",label:"MLX",kind:"native",runner:"mlx_lm.server",runnerCheck:["--help"],pull:!0,engineOf:t=>zn(t),only:{platform:"darwin",arch:"arm64"},port:8894,provides:["chat"],adapter:"openai",model:"mlx-community/Qwen3-1.7B-4bit",blurb:"Your own model on the Apple Silicon GPU through MLX — Apple’s framework, the lightest way to run a chat model on a Mac. A process on this machine behind the gateway, loopback only.",command:(t,l)=>["mlx_lm.server",["--model",t.model,"--host","127.0.0.1","--port",String(t.port),...le("mlx",t.tunings,l)]],answers:async(t,l)=>{try{return(await l(`${t}/v1/models`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="mlx")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{t.destinations=(t.destinations||[]).filter(h=>h?.service!=="mlx"&&h?.id!=="mlx"),t.destinations.push({id:"mlx",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[f.model],service:"mlx"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="mlx"&&l?.id!=="mlx"))}},{id:"apple",label:"Apple on-device",kind:"native",auto:!0,runner:Pe,engineOf:t=>Kn(t),only:{platform:"darwin",arch:"arm64",minDarwin:ut,label:"macOS 26 or later on Apple Silicon"},port:8895,provides:["chat"],adapter:"openai",window:4096,card:{engine:"apple",backend:"apple",where:"this machine",egress:"none",cost:"free",task:"chat",window:4096,vision:!1,tools:!1,reasoning:!1,label:"Apple on-device",licence:"Apple",draft:!1},blurb:"Apple’s own model, on this Mac (macOS 26 with Apple Intelligence on): the system loads it when asked and frees it when idle, so nothing stays loaded and nothing runs hot — the lightest choice for titles, topics and short answers. Text only, 4,096 tokens at a time. A small helper on this machine behind the gateway, loopback only.",command:t=>[Pe,["serve","--port",String(t.port)]],answers:async(t,l)=>{try{const f=await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)});return f.ok&&(await f.json())?.ok===!0}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="apple")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l)=>{t.destinations=(t.destinations||[]).filter(f=>f?.service!=="apple"&&f?.id!=="apple"),t.destinations.push({id:"apple",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[lt],service:"apple"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="apple"&&l?.id!=="apple"))}}]),re=t=>t.only?.label||`${t.only?.platform||"this platform"} ${t.only?.arch||""}`.trim();function un(t){Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="vllm"&&l?.id!=="vllm")),t.capabilities?.embed?.service==="vllm"&&delete t.capabilities.embed,t.capabilities?.stt?.service==="vllm"&&delete t.capabilities.stt}const x=t=>j.find(l=>l.id===t)||null,pt=({answers:t,configured:l,configure:f,unconfigure:h,volumes:P,args:p,env:U,caps:ce,command:de,engineOf:Ne,alias:N,..._})=>_,ht=Object.freeze(["google","yahoo","yep","duckduckgo","bing","wikipedia"]),gt=Object.freeze(["brave","qwant"]);function kt(t=[]){const l=t.length?t:ht,f=gt.filter(h=>!l.includes(h));return["# Written by chatpanel-gateway (Settings › Runtime). JSON on, the limiter off — the port is","# bound to 127.0.0.1, which is what makes that safe. Do not publish it on 0.0.0.0.","use_default_settings: true","general:",' instance_name: "ChatPanel search"'," debug: false"," enable_metrics: false","server:",' secret_key: "${SEARXNG_SECRET}"'," limiter: false"," public_instance: false"," image_proxy: false",' method: "GET"',"search:"," safe_search: 0",' autocomplete: ""'," formats:"," - html"," - json","ui:"," static_use_hash: true","engines:",...l.flatMap(h=>[` - name: ${h}`," disabled: false"]),...f.flatMap(h=>[` - name: ${h}`," disabled: true"]),""].join(`
|
|
2
|
-
`)}function Oe(t=process.platform){return t==="darwin"?{command:"brew install podman",url:"https://podman.io/docs/installation#macos",note:"Homebrew; then Start the engine below (it creates and starts the Podman machine)."}:t==="win32"?{command:"winget install RedHat.Podman",url:"https://podman.io/docs/installation#windows",note:"Then Start the engine below (it creates and starts the Podman machine under WSL)."}:{command:"sudo apt install podman # or: sudo dnf install podman",url:"https://podman.io/docs/installation#installing-on-linux",note:"Rootless; no daemon to start."}}function cn(t,l){const f=l==="podman"?Array.isArray(t.Names)?t.Names[0]:String(t.Names||""):String(t.Names||t.Name||""),h=l==="podman"?Array.isArray(t.Ports)?t.Ports.map(p=>`${p.host_ip||""}:${p.host_port}->${p.container_port}/${p.protocol||"tcp"}`):[]:String(t.Ports||"").split(",").map(p=>p.trim()).filter(Boolean),P=String(t.State||"").toLowerCase()||(/^up/i.test(String(t.Status||""))?"running":"exited");return{name:f,image:String(t.Image||""),state:P,status:String(t.Status||""),ports:h,ours:f.startsWith("chatpanel-"),engine:l}}function Lt({cfg:t,bridgeHealth:l,workers:f=()=>[],persist:h=()=>{},exec:P=(S,
|
|
3
|
-
`).filter(
|
|
4
|
-
`)[0]);return e.ok&&Number.isInteger(r)&&r>1?r:0}function Ge(n){const e=
|
|
1
|
+
import{promisify as Rn}from"node:util";import{execFile as In}from"node:child_process";import{existsSync as Ee,mkdirSync as ne,writeFileSync as oe,accessSync as Un,openSync as Fn,closeSync as Hn,constants as Dn}from"node:fs";import{randomBytes as jn,createHash as Xn}from"node:crypto";import Q from"node:os";import v from"node:path";import{modelsFor as Ze,isValidModelId as Wn,catalogFor as se,vllmTaskOf as te}from"./runtime-models.js";import{pickInferenceEngine as en,pickLlamaEngine as Jn,pickMlxEngine as zn,pickAppleEngine as Kn,recommendEngine as Qn,detectAccelerator as Vn,hostShape as qn}from"./inference-engines.js";import{tuningArgs as le,tuningRows as nn,patchTunings as Yn,profilesFor as tn,resolveTunings as rn,ENGINE_DOCS as Zn}from"./engine-tunings.js";import{IMAGE_RECIPES as et}from"./images.js";import{pullRepo as nt,pullGguf as tt,repoInstalled as rt,ggufInstalled as an}from"./model-pull.js";import{liveFit as it,kvCacheMB as at,cachedConfigPath as ot,needMB as st}from"./host-memory.js";import{APPLE_HELPER as Pe,APPLE_MODEL_ID as lt,APPLE_MIN_DARWIN as ut,appleHelperDirs as ct,appleInstallDoor as dt,darwinMajor as on}from"./apple-model.js";import{spawn as mt}from"node:child_process";import{readFileSync as sn,unlinkSync as ln}from"node:fs";const ft=Rn(In),ue=["podman","docker"],V="hf-cache",X=Object.freeze([{id:"searxng",label:"SearXNG",image:"docker.io/searxng/searxng:latest",container:"chatpanel-searxng",port:8888,containerPort:8080,provides:["search"],helper:!0,blurb:"A metasearch engine of your own: the gateway’s web search fans out through it instead of scraping result pages. Loopback only.",caps:["CHOWN","SETGID","SETUID"],answers:async(t,l)=>{try{return(await l(`${t}/search?q=chatpanel&format=json`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.search?.searxng?.url||""),configure:(t,l)=>{t.search=t.search||{},t.search.searxng={...t.search.searxng||{},url:l}},unconfigure:(t,l)=>{t.search?.searxng?.url===l&&(t.search.searxng.url="")}},{id:"reranker",label:"Reranker",image:"ghcr.io/chatpanel/reranker-cpu:latest",container:"chatpanel-reranker",port:8889,containerPort:8e3,provides:["rerank"],helper:!0,adapter:"tei",model:"BAAI/bge-reranker-base",blurb:"Orders sources by relevance — research in plan notes, search results, tool results. The gateway already reranks in-process by default (a small model, no container); start this to run a multilingual cross-encoder (bge-reranker base by default) in a container instead, behind the Text Embeddings Inference wire. Loopback only.",caps:[],volumes:t=>[`${v.join(t,V)}:/data`],env:t=>["HF_HOME=/data",`MODEL_ID=${t.model}`],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.capabilities?.rerank?.url||""),configure:(t,l,f)=>{t.capabilities=t.capabilities||{},t.capabilities.rerank={url:l,adapter:f.adapter,model:f.model,service:f.id}},unconfigure:(t,l)=>{t.capabilities?.rerank?.url===l&&delete t.capabilities.rerank}},{id:"opendecision",label:"OpenDecision",image:"ghcr.io/chatpanel/opendecision-cpu:latest",container:"chatpanel-opendecision",port:8890,containerPort:8e3,provides:["decide"],helper:!0,adapter:"systemone",model:"MoritzLaurer/ModernBERT-base-zeroshot-v2.0",calibrated:!1,blurb:"Typed decisions — sentiment, routing, triage — answered by a zero-shot classifier in one pass, no language model. The gateway already decides in-process by default with the same algorithm and model; start this to run it in a container instead. TypeSafe-shaped (/v1/systemone), Apache-2.0. Loopback only.",caps:[],volumes:t=>[`${v.join(t,V)}:/data`],env:t=>["HF_HOME=/data",`MODEL_ID=${t.model}`],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.capabilities?.decide?.url||""),configure:(t,l,f)=>{t.capabilities=t.capabilities||{},t.capabilities.decide={url:l,adapter:f.adapter,model:f.model,service:f.id,calibrated:f.calibrated}},unconfigure:(t,l)=>{t.capabilities?.decide?.url===l&&delete t.capabilities.decide}},{id:"vllm",label:"vLLM",image:"ghcr.io/chatpanel/vllm-cpu:latest",engineOf:t=>en({...t,containerOnly:!0}),container:"chatpanel-vllm",port:8891,containerPort:8e3,provides:["chat","embed","stt"],adapter:"openai",model:"Qwen/Qwen3-0.6B",pull:!0,blurb:"Your own model, served by vLLM on this machine’s accelerator (CUDA, ROCm, XPU — or CPU): a chat model the router can send turns to, an embedding model for semantic search, or a transcriber for every ear. OpenAI-shaped, loopback only.",caps:[],volumes:t=>[`${v.join(t,V)}:/data`],env:t=>["HF_HOME=/data","VLLM_CPU_KVCACHE_SPACE=4",`MODEL_ID=${t.model}`,...t.installed?["HF_HUB_OFFLINE=1"]:[]],args:(t,l)=>["--model",t.model,"--host","0.0.0.0","--port","8000",...te(t.model)==="embed"?["--task","embed"]:[],...le("vllm",t.tunings,{task:te(t.model),model:t.model,backend:l?.backend||null})],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String(t.capabilities?.embed?.service==="vllm"?t.capabilities.embed.url.replace(/\/v1$/,""):t.capabilities?.stt?.service==="vllm"?t.capabilities.stt.url.replace(/\/v1$/,""):(t.destinations||[]).find(l=>l?.service==="vllm")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{const h=`${l}/v1`,P=te(f.model);un(t),P==="chat"?(t.destinations=(t.destinations||[]).filter(p=>p?.service!=="vllm"&&p?.id!=="vllm"),t.destinations.push({id:"vllm",type:"api",protocol:"openai",baseUrl:h,models:[f.model],service:"vllm"})):P==="embed"?(t.capabilities=t.capabilities||{},t.capabilities.embed={url:h,adapter:"openai",model:f.model,service:"vllm"}):P==="transcription"&&(t.capabilities=t.capabilities||{},t.capabilities.stt={provider:"container",url:h,adapter:"openai",model:f.model,service:"vllm"})},unconfigure:t=>un(t)},{id:"vllm-metal",label:"vLLM (Metal, Apple Silicon)",kind:"native",runner:"vllm",pull:!0,engineOf:t=>en(t),only:{platform:"darwin",arch:"arm64"},port:8892,provides:["chat"],adapter:"openai",model:"mlx-community/Qwen3-1.7B-4bit",blurb:"Your own model on the Apple Silicon GPU, served by vLLM-Metal: a chat model the router can send turns to. A process on this machine behind the gateway, loopback only.",command:(t,l)=>["vllm",["serve",t.model,"--host","127.0.0.1","--port",String(t.port),...le("vllm-metal",t.tunings,l)]],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="vllm-metal")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{t.destinations=(t.destinations||[]).filter(h=>h?.service!=="vllm-metal"&&h?.id!=="vllm-metal"),t.destinations.push({id:"vllm-metal",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[f.model],service:"vllm-metal"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="vllm-metal"&&l?.id!=="vllm-metal"))}},{id:"llama",label:"llama.cpp",kind:"native",runner:"llama-server",pull:!0,engineOf:t=>Jn(t),port:8893,provides:["chat"],adapter:"openai",model:"unsloth/Qwen3-4B-GGUF:Q4_K_M",blurb:"Your own GGUF model on this machine, served by llama.cpp: the Metal GPU on a Mac, CUDA or Vulkan elsewhere, CPU otherwise — a chat model the router can send turns to, with the flags that make it fast set for this machine. A process on this machine behind the gateway, loopback only.",alias:t=>/\.gguf$/i.test(t)?t.split(/[\\/]/).pop().replace(/\.gguf$/i,""):t.split("/").pop().split(":")[0],command:(t,l)=>["llama-server",[...t.file?["-m",t.file]:/\.gguf$/i.test(t.model)?["-m",t.model]:["-hf",t.model],"--host","127.0.0.1","--port",String(t.port),"--alias",t.alias(t.model),"--jinja",...le("llama",t.tunings,l)]],answers:async(t,l)=>{try{return(await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="llama")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{t.destinations=(t.destinations||[]).filter(h=>h?.service!=="llama"&&h?.id!=="llama"),t.destinations.push({id:"llama",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[f.alias(f.model)],service:"llama"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="llama"&&l?.id!=="llama"))}},{id:"mlx",label:"MLX",kind:"native",runner:"mlx_lm.server",runnerCheck:["--help"],pull:!0,engineOf:t=>zn(t),only:{platform:"darwin",arch:"arm64"},port:8894,provides:["chat"],adapter:"openai",model:"mlx-community/Qwen3-1.7B-4bit",blurb:"Your own model on the Apple Silicon GPU through MLX — Apple’s framework, the lightest way to run a chat model on a Mac. A process on this machine behind the gateway, loopback only.",command:(t,l)=>["mlx_lm.server",["--model",t.model,"--host","127.0.0.1","--port",String(t.port),...le("mlx",t.tunings,l)]],answers:async(t,l)=>{try{return(await l(`${t}/v1/models`,{signal:AbortSignal.timeout(4e3)})).ok}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="mlx")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l,f)=>{t.destinations=(t.destinations||[]).filter(h=>h?.service!=="mlx"&&h?.id!=="mlx"),t.destinations.push({id:"mlx",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[f.model],service:"mlx"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="mlx"&&l?.id!=="mlx"))}},{id:"apple",label:"Apple on-device",kind:"native",auto:!0,runner:Pe,engineOf:t=>Kn(t),only:{platform:"darwin",arch:"arm64",minDarwin:ut,label:"macOS 26 or later on Apple Silicon"},port:8895,provides:["chat"],adapter:"openai",window:4096,card:{engine:"apple",backend:"apple",where:"this machine",egress:"none",cost:"free",task:"chat",window:4096,vision:!1,tools:!1,reasoning:!1,label:"Apple on-device",licence:"Apple",draft:!1},blurb:"Apple’s own model, on this Mac (macOS 26 with Apple Intelligence on): the system loads it when asked and frees it when idle, so nothing stays loaded and nothing runs hot — the lightest choice for titles, topics and short answers. Text only, 4,096 tokens at a time. A small helper on this machine behind the gateway, loopback only.",command:t=>[Pe,["serve","--port",String(t.port)]],answers:async(t,l)=>{try{const f=await l(`${t}/health`,{signal:AbortSignal.timeout(4e3)});return f.ok&&(await f.json())?.ok===!0}catch{return!1}},configured:t=>String((t.destinations||[]).find(l=>l?.service==="apple")?.baseUrl?.replace(/\/v1$/,"")||""),configure:(t,l)=>{t.destinations=(t.destinations||[]).filter(f=>f?.service!=="apple"&&f?.id!=="apple"),t.destinations.push({id:"apple",type:"api",protocol:"openai",baseUrl:`${l}/v1`,models:[lt],service:"apple"})},unconfigure:t=>{Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="apple"&&l?.id!=="apple"))}}]),re=t=>t.only?.label||`${t.only?.platform||"this platform"} ${t.only?.arch||""}`.trim();function un(t){Array.isArray(t.destinations)&&(t.destinations=t.destinations.filter(l=>l?.service!=="vllm"&&l?.id!=="vllm")),t.capabilities?.embed?.service==="vllm"&&delete t.capabilities.embed,t.capabilities?.stt?.service==="vllm"&&delete t.capabilities.stt}const x=t=>X.find(l=>l.id===t)||null,pt=({answers:t,configured:l,configure:f,unconfigure:h,volumes:P,args:p,env:H,caps:ce,command:de,engineOf:Ne,alias:B,..._})=>_,ht=Object.freeze(["google","yahoo","yep","duckduckgo","bing","wikipedia"]),gt=Object.freeze(["brave","qwant"]);function kt(t=[]){const l=t.length?t:ht,f=gt.filter(h=>!l.includes(h));return["# Written by chatpanel-gateway (Settings › Runtime). JSON on, the limiter off — the port is","# bound to 127.0.0.1, which is what makes that safe. Do not publish it on 0.0.0.0.","use_default_settings: true","general:",' instance_name: "ChatPanel search"'," debug: false"," enable_metrics: false","server:",' secret_key: "${SEARXNG_SECRET}"'," limiter: false"," public_instance: false"," image_proxy: false",' method: "GET"',"search:"," safe_search: 0",' autocomplete: ""'," formats:"," - html"," - json","ui:"," static_use_hash: true","engines:",...l.flatMap(h=>[` - name: ${h}`," disabled: false"]),...f.flatMap(h=>[` - name: ${h}`," disabled: true"]),""].join(`
|
|
2
|
+
`)}function Oe(t=process.platform){return t==="darwin"?{command:"brew install podman",url:"https://podman.io/docs/installation#macos",note:"Homebrew; then Start the engine below (it creates and starts the Podman machine)."}:t==="win32"?{command:"winget install RedHat.Podman",url:"https://podman.io/docs/installation#windows",note:"Then Start the engine below (it creates and starts the Podman machine under WSL)."}:{command:"sudo apt install podman # or: sudo dnf install podman",url:"https://podman.io/docs/installation#installing-on-linux",note:"Rootless; no daemon to start."}}function cn(t,l){const f=l==="podman"?Array.isArray(t.Names)?t.Names[0]:String(t.Names||""):String(t.Names||t.Name||""),h=l==="podman"?Array.isArray(t.Ports)?t.Ports.map(p=>`${p.host_ip||""}:${p.host_port}->${p.container_port}/${p.protocol||"tcp"}`):[]:String(t.Ports||"").split(",").map(p=>p.trim()).filter(Boolean),P=String(t.State||"").toLowerCase()||(/^up/i.test(String(t.Status||""))?"running":"exited");return{name:f,image:String(t.Image||""),state:P,status:String(t.Status||""),ports:h,ours:f.startsWith("chatpanel-"),engine:l}}function Lt({cfg:t,bridgeHealth:l,workers:f=()=>[],persist:h=()=>{},exec:P=(S,D,C={})=>ft(S,D,{timeout:6e4,killSignal:"SIGKILL",...C}),platform:p=process.platform,arch:H=process.arch,osRelease:ce=Q.release(),spawn:de=mt,lookup:Ne=null,fetchImpl:B=globalThis.fetch,stateDir:_=v.join(Q.homedir(),".chatpanel","runtime"),log:E=()=>{},sleep:me=S=>new Promise(D=>setTimeout(D,S)),totalMem:Be=()=>Q.totalmem(),memoryProbe:dn=S=>p==="darwin"&&t?.runtime?.heatwatch!==!1?it(S,{fetchImpl:B}):Promise.resolve(null),now:fe=()=>Date.now(),autoEnv:mn=process.env.CHATPANEL_RUNTIME_AUTO,every:Ce=(S,D)=>{const C=setInterval(S,D);return C.unref?.(),C}}={}){const S=Q.homedir(),D=p==="win32"?[v.join(S,"AppData","Local","Microsoft","WinGet","Links"),v.join(S,".local","bin"),v.join(S,".cargo","bin")]:["/opt/homebrew/bin","/usr/local/bin",v.join(S,".local","bin"),v.join(S,".cargo","bin"),"/home/linuxbrew/.linuxbrew/bin",...p==="darwin"?ct({home:S}):[]],C=(n=process.env)=>{const e=p==="win32"?";":":",r=String(n.PATH||n.Path||""),i=D.filter(s=>!r.split(e).includes(s));return{...n,PATH:[...r.split(e).filter(Boolean),...i].join(e)}},k=async(n,e,r={})=>{try{const i=await P(n,e,{...r,env:C(r.env)});return{ok:!0,out:String(i.stdout||"").trim(),err:String(i.stderr||"").trim()}}catch(i){return{ok:!1,out:String(i?.stdout||"").trim(),err:String(i?.stderr||i?.message||i).trim(),code:i?.code}}},y=n=>String(t.runtime?.services?.[n.id]?.model||n.model||"");let pe=null;const fn=async()=>(pe===null&&(pe=await Vn({exec:P,platform:p,arch:H})),pe),q={},pn=n=>{const e=p==="win32"?";":":",r=p==="win32"?[".exe",".cmd",".bat",""]:[""];for(const i of C().PATH.split(e).filter(Boolean))for(const s of r)try{return Un(v.join(i,n+s),Dn.X_OK),!0}catch{}return!1},L=async(n,e=["--version"])=>(q[n]===void 0&&(q[n]=(Ne||pn)(n)||(await k(n,e,{timeout:8e3})).ok),q[n]);let he=null;const ge=async()=>(he||(he=await qn({exec:P,platform:p,totalmem:Be,cpus:()=>Q.cpus()})),he),G=async n=>({platform:p,arch:H,accelerator:await fn(),engine:n,vllmOnPath:await L("vllm"),llamaOnPath:await L("llama-server"),mlxOnPath:p==="darwin"&&H==="arm64"?await L("mlx_lm.server",["--help"]):!1,osMajor:p==="darwin"?on(ce):0,appleOnPath:p==="darwin"&&H==="arm64"?await L(Pe):!1,appleInstall:p==="darwin"?dt({home:S}):null,...await ge()}),R=n=>!n.only||(!n.only.platform||n.only.platform===p)&&(!n.only.arch||n.only.arch===H)&&(!n.only.minDarwin||on(ce)>=n.only.minDarwin),Y=n=>v.join(_,`${n.id}.pid`),W=n=>{try{const e=Number(sn(Y(n),"utf8"));if(e>0)return process.kill(e,0),e}catch{}return null},ke=n=>R(n)?W(n)?"running":"stopped":"unsupported",j={};async function ie(n){const e=Z(n);if(!R(e))return{ok:!1,error:`${e.label} runs on ${re(e)} only`};if(W(e))return e.auto&&!e.configured(t)&&(e.configure(t,A(e),e),h()),{ok:!0,already:!0,url:A(e)};if(e.auto&&await e.answers(A(e),B)){const $=await wn(e.port);if($)return ne(_,{recursive:!0,mode:448}),oe(Y(e),String($),{mode:384}),j[e.id]={layer:"none",reason:"a model engine runs on the hardware, behind the gateway"},e.configure(t,A(e),e),h(),E(`[runtime] ${e.label} was already answering on ${A(e)} (pid ${$}) — adopted`),{ok:!0,adopted:!0,url:A(e),answering:!0,provides:e.provides}}const r=await G(null),i=e.engineOf(r);if(!await L(e.runner,e.runnerCheck))return{ok:!1,error:`\`${e.runner}\` is not on PATH — install it first (${i.install?.command||""}), or click Install`,install:i.install};if(e.id==="llama"&&/\.gguf$/i.test(e.model)&&!Ee(e.model))return{ok:!1,error:`no such file: ${e.model}`};const[s,o]=e.command(e,I(e,e.model,i,r)),a=v.join(_,V);ne(a,{recursive:!0,mode:448});const d={bin:s,argv:o,opts:{detached:!0,stdio:["ignore","ignore","ignore"],env:{...process.env,HF_HOME:a,LLAMA_CACHE:a,...e.installed?{HF_HUB_OFFLINE:"1"}:{}}},record:{layer:"none",reason:"a model engine runs on the hardware directly, behind the gateway (loopback only) — the sandbox is for agents and tools"}};j[e.id]=d.record;const u=v.join(_,`${e.id}.log`);let c,m=null;try{try{m=Fn(u,"w",384)}catch{m=null}c=de(d.bin,d.argv,{...d.opts,env:C(d.opts?.env),detached:!0,stdio:["ignore",m??"ignore",m??"ignore"]}),c.unref?.()}catch($){return{ok:!1,error:`${d.bin}: ${$.message}`,install:i.install}}finally{if(m!==null)try{Hn(m)}catch{}}if(!c?.pid)return{ok:!1,error:`${d.bin} did not start`,install:i.install};oe(Y(e),String(c.pid),{mode:384});const w=A(e);let g=!1;for(let $=0;$<120&&!g&&W(e);$++)g=await e.answers(w,B),g||await me(1e3);if(!W(e)){try{ln(Y(e))}catch{}let $="";try{$=sn(u,"utf8").trim().split(`
|
|
3
|
+
`).filter(U=>/\b(E |error|Error|couldn't|cannot|failed|not found|No such)\b/.test(U)).slice(-3).map(U=>U.replace(/^[\d.]+ [A-Z] \S+\s+/,"").trim()).join(" | ")}catch{$=""}return{ok:!1,error:`${e.label} exited on start${$?` — ${$}`:` — a model it cannot load, a draft or projector file that is not there, or ${e.runner} not installed (${i.install?.command})`}`,log:u}}return e.configure(t,w,e),h(),E(`[runtime] ${e.label} started (pid ${c.pid}) on ${w}, sandbox ${j[e.id].layer}${g?"":" — not answering yet (downloading the model?)"}`),{ok:!0,url:w,answering:g,provides:e.provides,model:y(e),sandbox:j[e.id]}}const we=n=>t.runtime?.services?.[n.id]?.off===!0,Le=(n,e)=>{t.runtime=t.runtime||{},t.runtime.services=t.runtime.services||{};const r={...t.runtime.services[n.id]||{}};e?r.off=!0:delete r.off,t.runtime.services[n.id]=r},hn=()=>t.runtime?.auto!==!1&&String(mn||"").toLowerCase()!=="off",O={};async function Te(n){if(!n?.auto)return{ok:!1,skipped:"not a service that starts by itself"};if(!hn())return{ok:!1,skipped:"automatic start is switched off"};if(!R(n))return{ok:!1,skipped:`runs on ${re(n)} only`};if(we(n))return{ok:!1,skipped:"stopped by the person"};if(!await L(n.runner,n.runnerCheck))return{ok:!1,skipped:"its helper is not in this install"};if(!W(n)){const r=await k(n.runner,["check"],{timeout:8e3});if(!r.ok){let i="";try{i=JSON.parse(r.out||"{}").message||""}catch{i=""}return O[n.id]=i||"not available on this Mac right now",{ok:!1,skipped:O[n.id]}}}const e=await ie(n);return e.ok?(delete O[n.id],{ok:!0,...e.already?{already:!0}:e.adopted?{adopted:!0}:{started:!0}}):(O[n.id]=e.error,{ok:!1,skipped:e.error})}async function gn(){const n=[];for(const e of X.filter(r=>r.auto))n.push({id:e.id,label:e.label,...await Te(e).catch(r=>({ok:!1,skipped:r.message}))});return n}async function kn(n){const e=x(n);return e?.auto?Te(e):{ok:!1,skipped:"not a service that starts by itself"}}async function wn(n){if(p==="win32")return 0;const e=await k("lsof",["-nP",`-iTCP:${n}`,"-sTCP:LISTEN","-t"],{timeout:4e3}),r=Number(String(e.out||"").split(`
|
|
4
|
+
`)[0]);return e.ok&&Number.isInteger(r)&&r>1?r:0}function Ge(n){const e=W(n);if(e)try{process.kill(e,"SIGTERM")}catch{}try{ln(Y(n))}catch{}return n.unconfigure(t,A(n)),h(),{ok:!0}}const Z=n=>n.model?{...n,model:y(n),installed:K(n,y(n)),tunings:t.runtime?.services?.[n.id]?.tunings||{},...n.id==="llama"?{file:yn(y(n))}:{}}:n,J=n=>n.id==="vllm"||n.id==="vllm-metal"||n.id==="llama"||n.id==="mlx";function bn(n,e){const r=(e.ramGB||0)*1024,i={light:0,balanced:1,accurate:2,max:3},s=se(n.id).filter(d=>!d.minRamMB||r>0&&r>=d.minRamMB);if(!s.length||!r)return null;const o=s.slice().sort((d,u)=>(i[u.tier]??-1)-(i[d.tier]??-1)||d.ramMB-u.ramMB)[0],a=Math.round(o.ramMB/1024*10)/10;return{model:o.id,label:o.label,why:`This machine (${e.ramGB} GB${e.accelerator==="apple"?", Apple Silicon":e.accelerator?`, ${e.accelerator.toUpperCase()} GPU`:", no GPU"}) runs ${o.label} well — about ${a} GB while loaded${o.tier==="max"?"; the strongest in the list":""}.`,profile:"coding",current:y(n)===o.id}}async function Re(n,{model:e,ctx:r,needMB:i}={}){const s=x(n);if(!s||!s.model)return{ok:!1,error:s?`${s.label} takes no model`:`unknown service ${n}`};const o=String(e||y(s)),a=se(n).find(_e=>_e.id===o)||null,d=Number(i)>0?Number(i):a?.ramMB||null;if(!d)return{ok:!1,error:`${o} is not in the catalogue — pass need_mb (its peak memory while serving)`};const u=Number(r)>0?Number(r):Ve(n),c=/\.gguf$/i.test(o)||s.id==="llama"?null:ot(z(),o),m=u&&c?at(c,u):null,w=st({ramMB:d,kvMB:m||0}),g=s.kind==="native"?await dn(w):null,$=((await ge()).ramGB||0)*1024,U=g?g.fits:$>0&&w<=$,F=_e=>`${Math.round(_e/102.4)/10} GB`,Gn=g?g.fits?`${o} fits: needs about ${F(w)}, ${F(g.availableMB)} is free now${g.fitsGPULimit===!1?` — but it is above the GPU wired limit (${F(g.gpuWiredLimitMB)}); raise iogpu.wired_limit_mb`:""}.`:`${o} needs about ${F(w)} and ${F(g.availableMB)} is free now — ${F(g.shortfallMB)} short.${g.close.length?` Close ${g.close.join(", ")} to make room, or pick a smaller model.`:" Pick a smaller model."}`:`${o} needs about ${F(w)} of the machine's ${F($)} — ${U?"fits":"does not fit"} (total memory; install Heatwatch to check what is free now).`;return{ok:!0,service:s.id,model:o,needMB:w,weightsMB:d,kvMB:m,context:u||null,contextCounted:m!==null||!u,source:g?"heatwatch":"total-memory",fits:U,live:g,advice:Gn}}const I=(n,e,r,i={})=>({task:n.id==="vllm"?te(e):"chat",model:e,backend:r?.backend||null,ramGB:i.ramGB||0,cores:i.cores||0,perfCores:i.perfCores||0}),z=()=>v.join(_,V),K=(n,e)=>/\.gguf$/i.test(e)?Ee(e):n.id==="llama"?!!an(z(),e):rt(z(),e),yn=n=>/\.gguf$/i.test(n)?n:an(z(),n),b={},wt=n=>b[n.id]||null;function be(n,e,r={}){return b[n.id]={kind:e,since:Date.now(),lines:[],progress:null,done:!1,error:null,...r},b[n.id]}function N(n,e){const r=String(e||"").trim();if(!r)return;n.lines.push(r.slice(0,200)),n.lines.length>8&&n.lines.shift();const i=/^STEP (\d+)\/(\d+)/.exec(r);i&&(n.step={n:Number(i[1]),of:Number(i[2])})}const ae=(n,e,r,{timeout:i=36e5*4}={})=>new Promise(s=>{if(n.cancelled)return s({ok:!1,code:-1,error:"cancelled"});let o;try{o=de(e,r,{stdio:["ignore","pipe","pipe"],env:C()})}catch(c){return s({ok:!1,code:-1,error:c.message})}n.child=o;let a="";const d=c=>{a+=String(c);const m=a.split(/\r?\n|\r/);a=m.pop();for(const w of m)N(n,w)};o.stdout?.on("data",d),o.stderr?.on("data",d);const u=setTimeout(()=>{try{o.kill("SIGTERM")}catch{}},i);u.unref?.(),o.on("error",c=>{clearTimeout(u),n.child=null,s({ok:!1,code:-1,error:c.message})}),o.on("exit",c=>{clearTimeout(u),n.child=null,a&&N(n,a),s({ok:c===0&&!n.cancelled,code:c,...n.cancelled?{error:"cancelled"}:{}})})}),Ie={install:Promise.resolve(),build:Promise.resolve()},ye={install:0,build:0},Ue=(n,e,r)=>{ye[n]>0&&(e.waiting=!0,N(e,`waiting for the other ${n} to finish first — one at a time`)),ye[n]++;const i=Ie[n];let s;const o=new Promise(a=>{s=a});return Ie[n]=i.then(()=>o),i.then(async()=>{e.waiting&&(N(e,"the other one finished — going"),e.waiting=!1);try{return await r()}finally{ye[n]--,s()}})},Fe=async(n,e)=>(await k(n,["image","exists",e],{timeout:2e4})).ok;async function $n(n,e,r,i){const s=e?.image||r.image;if(await Fe(n,s))return{ok:!0};const o=e?.sources?.length?e.sources:[s],a=[];for(const m of o){if(i.kind="pull-image",i.detail=m,N(i,`pulling ${m}`),(await ae(i,n,["pull",m])).ok)return m!==s&&await k(n,["tag",m,s],{timeout:2e4}),{ok:!0,pulled:m};a.push(m)}const d=e?.recipe?et[e.recipe]:null;if(!d)return{ok:!1,error:`no image to pull (${a.join(", ")} — ${i.lines.at(-1)||"refused"})`};const u=v.join(_,"images",e.recipe);return ne(u,{recursive:!0,mode:448}),oe(v.join(u,"Dockerfile"),d.dockerfile,{mode:384}),i.kind="build-image",i.detail=s,i.minutes=d.minutes,N(i,`no registry has ${s} for this machine — building it here (about ${d.minutes} minutes)`),E(`[runtime] building ${s} from the ${e.recipe} recipe in ${u}`),(await Ue("build",i,()=>ae(i,n,["build","-t",s,"-f",v.join(u,"Dockerfile"),u]))).ok?{ok:!0,built:!0}:{ok:!1,error:`build failed: ${i.lines.slice(-3).join(" | ")}`}}async function He(n,e){const r=y(n);if(!r||K(n,r))return{ok:!0};if(/\.gguf$/i.test(r))return{ok:!1,error:`no such file: ${r}`};e.kind="pull-model",e.detail=r;const i=s=>{if(e.cancelled)throw new Error("cancelled");e.progress={bytes:s.bytes,total:s.total,file:s.file}};try{return n.id==="llama"?await tt(r,{root:z(),fetchImpl:B,onProgress:i}):await nt(r,{root:z(),fetchImpl:B,onProgress:i}),{ok:!0}}catch(s){return{ok:!1,error:`pull ${r}: ${s.message}`}}}async function vn(n,e,r){const i=[];return n.kind!=="native"&&e&&!await Fe(e,r?.image||n.image)&&i.push("image"),n.pull&&n.model&&!K(n,y(n))&&i.push("model"),i}async function De(n,e){if(!n||!e?.[n]?.running)return 0;if(n==="podman"&&p!=="linux"){const r=await k("podman",["machine","inspect","--format","{{.Resources.Memory}}"],{timeout:8e3}),i=parseInt(r.out,10);return r.ok&&i>0?i:0}if(n==="docker"&&p!=="linux"){const r=await k("docker",["info","--format","{{.MemTotal}}"],{timeout:8e3}),i=parseInt(r.out,10);return r.ok&&i>0?Math.round(i/1048576):0}return Math.round(Be()/1048576)}async function M(){const n={};for(const r of ue){const i=await k(r,["--version"],{timeout:5e3});if(!i.ok){n[r]={installed:!1};continue}const s=(i.out.match(/(\d+\.\d+(\.\d+)?)/)||[])[1]||i.out;let o=!1,a=null;if(r==="podman")if(p==="linux")o=(await k("podman",["info","--format","{{.Host.Arch}}"],{timeout:8e3})).ok;else{const d=await k("podman",["machine","list","--format","json"],{timeout:8e3});try{const c=JSON.parse(d.out||"[]")[0]||null;a=c?{name:c.Name,running:!!c.Running}:null,o=!!c?.Running}catch{a=null}}else o=(await k("docker",["info","--format","{{.ServerVersion}}"],{timeout:8e3})).ok;n[r]={installed:!0,version:s,running:o,...r==="podman"&&p!=="linux"?{machine:a}:{}}}const e=ue.find(r=>n[r]?.installed&&n[r].running)||ue.find(r=>n[r]?.installed)||null;return{...n,preferred:e,...e?{}:{install:Oe(p)}}}async function $e(n="podman"){if(!ue.includes(n))return{ok:!1,error:`unknown engine ${n}`};const e=(await M())[n];if(!e?.installed)return{ok:!1,error:`${n} is not installed`,install:Oe(p)};if(e.running)return{ok:!0,already:!0};if(n==="docker")return{ok:!1,error:"start Docker Desktop (or the docker daemon) yourself — the gateway does not manage it"};if(p!=="linux"){if(!e.machine){const i=await k("podman",["machine","init"],{timeout:6e5});if(!i.ok)return{ok:!1,error:`podman machine init: ${i.err||i.out}`}}const r=await k("podman",["machine","start"],{timeout:3e5});if(!r.ok&&!/already running/i.test(r.err))return{ok:!1,error:`podman machine start: ${r.err||r.out}`}}return{ok:!0}}async function je(){const n=await M(),e=n.preferred;if(!e||!n[e].running)return[];if(e==="podman"){const i=await k("podman",["ps","-a","--format","json"],{timeout:1e4});if(!i.ok)return[];try{return JSON.parse(i.out||"[]").map(s=>cn(s,"podman"))}catch{return[]}}const r=await k("docker",["ps","-a","--format","{{json .}}"],{timeout:1e4});return r.ok?r.out.split(`
|
|
5
5
|
`).filter(Boolean).map(i=>{try{return cn(JSON.parse(i),"docker")}catch{return null}}).filter(Boolean):[]}async function Xe(n,e){const r=await k(n,["inspect","--format","{{.State.Status}}",e],{timeout:8e3});return r.ok?/running/i.test(r.out)?"running":"stopped":"absent"}async function ve(n,e){const r=await k(n,["ps","-a","--format","{{.Names}} {{.State}}"],{timeout:8e3}),i={};if(!r.ok){for(const o of e)i[o]="absent";return i}const s=new Map(r.out.split(`
|
|
6
|
-
`).map(o=>o.split(" ")).filter(o=>o[0]).map(([o,a])=>[o,/running/i.test(a||"")?"running":"stopped"]));for(const o of e)i[o]=s.get(o)||"absent";return i}const A=n=>`http://127.0.0.1:${n.port}`;async function We(){const n=await M(),e=n.preferred,r=await De(e,n),i={},s=await T(e),o=e&&n[e].running?await ve(e,j.filter(a=>a.kind!=="native").map(a=>a.container)):{};for(const a of j){const c=A(a);let u="no-engine";a.kind==="native"?u=ke(a):e&&n[e].running?u=o[a.container]||"absent":e&&(u="engine-stopped");const d=a.model?y(a):null,m=a.engineOf?a.engineOf(s):null,w=a.kind==="native"?(s.ramGB||0)*1024:r;i[a.id]={...pt(a),engine:a.kind==="native"?"host":e,state:u,url:c,configured:a.configured(t),answering:u==="running"?await a.answers(c,N):!1,...a.helper?{asleep:L.has(a.id),idleMinutes:qe()/6e4}:{},...m?{engineFor:{backend:m.backend,kind:m.kind,image:m.image||null,...m.runner?{runner:m.runner}:{},why:m.why,...m.for?{for:m.for}:{},...m.speed?{speed:m.speed}:{},...m.notFor?{notFor:m.notFor}:{},...m.warn?{warn:m.warn}:{},...m.install?{install:m.install}:{}}}:{},...a.kind==="native"&&!H(a)?{why:`${a.label} runs on ${re(a)} only`}:{},...a.auto&&u!=="running"&&H(a)?{auto:!0,...we(a)?{why:"Stopped here — Start turns it back on"}:W[a.id]?{why:W[a.id]}:{}}:a.auto?{auto:!0}:{},...a.kind==="native"&&D[a.id]?{sandbox:D[a.id]}:{},...b[a.id]?{job:{kind:b[a.id].kind,since:b[a.id].since,detail:b[a.id].detail||null,step:b[a.id].step||null,minutes:b[a.id].minutes||null,progress:b[a.id].progress,lines:b[a.id].lines.slice(-4),done:b[a.id].done,error:b[a.id].error,waiting:!!b[a.id].waiting,cancelled:!!b[a.id].cancelled}}:{},...J(a)?{profiles:tn(a.id,t.runtime?.services?.[a.id]?.tunings,G(a,d,m,s)),docs:Zn[a.id]||null}:{},...a.model&&a.kind==="native"?{recommend:bn(a,s)}:{},...a.model?{model:d,default:a.model,models:Ze(a.id,{active:d,engineRamMB:w,engine:a.kind==="native"?"host":e,platform:p,installed:g=>K(a,g)}),machine:{engineRamMB:w}}:{},...J(a)?{tunings:nn(a.id,t.runtime?.services?.[a.id]?.tunings,G(a,d,m,s))}:{}}}return i}async function Sn(){const n=await M(),e=await T(n.preferred);return{platform:p,arch:U,accelerator:e.accelerator,vllmOnPath:e.vllmOnPath,llamaOnPath:e.llamaOnPath,mlxOnPath:e.mlxOnPath,ramGB:e.ramGB,cores:e.cores,perfCores:e.perfCores,recommend:Qn(e)}}function Je(n,{settingsFile:e=null,secret:r=null,pick:i=null,cpus:s=null}={}){const o=Z(n),a=["run","-d","--name",o.container,"--restart","no","-p",`127.0.0.1:${o.port}:${o.containerPort}`];o.helper&&s&&a.push("--cpus",String(s));for(const u of o.volumes?o.volumes(_):[])a.push("-v",u);e&&a.push("-v",`${e}:/etc/searxng/settings.yml:ro`);for(const u of o.env?o.env(o):[])a.push("-e",u);o.helper&&s&&a.push("-e",`THREADS=${s}`),r&&a.push("-e",`SEARXNG_SECRET=${r}`,"-e",`SEARXNG_BASE_URL=http://127.0.0.1:${o.port}/`),a.push("--cap-drop","ALL");for(const u of o.caps||[])a.push("--cap-add",u);i?.devices?.length&&a.push(...i.devices),a.push(i?.image||o.image,...o.args?o.args(o,i):[]);const c=Xn("sha1").update(JSON.stringify(a.filter(u=>!String(u).startsWith("SEARXNG_SECRET=")))).digest("hex").slice(0,12);return a.splice(2,0,"--label",`chatpanel.run=${c}`),{args:a,hash:c}}const Se={};async function An(n){if(Se[n]==null){const e=await k(n,["info","--format",n==="docker"?"{{.NCPU}}":"{{.Host.CPUs}}"],{timeout:8e3}),r=Number.parseInt(e.out,10);Se[n]=Number.isFinite(r)&&r>0?r:Q.cpus()?.length||2}return Math.max(1,Math.floor(Se[n]/2))}async function ze(n,{force:e=!1}={}){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};L.delete(r.id),xe(r.id),r.auto&&we(r)&&Le(r,!1);const i=b[r.id];if(i&&!i.done)return{ok:!0,pending:{kind:i.kind,since:i.since,detail:i.detail||null}};let s=null;if(r.kind!=="native"){const d=await M();if(s=d.preferred,!s)return{ok:!1,error:"no container engine — install Podman first",install:Oe(p)};if(!d[s].running){const m=await $e(s);if(!m.ok)return m}}else if(!H(r))return{ok:!1,error:`${r.label} runs on ${re(r)} only`};const o=await T(s),a=r.engineOf?r.engineOf(o):null;if(r.kind==="native"&&!await C(r.runner,r.runnerCheck))return{ok:!1,error:`\`${r.runner}\` is not on PATH — install it first (${a?.install?.command||""}), or click Install`,install:a?.install};if(r.model&&/\.gguf$/i.test(y(r))&&!Ee(y(r)))return{ok:!1,error:`no such file: ${y(r)}`};if(r.kind==="native"&&r.model&&!e){const d=await Re(r.id);if(d.live&&!d.fits)return{ok:!1,error:d.advice,plan:d}}const c=await vn(r,s,a);if(!c.length)return delete b[r.id],r.kind==="native"?ie(r):Ae(r,s);const u=be(r,c[0]==="image"?"pull-image":"pull-model",{detail:c[0]==="image"?a?.image||r.image:y(r)});return u.then=(async()=>{try{if(c.includes("image")){const m=await $n(s,a,r,u);if(!m.ok)throw new Error(m.error)}if(c.includes("model")){const m=await He(r,u);if(!m.ok)throw new Error(m.error)}u.kind="starting",u.detail=r.label;const d=r.kind==="native"?await ie(r):await Ae(r,s);if(!d.ok)throw new Error(d.error);u.done=!0,u.result=d,E(`[runtime] ${r.label}: ready after ${Math.round((Date.now()-u.since)/1e3)} s`)}catch(d){u.done=!0,u.error=u.cancelled?"cancelled":d.message,E(`[runtime] ${r.label}: ${u.error}`)}})(),{ok:!0,pending:{kind:u.kind,since:u.since,detail:u.detail}}}function Mn(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};const r=b[e.id];if(!r||r.done)return{ok:!0,nothing:!0};if(r.cancelled=!0,r.child){try{r.child.kill("SIGTERM")}catch{}const i=r.child;setTimeout(()=>{try{i.kill("SIGKILL")}catch{}},5e3).unref?.()}return O(r,"cancelled"),E(`[runtime] ${e.label}: job cancelled (${r.kind})`),{ok:!0,cancelled:r.kind}}async function Ae(n,e){let r=await Xe(e,n.container);const i=n.helper?await An(e):null,s=n.engineOf?n.engineOf(await T(e)):null,o=n.id==="searxng"?v.join(_,"searxng-settings.yml"):null,a=Je(n,{settingsFile:o,secret:n.id==="searxng"?"x":null,pick:s,cpus:i});if(r!=="absent"){const d=await k(e,["inspect","--format",'{{index .Config.Labels "chatpanel.run"}}',n.container],{timeout:8e3});(!d.ok||d.out!==a.hash)&&(E(`[runtime] ${n.label}: made with older settings — re-creating it`),await k(e,["rm","-f",n.container],{timeout:6e4}),r="absent")}if(r!=="running")if(r==="stopped"){const d=await k(e,["start",n.container],{timeout:6e4});if(!d.ok)return{ok:!1,error:`${e} start: ${d.err||d.out}`}}else{ne(_,{recursive:!0,mode:448});let d=null;n.id==="searxng"&&(oe(o,kt(String(t.search?.searxng?.engines||"").split(",").map(g=>g.trim()).filter(Boolean)),{mode:384}),d=jn(32).toString("hex")),n.volumes&&ne(v.join(_,V),{recursive:!0,mode:448});const{args:m}=Je(n,{settingsFile:o,secret:d,pick:s,cpus:i});E(`[runtime] ${e} ${m.filter(g=>!g.startsWith("SEARXNG_SECRET")).join(" ")}`);const w=await k(e,m,{timeout:6e5});if(!w.ok)return{ok:!1,error:`${e} run: ${w.err||w.out}`}}const c=A(n);let u=!1;for(let d=0;d<30&&!u;d++)u=await n.answers(c,N),u||await me(1e3);return n.configure(t,c,Z(n)),h(),{ok:!0,url:c,answering:u,...n.provides.length?{provides:n.provides}:{},...n.model?{model:y(n)}:{}}}async function xn(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};if(L.delete(e.id),delete Me[e.id],e.auto&&Le(e,!0),e.kind==="native")return Ge(e);const r=await M(),i=r.preferred;if(i&&r[i].running){const s=await k(i,["stop",e.container],{timeout:6e4});if(!s.ok&&!/no such container/i.test(s.err))return{ok:!1,error:`${i} stop: ${s.err||s.out}`}}return e.unconfigure(t,A(e)),h(),{ok:!0}}async function _n(n,e){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};if(!r.model)return{ok:!1,error:`${r.label} takes no model`};const i=String(e||"").trim();if(!Wn(n,i))return{ok:!1,error:`not a model id: ${JSON.stringify(e)} — pick one from the list, or a Hugging Face id like owner/name`};const s=await M(),o=s.preferred,a=r.kind==="native"?((await ge()).ramGB||0)*1024:await De(o,s),c=Ze(n,{active:i,engineRamMB:a,engine:r.kind==="native"?"host":o,platform:p,installed:m=>K(r,m)}).find(m=>m.id===i);if(c?.unavailable)return{ok:!1,error:`${i} ${c.unavailable}`};t.runtime=t.runtime||{services:{}},t.runtime.services=t.runtime.services||{},t.runtime.services[n]={...t.runtime.services[n]||{},model:i};const u=A(r);r.configured(t)===u&&r.configure(t,u,Z(r)),h();const d=await Ke(r,o,s);return d.ok?{ok:!0,model:i,restarted:d.restarted,...c?.ramNote?{note:c.ramNote}:{}}:d}async function Ke(n,e,r){if(n.kind==="native"){if(ke(n)!=="running")return{ok:!0,restarted:!1};Ge(n);const o=await ie(n);return o.ok?{ok:!0,restarted:!0}:o}if(!e||!r[e].running)return{ok:!0,restarted:!1};const i=await Xe(e,n.container);if(i==="absent")return{ok:!0,restarted:!1};const s=await k(e,["rm","-f",n.container],{timeout:6e4});if(!s.ok&&!/no such container/i.test(s.err))return{ok:!1,error:`${e} rm: ${s.err||s.out}`};if(i==="running"){const o=await ze(n.id);return o.ok?{ok:!0,restarted:!0}:o}return{ok:!0,restarted:!1}}async function En(n,e){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};if(!J(r))return{ok:!1,error:`${r.label} takes no profile`};const i=await M(),s=await T(i.preferred),o=r.engineOf?r.engineOf(s):null,a=tn(r.id,t.runtime?.services?.[n]?.tunings,G(r,y(r),o,s)).find(u=>u.id===e);if(!a)return{ok:!1,error:`no profile ${JSON.stringify(e)} — one of speed, coding, long, xl`};if(!a.fits)return{ok:!1,error:`${a.label}: ${a.why}`};const c=await Qe(n,a.patch);return c.ok?{...c,profile:a.id}:c}async function Pn(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};if(e.kind!=="native")return{ok:!1,error:`${e.label} is a container — its image is pulled or built on Start`};if(!H(e))return{ok:!1,error:`${e.label} runs on ${re(e)} only`};const r=b[e.id];if(r&&!r.done)return{ok:!0,pending:{kind:r.kind,since:r.since,detail:r.detail||null}};if(delete q[e.runner],await C(e.runner,e.runnerCheck))return{ok:!0,installed:!0};const s=e.engineOf(await T(null))?.install;if(!s?.steps?.length)return{ok:!1,error:`no installer for ${e.label} on this platform${s?.url?` — see ${s.url}`:""}`,install:s||null};const o=be(e,"install",{detail:e.runner});return o.then=Ue("install",o,async()=>{const a=async d=>{for(const[m,...w]of d){O(o,`$ ${m} ${w.join(" ")}`);let g=await ae(o,m,w,{timeout:36e5});for(let $=0;!g.ok&&!o.cancelled&&$<6&&o.lines.some(R=>/already locked|Please wait for it to finish/i.test(R));$++)O(o,`another ${m} holds the lock — waiting 20 s (${$+1}/6)`),await me(2e4),g=await ae(o,m,w,{timeout:36e5});if(!g.ok)return{ok:!1,error:g.error||`${m} exited ${g.code}`}}return{ok:!0}};let c=await a(s.steps);!c.ok&&!o.cancelled&&s.fallback?.length&&(O(o,`${c.error} — trying the other way`),c=await a(s.fallback)),delete q[e.runner];const u=c.ok&&await C(e.runner,e.runnerCheck);o.done=!0,o.cancelled?o.error="cancelled":c.ok?u||(o.error=`${e.runner} still not found after the install — open a new terminal and run \`${s.command}\` by hand`):o.error=`install failed: ${c.error}${o.lines.length?` (${o.lines.slice(-2).join(" | ")})`:""}`,E(`[runtime] install ${e.runner}: ${o.error||"ok"}`)}),{ok:!0,pending:{kind:o.kind,since:o.since,detail:o.detail}}}async function On(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};if(!e.pull)return{ok:!1,error:`${e.label} fetches its own model on the first start`};const r=b[e.id];if(r&&!r.done)return{ok:!0,pending:{kind:r.kind,since:r.since,detail:r.detail||null}};if(K(e,y(e)))return{ok:!0,installed:!0,model:y(e)};const i=be(e,"pull-model",{detail:y(e)});return i.then=(async()=>{const s=await He(e,i);i.done=!0,s.ok||(i.error=s.error)})(),{ok:!0,pending:{kind:i.kind,since:i.since,detail:i.detail}}}async function Qe(n,e){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};if(!J(r))return{ok:!1,error:`${r.label} takes no tunings`};if(!e||typeof e!="object"||Array.isArray(e))return{ok:!1,error:"tunings: an object of { id: value }"};const i=await M(),s=i.preferred,o=y(r),a=await T(s),c=r.engineOf?r.engineOf(a):null,u=Yn(r.id,t.runtime?.services?.[n]?.tunings,e,G(r,o,c,a));if(u.error)return{ok:!1,error:u.error};t.runtime=t.runtime||{services:{}},t.runtime.services=t.runtime.services||{},t.runtime.services[n]={...t.runtime.services[n]||{},tunings:u},h();const d=await Ke(r,s,i);return d.ok?{ok:!0,tunings:nn(r.id,u,G(r,o,c,a)),restarted:d.restarted}:d}async function Nn(){const n=await M(),e=n.preferred,r=e&&n[e].running?await ve(e,j.filter(o=>o.kind!=="native").map(o=>o.container)):{},i={};let s=!1;return await Promise.all(j.map(async o=>{const a=o.kind==="native"?ke(o):e&&n[e].running?r[o.container]||"absent":"no-engine";i[o.id]=a==="running"&&await o.answers(A(o),N)?"up":"down";const c=(o.provides||[]).some(u=>["embedded","none"].includes(t.capabilities?.[u]?.provider));i[o.id]==="up"&&o.configure&&!c&&o.configured(t)!==A(o)&&(o.configure(t,A(o),Z(o)),s=!0)})),s&&h(),i}function Ve(n){const e=x(n);if(e?.window)return e.window;if(!e||!J(e))return null;const r=Number(rn(e.id,t.runtime?.services?.[n]?.tunings,G(e,y(e),null,{})).maxModelLen);return Number.isFinite(r)&&r>0?r:null}function Bn(n){const e=x(n);if(e?.card)return e.card;if(!e||!J(e))return null;const r=y(e),i=rn(e.id,t.runtime?.services?.[n]?.tunings,G(e,r,null,{})),s=se(e.id).find(a=>a.id===r)||null,o=e.id==="vllm"?te(r):"chat";return{engine:e.id,backend:D[e.id]?.backend||null,where:"this machine",egress:"none",cost:"free",task:o,window:Number(i.maxModelLen)>0?Number(i.maxModelLen):null,vision:o==="chat"&&!!i.vision,tools:!!(o==="chat"&&(e.id==="llama"||i.toolCalls&&i.toolCalls!=="off")),reasoning:o==="chat"&&!!i.reasoning&&i.reasoning!=="off",...s?{tier:s.tier||null,licence:s.licence||null,languages:s.lang||null,label:s.label||null}:{},draft:!!(i.speculative&&i.speculative!=="off")}}const Cn=10,qe=()=>{const n=Number(t.runtime?.idleMinutes);return(Number.isFinite(n)&&n>=0?n:Cn)*6e4},Ln=fe(),Me={},L=new Set,ee={};function xe(n){Me[n]=fe()}async function Tn(n,{force:e=!1}={}){const r=x(n);if(!r||!r.helper)return{ok:!0};if(xe(r.id),!L.has(r.id)&&!e){const i=r.container&&r.configured?.(t)?(await je()).find(s=>s.name===r.container):null;if(!i||i.state==="running")return{ok:!0,awake:!0};L.add(r.id)}return ee[r.id]||(ee[r.id]=(async()=>{const i=await M(),s=i.preferred;if(!s)return{ok:!1,error:"no container engine"};if(!i[s].running){const a=await $e(s);if(!a.ok)return a}const o=await Ae(r,s);return o.ok&&(L.delete(r.id),E(`[runtime] ${r.label}: woken for a request`)),o})().finally(()=>{delete ee[r.id]})),ee[r.id]}async function Ye(){const n=qe();if(!n)return[];const e=j.filter(a=>a.helper&&a.configured(t)&&!L.has(a.id)&&!ee[a.id]&&!(b[a.id]&&!b[a.id].done)&&fe()-(Me[a.id]??Ln)>=n);if(!e.length)return[];const r=await M(),i=r.preferred;if(!i||!r[i].running){for(const a of e)L.add(a.id);return e.map(a=>a.id)}const s=await ve(i,e.map(a=>a.container)),o=[];for(const a of e){if(s[a.container]==="running"){if(!(await k(i,["stop",a.container],{timeout:6e4})).ok)continue;E(`[runtime] ${a.label}: asleep after ${Math.round(n/6e4)} min without a request — the next one starts it`)}L.add(a.id),o.push(a.id)}return o}return Ce&&Ce(()=>{Ye().catch(n=>E(`[runtime] idle sweep: ${n.message}`))},6e4),{touch:xe,wake:Tn,sweepIdle:Ye,health:Nn,contextWindow:Ve,modelCard:Bn,async status(){const[n,e,r,i,s]=await Promise.all([l().catch(()=>null),M(),We(),je(),Sn()]);return{machine:s,sandbox:n?.sandbox||null,processes:{all:[...Array.isArray(n?.processes)?n.processes:[],...f()],localMcp:Array.isArray(n?.localMcp)?n.localMcp:[],warm:n?.warm||null},containers:i,refused:Array.isArray(n?.sandbox?.refused)?n.sandbox.refused:[],bridge:n?{ok:!0,version:n.version||""}:{ok:!1},engines:e,services:r}},startEngine:$e,startService:ze,stopService:xn,ensureDefaults:gn,revive:kn,plan:Re,setModel:_n,setTunings:Qe,setProfile:En,pullModel:On,installRunner:Pn,cancelJob:Mn,services:We,catalogFor:se}}export{ht as SEARXNG_DEFAULT_ENGINES,j as SERVICES,cn as containerRow,Lt as createRuntime,Oe as installDoor,kt as searxngSettings};
|
|
6
|
+
`).map(o=>o.split(" ")).filter(o=>o[0]).map(([o,a])=>[o,/running/i.test(a||"")?"running":"stopped"]));for(const o of e)i[o]=s.get(o)||"absent";return i}const A=n=>`http://127.0.0.1:${n.port}`;async function We(){const n=await M(),e=n.preferred,r=await De(e,n),i={},s=await G(e),o=e&&n[e].running?await ve(e,X.filter(a=>a.kind!=="native").map(a=>a.container)):{};for(const a of X){const d=A(a);let u="no-engine";a.kind==="native"?u=ke(a):e&&n[e].running?u=o[a.container]||"absent":e&&(u="engine-stopped");const c=a.model?y(a):null,m=a.engineOf?a.engineOf(s):null,w=a.kind==="native"?(s.ramGB||0)*1024:r;i[a.id]={...pt(a),engine:a.kind==="native"?"host":e,state:u,url:d,configured:a.configured(t),answering:u==="running"?await a.answers(d,B):!1,...a.helper?{asleep:T.has(a.id),idleMinutes:qe()/6e4}:{},...m?{engineFor:{backend:m.backend,kind:m.kind,image:m.image||null,...m.runner?{runner:m.runner}:{},why:m.why,...m.for?{for:m.for}:{},...m.speed?{speed:m.speed}:{},...m.notFor?{notFor:m.notFor}:{},...m.warn?{warn:m.warn}:{},...m.install?{install:m.install}:{}}}:{},...a.kind==="native"&&!R(a)?{why:`${a.label} runs on ${re(a)} only`}:{},...a.auto&&u!=="running"&&R(a)?{auto:!0,...we(a)?{why:"Stopped here — Start turns it back on"}:O[a.id]?{why:O[a.id]}:{}}:a.auto?{auto:!0}:{},...!a.auto&&a.kind==="native"&&u!=="running"&&R(a)&&O[a.id]?{why:O[a.id]}:{},...a.kind==="native"&&j[a.id]?{sandbox:j[a.id]}:{},...b[a.id]?{job:{kind:b[a.id].kind,since:b[a.id].since,detail:b[a.id].detail||null,step:b[a.id].step||null,minutes:b[a.id].minutes||null,progress:b[a.id].progress,lines:b[a.id].lines.slice(-4),done:b[a.id].done,error:b[a.id].error,waiting:!!b[a.id].waiting,cancelled:!!b[a.id].cancelled}}:{},...J(a)?{profiles:tn(a.id,t.runtime?.services?.[a.id]?.tunings,I(a,c,m,s)),docs:Zn[a.id]||null}:{},...a.model&&a.kind==="native"?{recommend:bn(a,s)}:{},...a.model?{model:c,default:a.model,models:Ze(a.id,{active:c,engineRamMB:w,engine:a.kind==="native"?"host":e,platform:p,installed:g=>K(a,g)}),machine:{engineRamMB:w}}:{},...J(a)?{tunings:nn(a.id,t.runtime?.services?.[a.id]?.tunings,I(a,c,m,s))}:{}}}return i}async function Sn(){const n=await M(),e=await G(n.preferred);return{platform:p,arch:H,accelerator:e.accelerator,vllmOnPath:e.vllmOnPath,llamaOnPath:e.llamaOnPath,mlxOnPath:e.mlxOnPath,ramGB:e.ramGB,cores:e.cores,perfCores:e.perfCores,recommend:Qn(e)}}function Je(n,{settingsFile:e=null,secret:r=null,pick:i=null,cpus:s=null}={}){const o=Z(n),a=["run","-d","--name",o.container,"--restart","no","-p",`127.0.0.1:${o.port}:${o.containerPort}`];o.helper&&s&&a.push("--cpus",String(s));for(const u of o.volumes?o.volumes(_):[])a.push("-v",u);e&&a.push("-v",`${e}:/etc/searxng/settings.yml:ro`);for(const u of o.env?o.env(o):[])a.push("-e",u);o.helper&&s&&a.push("-e",`THREADS=${s}`),r&&a.push("-e",`SEARXNG_SECRET=${r}`,"-e",`SEARXNG_BASE_URL=http://127.0.0.1:${o.port}/`),a.push("--cap-drop","ALL");for(const u of o.caps||[])a.push("--cap-add",u);i?.devices?.length&&a.push(...i.devices),a.push(i?.image||o.image,...o.args?o.args(o,i):[]);const d=Xn("sha1").update(JSON.stringify(a.filter(u=>!String(u).startsWith("SEARXNG_SECRET=")))).digest("hex").slice(0,12);return a.splice(2,0,"--label",`chatpanel.run=${d}`),{args:a,hash:d}}const Se={};async function An(n){if(Se[n]==null){const e=await k(n,["info","--format",n==="docker"?"{{.NCPU}}":"{{.Host.CPUs}}"],{timeout:8e3}),r=Number.parseInt(e.out,10);Se[n]=Number.isFinite(r)&&r>0?r:Q.cpus()?.length||2}return Math.max(1,Math.floor(Se[n]/2))}async function ze(n,{force:e=!1}={}){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};T.delete(r.id),xe(r.id),r.auto&&we(r)&&Le(r,!1);const i=b[r.id];if(i&&!i.done)return{ok:!0,pending:{kind:i.kind,since:i.since,detail:i.detail||null}};let s=null;if(r.kind!=="native"){const c=await M();if(s=c.preferred,!s)return{ok:!1,error:"no container engine — install Podman first",install:Oe(p)};if(!c[s].running){const m=await $e(s);if(!m.ok)return m}}else if(!R(r))return{ok:!1,error:`${r.label} runs on ${re(r)} only`};const o=await G(s),a=r.engineOf?r.engineOf(o):null;if(r.kind==="native"&&!await L(r.runner,r.runnerCheck))return{ok:!1,error:`\`${r.runner}\` is not on PATH — install it first (${a?.install?.command||""}), or click Install`,install:a?.install};if(r.model&&/\.gguf$/i.test(y(r))&&!Ee(y(r)))return{ok:!1,error:`no such file: ${y(r)}`};if(r.kind==="native"&&r.model&&!e){const c=await Re(r.id);if(c.live&&!c.fits)return{ok:!1,error:c.advice,plan:c}}const d=await vn(r,s,a);if(!d.length){if(delete b[r.id],r.kind!=="native")return Ae(r,s);const c=await ie(r);return c.ok?delete O[r.id]:O[r.id]=c.error,c}const u=be(r,d[0]==="image"?"pull-image":"pull-model",{detail:d[0]==="image"?a?.image||r.image:y(r)});return u.then=(async()=>{try{if(d.includes("image")){const m=await $n(s,a,r,u);if(!m.ok)throw new Error(m.error)}if(d.includes("model")){const m=await He(r,u);if(!m.ok)throw new Error(m.error)}u.kind="starting",u.detail=r.label;const c=r.kind==="native"?await ie(r):await Ae(r,s);if(!c.ok)throw new Error(c.error);u.done=!0,u.result=c,E(`[runtime] ${r.label}: ready after ${Math.round((Date.now()-u.since)/1e3)} s`)}catch(c){u.done=!0,u.error=u.cancelled?"cancelled":c.message,E(`[runtime] ${r.label}: ${u.error}`)}})(),{ok:!0,pending:{kind:u.kind,since:u.since,detail:u.detail}}}function Mn(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};const r=b[e.id];if(!r||r.done)return{ok:!0,nothing:!0};if(r.cancelled=!0,r.child){try{r.child.kill("SIGTERM")}catch{}const i=r.child;setTimeout(()=>{try{i.kill("SIGKILL")}catch{}},5e3).unref?.()}return N(r,"cancelled"),E(`[runtime] ${e.label}: job cancelled (${r.kind})`),{ok:!0,cancelled:r.kind}}async function Ae(n,e){let r=await Xe(e,n.container);const i=n.helper?await An(e):null,s=n.engineOf?n.engineOf(await G(e)):null,o=n.id==="searxng"?v.join(_,"searxng-settings.yml"):null,a=Je(n,{settingsFile:o,secret:n.id==="searxng"?"x":null,pick:s,cpus:i});if(r!=="absent"){const c=await k(e,["inspect","--format",'{{index .Config.Labels "chatpanel.run"}}',n.container],{timeout:8e3});(!c.ok||c.out!==a.hash)&&(E(`[runtime] ${n.label}: made with older settings — re-creating it`),await k(e,["rm","-f",n.container],{timeout:6e4}),r="absent")}if(r!=="running")if(r==="stopped"){const c=await k(e,["start",n.container],{timeout:6e4});if(!c.ok)return{ok:!1,error:`${e} start: ${c.err||c.out}`}}else{ne(_,{recursive:!0,mode:448});let c=null;n.id==="searxng"&&(oe(o,kt(String(t.search?.searxng?.engines||"").split(",").map(g=>g.trim()).filter(Boolean)),{mode:384}),c=jn(32).toString("hex")),n.volumes&&ne(v.join(_,V),{recursive:!0,mode:448});const{args:m}=Je(n,{settingsFile:o,secret:c,pick:s,cpus:i});E(`[runtime] ${e} ${m.filter(g=>!g.startsWith("SEARXNG_SECRET")).join(" ")}`);const w=await k(e,m,{timeout:6e5});if(!w.ok)return{ok:!1,error:`${e} run: ${w.err||w.out}`}}const d=A(n);let u=!1;for(let c=0;c<30&&!u;c++)u=await n.answers(d,B),u||await me(1e3);return n.configure(t,d,Z(n)),h(),{ok:!0,url:d,answering:u,...n.provides.length?{provides:n.provides}:{},...n.model?{model:y(n)}:{}}}async function xn(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};if(T.delete(e.id),delete Me[e.id],e.auto&&Le(e,!0),e.kind==="native")return Ge(e);const r=await M(),i=r.preferred;if(i&&r[i].running){const s=await k(i,["stop",e.container],{timeout:6e4});if(!s.ok&&!/no such container/i.test(s.err))return{ok:!1,error:`${i} stop: ${s.err||s.out}`}}return e.unconfigure(t,A(e)),h(),{ok:!0}}async function _n(n,e){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};if(!r.model)return{ok:!1,error:`${r.label} takes no model`};const i=String(e||"").trim();if(!Wn(n,i))return{ok:!1,error:`not a model id: ${JSON.stringify(e)} — pick one from the list, or a Hugging Face id like owner/name`};const s=await M(),o=s.preferred,a=r.kind==="native"?((await ge()).ramGB||0)*1024:await De(o,s),d=Ze(n,{active:i,engineRamMB:a,engine:r.kind==="native"?"host":o,platform:p,installed:m=>K(r,m)}).find(m=>m.id===i);if(d?.unavailable)return{ok:!1,error:`${i} ${d.unavailable}`};t.runtime=t.runtime||{services:{}},t.runtime.services=t.runtime.services||{},t.runtime.services[n]={...t.runtime.services[n]||{},model:i};const u=A(r);r.configured(t)===u&&r.configure(t,u,Z(r)),h();const c=await Ke(r,o,s);return c.ok?{ok:!0,model:i,restarted:c.restarted,...d?.ramNote?{note:d.ramNote}:{}}:c}async function Ke(n,e,r){if(n.kind==="native"){if(ke(n)!=="running")return{ok:!0,restarted:!1};Ge(n);const o=await ie(n);return o.ok?{ok:!0,restarted:!0}:o}if(!e||!r[e].running)return{ok:!0,restarted:!1};const i=await Xe(e,n.container);if(i==="absent")return{ok:!0,restarted:!1};const s=await k(e,["rm","-f",n.container],{timeout:6e4});if(!s.ok&&!/no such container/i.test(s.err))return{ok:!1,error:`${e} rm: ${s.err||s.out}`};if(i==="running"){const o=await ze(n.id);return o.ok?{ok:!0,restarted:!0}:o}return{ok:!0,restarted:!1}}async function En(n,e){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};if(!J(r))return{ok:!1,error:`${r.label} takes no profile`};const i=await M(),s=await G(i.preferred),o=r.engineOf?r.engineOf(s):null,a=tn(r.id,t.runtime?.services?.[n]?.tunings,I(r,y(r),o,s)).find(u=>u.id===e);if(!a)return{ok:!1,error:`no profile ${JSON.stringify(e)} — one of speed, coding, long, xl`};if(!a.fits)return{ok:!1,error:`${a.label}: ${a.why}`};const d=await Qe(n,a.patch);return d.ok?{...d,profile:a.id}:d}async function Pn(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};if(e.kind!=="native")return{ok:!1,error:`${e.label} is a container — its image is pulled or built on Start`};if(!R(e))return{ok:!1,error:`${e.label} runs on ${re(e)} only`};const r=b[e.id];if(r&&!r.done)return{ok:!0,pending:{kind:r.kind,since:r.since,detail:r.detail||null}};if(delete q[e.runner],await L(e.runner,e.runnerCheck))return{ok:!0,installed:!0};const s=e.engineOf(await G(null))?.install;if(!s?.steps?.length)return{ok:!1,error:`no installer for ${e.label} on this platform${s?.url?` — see ${s.url}`:""}`,install:s||null};const o=be(e,"install",{detail:e.runner});return o.then=Ue("install",o,async()=>{const a=async c=>{for(const[m,...w]of c){N(o,`$ ${m} ${w.join(" ")}`);let g=await ae(o,m,w,{timeout:36e5});for(let $=0;!g.ok&&!o.cancelled&&$<6&&o.lines.some(U=>/already locked|Please wait for it to finish/i.test(U));$++)N(o,`another ${m} holds the lock — waiting 20 s (${$+1}/6)`),await me(2e4),g=await ae(o,m,w,{timeout:36e5});if(!g.ok)return{ok:!1,error:g.error||`${m} exited ${g.code}`}}return{ok:!0}};let d=await a(s.steps);!d.ok&&!o.cancelled&&s.fallback?.length&&(N(o,`${d.error} — trying the other way`),d=await a(s.fallback)),delete q[e.runner];const u=d.ok&&await L(e.runner,e.runnerCheck);o.done=!0,o.cancelled?o.error="cancelled":d.ok?u||(o.error=`${e.runner} still not found after the install — open a new terminal and run \`${s.command}\` by hand`):o.error=`install failed: ${d.error}${o.lines.length?` (${o.lines.slice(-2).join(" | ")})`:""}`,E(`[runtime] install ${e.runner}: ${o.error||"ok"}`)}),{ok:!0,pending:{kind:o.kind,since:o.since,detail:o.detail}}}async function On(n){const e=x(n);if(!e)return{ok:!1,error:`unknown service ${n}`};if(!e.pull)return{ok:!1,error:`${e.label} fetches its own model on the first start`};const r=b[e.id];if(r&&!r.done)return{ok:!0,pending:{kind:r.kind,since:r.since,detail:r.detail||null}};if(K(e,y(e)))return{ok:!0,installed:!0,model:y(e)};const i=be(e,"pull-model",{detail:y(e)});return i.then=(async()=>{const s=await He(e,i);i.done=!0,s.ok||(i.error=s.error)})(),{ok:!0,pending:{kind:i.kind,since:i.since,detail:i.detail}}}async function Qe(n,e){const r=x(n);if(!r)return{ok:!1,error:`unknown service ${n}`};if(!J(r))return{ok:!1,error:`${r.label} takes no tunings`};if(!e||typeof e!="object"||Array.isArray(e))return{ok:!1,error:"tunings: an object of { id: value }"};const i=await M(),s=i.preferred,o=y(r),a=await G(s),d=r.engineOf?r.engineOf(a):null,u=Yn(r.id,t.runtime?.services?.[n]?.tunings,e,I(r,o,d,a));if(u.error)return{ok:!1,error:u.error};t.runtime=t.runtime||{services:{}},t.runtime.services=t.runtime.services||{},t.runtime.services[n]={...t.runtime.services[n]||{},tunings:u},h();const c=await Ke(r,s,i);return c.ok?{ok:!0,tunings:nn(r.id,u,I(r,o,d,a)),restarted:c.restarted}:c}async function Nn(){const n=await M(),e=n.preferred,r=e&&n[e].running?await ve(e,X.filter(o=>o.kind!=="native").map(o=>o.container)):{},i={};let s=!1;return await Promise.all(X.map(async o=>{const a=o.kind==="native"?ke(o):e&&n[e].running?r[o.container]||"absent":"no-engine";i[o.id]=a==="running"&&await o.answers(A(o),B)?"up":"down";const d=(o.provides||[]).some(u=>["embedded","none"].includes(t.capabilities?.[u]?.provider));i[o.id]==="up"&&o.configure&&!d&&o.configured(t)!==A(o)&&(o.configure(t,A(o),Z(o)),s=!0)})),s&&h(),i}function Ve(n){const e=x(n);if(e?.window)return e.window;if(!e||!J(e))return null;const r=Number(rn(e.id,t.runtime?.services?.[n]?.tunings,I(e,y(e),null,{})).maxModelLen);return Number.isFinite(r)&&r>0?r:null}function Bn(n){const e=x(n);if(e?.card)return e.card;if(!e||!J(e))return null;const r=y(e),i=rn(e.id,t.runtime?.services?.[n]?.tunings,I(e,r,null,{})),s=se(e.id).find(a=>a.id===r)||null,o=e.id==="vllm"?te(r):"chat";return{engine:e.id,backend:j[e.id]?.backend||null,where:"this machine",egress:"none",cost:"free",task:o,window:Number(i.maxModelLen)>0?Number(i.maxModelLen):null,vision:o==="chat"&&!!i.vision,tools:!!(o==="chat"&&(e.id==="llama"||i.toolCalls&&i.toolCalls!=="off")),reasoning:o==="chat"&&!!i.reasoning&&i.reasoning!=="off",...s?{tier:s.tier||null,licence:s.licence||null,languages:s.lang||null,label:s.label||null}:{},draft:!!(i.speculative&&i.speculative!=="off")}}const Cn=10,qe=()=>{const n=Number(t.runtime?.idleMinutes);return(Number.isFinite(n)&&n>=0?n:Cn)*6e4},Ln=fe(),Me={},T=new Set,ee={};function xe(n){Me[n]=fe()}async function Tn(n,{force:e=!1}={}){const r=x(n);if(!r||!r.helper)return{ok:!0};if(xe(r.id),!T.has(r.id)&&!e){const i=r.container&&r.configured?.(t)?(await je()).find(s=>s.name===r.container):null;if(!i||i.state==="running")return{ok:!0,awake:!0};T.add(r.id)}return ee[r.id]||(ee[r.id]=(async()=>{const i=await M(),s=i.preferred;if(!s)return{ok:!1,error:"no container engine"};if(!i[s].running){const a=await $e(s);if(!a.ok)return a}const o=await Ae(r,s);return o.ok&&(T.delete(r.id),E(`[runtime] ${r.label}: woken for a request`)),o})().finally(()=>{delete ee[r.id]})),ee[r.id]}async function Ye(){const n=qe();if(!n)return[];const e=X.filter(a=>a.helper&&a.configured(t)&&!T.has(a.id)&&!ee[a.id]&&!(b[a.id]&&!b[a.id].done)&&fe()-(Me[a.id]??Ln)>=n);if(!e.length)return[];const r=await M(),i=r.preferred;if(!i||!r[i].running){for(const a of e)T.add(a.id);return e.map(a=>a.id)}const s=await ve(i,e.map(a=>a.container)),o=[];for(const a of e){if(s[a.container]==="running"){if(!(await k(i,["stop",a.container],{timeout:6e4})).ok)continue;E(`[runtime] ${a.label}: asleep after ${Math.round(n/6e4)} min without a request — the next one starts it`)}T.add(a.id),o.push(a.id)}return o}return Ce&&Ce(()=>{Ye().catch(n=>E(`[runtime] idle sweep: ${n.message}`))},6e4),{touch:xe,wake:Tn,sweepIdle:Ye,health:Nn,contextWindow:Ve,modelCard:Bn,async status(){const[n,e,r,i,s]=await Promise.all([l().catch(()=>null),M(),We(),je(),Sn()]);return{machine:s,sandbox:n?.sandbox||null,processes:{all:[...Array.isArray(n?.processes)?n.processes:[],...f()],localMcp:Array.isArray(n?.localMcp)?n.localMcp:[],warm:n?.warm||null},containers:i,refused:Array.isArray(n?.sandbox?.refused)?n.sandbox.refused:[],bridge:n?{ok:!0,version:n.version||""}:{ok:!1},engines:e,services:r}},startEngine:$e,startService:ze,stopService:xn,ensureDefaults:gn,revive:kn,plan:Re,setModel:_n,setTunings:Qe,setProfile:En,pullModel:On,installRunner:Pn,cancelJob:Mn,services:We,catalogFor:se}}export{ht as SEARXNG_DEFAULT_ENGINES,X as SERVICES,cn as containerRow,Lt as createRuntime,Oe as installDoor,kt as searxngSettings};
|
package/src/update.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
-
import U from"node:os";import i from"node:path";import{execFile as A}from"node:child_process";import{chmod as G,rename as L,mkdir as K,readFile as V,writeFile as R,rm as W}from"node:fs/promises";import{existsSync as Y,readFileSync as q,realpathSync as z}from"node:fs";import{restartService as Q,serviceRegistered as y}from"./service.js";const g="@chatpanel/gateway",Et="chatpanel/chatpanel-gateway",j="https://dl.chatpanel.net/version/gateway",E=(process.env.CHATPANEL_NPM_REGISTRY||process.env.npm_config_registry||"https://registry.npmjs.org").replace(/\/$/,""),X=`${E}/${g}/latest`,Z=t=>`https://dl.chatpanel.net/gateway/${t.replace(/^chatpanel-gateway-/,"")}`,D=360*60*1e3,N=600*1e3,tt=Math.max(500,Number(process.env.CHATPANEL_UPDATE_TIMEOUT_MS)||5e3),et=15*6e4,k=20*6e4,_=process.env.CHATPANEL_UPDATE_CACHE||i.join(U.homedir(),".chatpanel","gateway-update-check.json"),S=String(process.env.CHATPANEL_SELF_UPDATE||"").toLowerCase()==="off",O={"User-Agent":"chatpanel-gateway-updater"},nt=new Set(["dl.chatpanel.net","github.com","api.github.com","objects.githubusercontent.com","release-assets.githubusercontent.com"]);function at(t){try{const e=new URL(t);return e.protocol==="https:"&&nt.has(e.hostname)}catch{return!1}}let m={at:0,error:""};function _t(){m={at:0,error:""}}function $(){const t=i.basename(process.execPath).toLowerCase();return!(t.startsWith("node")||t.startsWith("bun"))}function rt(){return process.platform==="darwin"?`chatpanel-gateway-macos-${process.arch==="arm64"?"arm64":"x64"}`:process.platform==="linux"?process.arch==="x64"?"chatpanel-gateway-linux-x64":null:process.platform==="win32"?"chatpanel-gateway-windows-x64.exe":null}function f(t=""){const e=/(\d+(?:\.\d+){0,3})/.exec(t||"");return e?e[1]:null}function H(t,e){const n=String(t).split(".").map(Number),a=String(e).split(".").map(Number);for(let r=0;r<Math.max(n.length,a.length);r+=1){const o=(n[r]||0)-(a[r]||0);if(o)return o>0?1:-1}return 0}async function ot(){try{return JSON.parse(await V(_,"utf8"))}catch{return null}}async function st(t){try{await K(i.dirname(_),{recursive:!0}),await R(_,JSON.stringify(t))}catch{}}async function x(t,e=tt){const n=new AbortController,a=setTimeout(()=>n.abort(),e);try{const r=await fetch(t,{headers:{Accept:"application/json, application/vnd.github+json",...O},signal:n.signal});if(!r.ok)throw new Error(r.status===403&&/github/.test(t)?"GitHub rate limit (60/hour per IP) — try again later":`HTTP ${r.status}`);return await r.json()}catch(r){const o=r?.cause?.code||r?.cause?.message||r?.message||String(r);throw new Error(n.signal.aborted?`the update server did not answer within ${Math.round(e/1e3)}s`:`${new URL(t).hostname}: ${o}`)}finally{clearTimeout(a)}}function T(t=process.argv[1]){let e=t?i.resolve(t):"";try{e=z(e)}catch{}const n=/^(.*[/\\]node_modules[/\\]@chatpanel[/\\]gateway)[/\\]/.exec(e);return n?n[1]:""}function it(){const t=T();if(!t)return"";try{return String(JSON.parse(q(i.join(t,"package.json"),"utf8")).version||"")}catch{return""}}function v(){const t=i.dirname(process.execPath);return[i.join(t,"..","lib","node_modules","npm","bin","npm-cli.js"),i.join(t,"node_modules","npm","bin","npm-cli.js")].find(n=>Y(n))||""}function lt(t=process.env,e=process.execPath){const n={...t,npm_config_registry:E,npm_config_fund:"false",npm_config_audit:"false"};delete n.ELECTRON_RUN_AS_NODE;const a=Object.keys(n).find(r=>r.toLowerCase()==="path")||"PATH";return n[a]=[i.dirname(e),...(n[a]||"").split(i.delimiter).filter(Boolean)].filter((r,o,c)=>c.indexOf(r)===o).join(i.delimiter),n}function ct(){import("./prune-install.js").then(({pruneForeignPrebuilds:t,pruneLine:e})=>{const n=e(t({log:a=>console.log(a)}));n&&console.log(`[update]${n}`)}).catch(()=>{})}function pt(){return["install","-g",`${g}@latest`,"--ignore-scripts"]}function dt(t,{home:e=U.homedir(),platform:n=process.platform}={}){if(n==="win32"||!/\b(EACCES|EPERM)\b/.test(t||""))return"";const a=(t.match(/^npm (?:error|ERR!) path (.+)$/m)||[])[1]?.trim()||"",r=a.indexOf(`${i.sep}lib${i.sep}node_modules`),o=r>0?a.slice(0,r):"";return o?o===e||o.startsWith(e+i.sep)?`npm cannot write ${o} — part of it belongs to another user, usually from an earlier \`sudo npm i -g\` (npm's hint about ~/.npm is a different folder). Fix: sudo chown -R "$(whoami)" "${o}" — then update again.`:`npm cannot write ${o}, which belongs to another user. Install the standalone build instead — it needs no npm: curl -fsSL https://dl.chatpanel.net/install.sh | bash`:""}function ut(){const t=v(),e=lt(),n=pt(),[a,r]=t?[process.execPath,[t,...n]]:["npm",n];return new Promise(o=>{A(a,r,{env:e,timeout:k,maxBuffer:8<<20,windowsHide:!0},(c,d,s)=>{const l=`${d||""}${s||""}`.trim();return c?c.killed&&!l?o({ok:!1,out:`npm was still running after ${Math.round(k/6e4)} minutes and was stopped`}):o({ok:!1,out:l||(t?c.message:"could not run npm: it is not beside the node running this gateway and not on the service's PATH")}):(ct(),o({ok:!0,out:l}))})})}async function M(t,{force:e=!1}={}){const n=$()?"binary":"npm";if(S)return{current:t,latest:null,updateAvailable:!1,mode:n,canSelfUpdate:!1,assetUrl:null,stale:!1,error:"",npmCommand:null,channel:n==="npm"?"npm":"release",service:!1,disabled:!0};const a=rt();let r=null,o=null,c=!1,d="",s=0;const l=await ot(),w=l&&l.mode===n,C=()=>{r=w&&l.latest||null,o=w&&l.assetUrl||null,s=w&&l.checkedAt||0,c=!0};if(!e&&w&&Date.now()-l.checkedAt<D)r=l.latest,o=l.assetUrl,s=l.checkedAt;else if(!e&&m.at&&Date.now()-m.at<N)d=m.error,C();else try{if(n==="npm"){let u;try{u=await x(X),r=f(u.version)}catch(J){const P=await x(j);if(r=f(P?.npm?.version)||f(P?.version),!r)throw J}}else{const u=await x(j);r=f(u.version)||f(u.release?.tag),o=a&&(u.release?.assets||[]).includes(a)?Z(a):null}s=Date.now(),await st({checkedAt:s,mode:n,latest:r,assetUrl:o}),m={at:0,error:""}}catch(u){d=u.message,m={at:Date.now(),error:d},C()}const I=!!r&&H(r,t)>0,F=n==="binary"?!!o&&(process.platform!=="win32"||y()):!!T()&&(process.platform!=="win32"||y()&&!!v()),B=n==="npm"?process.platform==="win32"?`chatpanel-gateway --stop; npm i -g ${g}@latest --ignore-scripts; chatpanel-gateway --install`:`npm i -g ${g}@latest --ignore-scripts`:null;return{current:t,latest:r,updateAvailable:I,mode:n,canSelfUpdate:F,assetUrl:o,stale:c,error:d,npmCommand:B,channel:n==="npm"?"npm":"release",service:y(),checkedAt:s}}let h=null,b=null;function St(t){const e=$()?"binary":"npm";return S?{current:t,latest:null,updateAvailable:!1,mode:e,canSelfUpdate:!1,stale:!1,error:"",npmCommand:null,channel:e==="npm"?"npm":"release",service:!1,disabled:!0}:((!h||(h.stale?!(m.at&&Date.now()-m.at<N):Date.now()-h.seenAt>D))&&!b&&(b=M(t).then(a=>{h={...a,seenAt:Date.now()}}).catch(()=>{}).finally(()=>{b=null})),h?{...h,seenAt:void 0,current:t}:{current:t,latest:null,updateAvailable:!1,mode:e,canSelfUpdate:!1,stale:!0,checking:!0,error:"",npmCommand:null,channel:e==="npm"?"npm":"release",service:y()})}function $t(){h=null,b=null}async function mt(t){const e=process.execPath,n=i.dirname(e),a=i.join(n,`.chatpanel-gateway.new-${Date.now()}`),r=new AbortController,o=setTimeout(()=>r.abort(),et);let c;try{const s=await fetch(t.assetUrl,{headers:O,redirect:"follow",signal:r.signal});if(!s.ok)throw new Error(`download failed (HTTP ${s.status})`);if(!at(s.url||t.assetUrl))throw new Error(`refused: the download was redirected to ${s.url}, which is not a ChatPanel release host`);c=Buffer.from(await s.arrayBuffer())}finally{clearTimeout(o)}if(c.length<5<<20)throw new Error(`the download was only ${(c.length/1024).toFixed(0)} KB — that is not the gateway, so nothing was replaced`);await R(a,c),process.platform!=="win32"&&await G(a,493),process.platform==="darwin"&&await new Promise(s=>A("xattr",["-c",a],()=>s()));const d=await new Promise(s=>A(a,["--version"],{timeout:6e4,windowsHide:!0},(l,w)=>s(l?"":String(w||"").trim())));if(!f(d))throw await W(a,{force:!0}),new Error("the downloaded gateway would not run, so it was discarded");return process.platform==="win32"&&await L(e,i.join(n,`chatpanel-gateway.old-${Date.now()}.exe`)),await L(a,e),f(d)}async function ft(t){if(S)throw new Error("Self-update is switched off on this gateway (CHATPANEL_SELF_UPDATE=off).");const e=await M(t,{force:!0});if(e.stale)throw new Error(`Could not reach the update server${e.error?` (${e.error})`:""}. Refusing to act on a stale check — try again in a few minutes.`);if(!e.updateAvailable)throw new Error(`Already on the latest ${e.channel} version (v${t}).`);if(!e.canSelfUpdate)throw new Error(e.mode==="npm"?`This gateway cannot update itself here. Run: ${e.npmCommand}`:"No downloadable build for this platform — install it with npm instead.");if(e.mode==="binary")return{from:t,to:await mt(e),mode:"binary"};if(process.platform==="win32")return{from:t,to:e.latest,mode:"npm",deferred:`"${process.execPath}" "${v()}" install -g ${g}@latest --registry=${E} --no-fund --no-audit`};const n=await ut();if(!n.ok){const r=dt(n.out);throw new Error(r?`${r}
|
|
1
|
+
import R from"node:os";import l from"node:path";import{execFile as S}from"node:child_process";import{chmod as q,rename as L,mkdir as z,readFile as Q,writeFile as I,rm as X}from"node:fs/promises";import{existsSync as Z,readFileSync as ee,realpathSync as te}from"node:fs";import{explainInstallFailure as y,adviceText as x,npmInstallCommand as ne}from"@chatpanel/events/install-advice.js";import{restartService as ae,serviceRegistered as b}from"./service.js";const A="@chatpanel/gateway",Oe="chatpanel/chatpanel-gateway",H="https://dl.chatpanel.net/version/gateway",_=(process.env.CHATPANEL_NPM_REGISTRY||process.env.npm_config_registry||"https://registry.npmjs.org").replace(/\/$/,""),se=`${_}/${A}/latest`,re=e=>`https://dl.chatpanel.net/gateway/${e.replace(/^chatpanel-gateway-/,"")}`,F=360*60*1e3,M=600*1e3,oe=Math.max(500,Number(process.env.CHATPANEL_UPDATE_TIMEOUT_MS)||5e3),ie=15*6e4,B=20*6e4,T=process.env.CHATPANEL_UPDATE_CACHE||l.join(R.homedir(),".chatpanel","gateway-update-check.json"),C=String(process.env.CHATPANEL_SELF_UPDATE||"").toLowerCase()==="off",J={"User-Agent":"chatpanel-gateway-updater"},le=new Set(["dl.chatpanel.net","github.com","api.github.com","objects.githubusercontent.com","release-assets.githubusercontent.com"]);function ce(e){try{const t=new URL(e);return t.protocol==="https:"&&le.has(t.hostname)}catch{return!1}}let f={at:0,error:""};function Ue(){f={at:0,error:""}}function P(){const e=l.basename(process.execPath).toLowerCase();return!(e.startsWith("node")||e.startsWith("bun"))}function de(){return process.platform==="darwin"?`chatpanel-gateway-macos-${process.arch==="arm64"?"arm64":"x64"}`:process.platform==="linux"?process.arch==="x64"?"chatpanel-gateway-linux-x64":null:process.platform==="win32"?"chatpanel-gateway-windows-x64.exe":null}function h(e=""){const t=/(\d+(?:\.\d+){0,3})/.exec(e||"");return t?t[1]:null}function G(e,t){const n=String(e).split(".").map(Number),s=String(t).split(".").map(Number);for(let a=0;a<Math.max(n.length,s.length);a+=1){const r=(n[a]||0)-(s[a]||0);if(r)return r>0?1:-1}return 0}async function pe(){try{return JSON.parse(await Q(T,"utf8"))}catch{return null}}async function ue(e){try{await z(l.dirname(T),{recursive:!0}),await I(T,JSON.stringify(e))}catch{}}async function N(e,t=oe){const n=new AbortController,s=setTimeout(()=>n.abort(),t);try{const a=await fetch(e,{headers:{Accept:"application/json, application/vnd.github+json",...J},signal:n.signal});if(!a.ok)throw new Error(a.status===403&&/github/.test(e)?"GitHub rate limit (60/hour per IP) — try again later":`HTTP ${a.status}`);return await a.json()}catch(a){const r=a?.cause?.code||a?.cause?.message||a?.message||String(a);throw new Error(n.signal.aborted?`the update server did not answer within ${Math.round(t/1e3)}s`:`${new URL(e).hostname}: ${r}`)}finally{clearTimeout(s)}}function k(e=process.argv[1]){let t=e?l.resolve(e):"";try{t=te(t)}catch{}const n=/^(.*[/\\]node_modules[/\\]@chatpanel[/\\]gateway)[/\\]/.exec(t);return n?n[1]:""}function me(){const e=k();if(!e)return"";try{return String(JSON.parse(ee(l.join(e,"package.json"),"utf8")).version||"")}catch{return""}}function E(){const e=l.dirname(process.execPath);return[l.join(e,"..","lib","node_modules","npm","bin","npm-cli.js"),l.join(e,"..","libexec","lib","node_modules","npm","bin","npm-cli.js"),l.join(e,"node_modules","npm","bin","npm-cli.js")].find(n=>Z(n))||""}function fe(e=process.env,t=process.execPath){const n={...e,npm_config_registry:_,npm_config_fund:"false",npm_config_audit:"false"};delete n.ELECTRON_RUN_AS_NODE;const s=Object.keys(n).find(a=>a.toLowerCase()==="path")||"PATH";return n[s]=[l.dirname(t),...(n[s]||"").split(l.delimiter).filter(Boolean)].filter((a,r,c)=>c.indexOf(a)===r).join(l.delimiter),n}function he(){import("./prune-install.js").then(({pruneForeignPrebuilds:e,pruneLine:t})=>{const n=t(e({log:s=>console.log(s)}));n&&console.log(`[update]${n}`)}).catch(()=>{})}function we(){return["install","-g",`${A}@latest`,"--ignore-scripts"]}function ge(e,{home:t=R.homedir(),platform:n=process.platform}={}){if(n==="win32"||!/\b(EACCES|EPERM)\b/.test(e||""))return"";const s=(e.match(/^npm (?:error|ERR!) path (.+)$/m)||[])[1]?.trim()||"",a=s.indexOf(`${l.sep}lib${l.sep}node_modules`),r=a>0?s.slice(0,a):"";return r?r===t||r.startsWith(t+l.sep)?`npm cannot write ${r} — part of it belongs to another user, usually from an earlier \`sudo npm i -g\` (npm's hint about ~/.npm is a different folder). Fix: sudo chown -R "$(whoami)" "${r}" — then update again.`:`npm cannot write ${r}, which belongs to another user. Install the standalone build instead — it needs no npm: curl -fsSL https://dl.chatpanel.net/install.sh | bash`:""}function ye(e=process.allowedNodeEnvironmentFlags){try{return!process.versions.bun&&e.has("--use-system-ca")}catch{return!1}}function be({cli:e=E(),systemCa:t=!1,env:n=fe(),execPath:s=process.execPath}={}){const a=we();return e?{cmd:s,args:[...t?["--use-system-ca"]:[],e,...a],env:n}:{cmd:"npm",args:a,env:t?{...n,NODE_OPTIONS:`${n.NODE_OPTIONS?`${n.NODE_OPTIONS} `:""}--use-system-ca`}:n}}function Ae({systemCa:e=!1}={}){const t=E(),{cmd:n,args:s,env:a}=be({cli:t,systemCa:e});return new Promise(r=>{S(n,s,{env:a,timeout:B,maxBuffer:8<<20,windowsHide:!0},(c,u,o)=>{const i=`${u||""}${o||""}`.trim();return c?c.killed&&!i?r({ok:!1,out:`npm was still running after ${Math.round(B/6e4)} minutes and was stopped`}):r({ok:!1,out:i||(t?c.message:"could not run npm: it is not beside the node running this gateway and not on the service's PATH")}):(he(),r({ok:!0,out:i}))})})}async function Ee({run:e=Ae,canSystemCa:t=ye()}={}){const n=await e({systemCa:!1});if(n.ok||!t||y(n.out)?.kind!=="certificate")return n;console.log("[update] npm refused the registry's certificate (a re-signing proxy) — trying once more with the system's certificates");const s=await e({systemCa:!0});return s.ok?{...s,via:"system-ca"}:s}function ve(e,t=process.versions.node,n=process.platform){return!e||process.versions.bun?null:y("",{node:t,needsNode:e,platform:n})}async function W(e,{force:t=!1}={}){const n=P()?"binary":"npm";if(C)return{current:e,latest:null,updateAvailable:!1,mode:n,canSelfUpdate:!1,assetUrl:null,stale:!1,error:"",npmCommand:null,channel:n==="npm"?"npm":"release",service:!1,disabled:!0};const s=de();let a=null,r=null,c=!1,u="",o=0,i="";const d=await pe(),g=d&&d.mode===n,U=()=>{a=g&&d.latest||null,r=g&&d.assetUrl||null,o=g&&d.checkedAt||0,i=g&&d.needsNode||"",c=!0};if(!t&&g&&Date.now()-d.checkedAt<F)a=d.latest,r=d.assetUrl,o=d.checkedAt,i=d.needsNode||"";else if(!t&&f.at&&Date.now()-f.at<M)u=f.error,U();else try{if(n==="npm"){let m;try{m=await N(se),a=h(m.version),i=String(m.engines?.node||"")}catch(Y){const D=await N(H);if(a=h(D?.npm?.version)||h(D?.version),!a)throw Y}}else{const m=await N(H);a=h(m.version)||h(m.release?.tag),r=s&&(m.release?.assets||[]).includes(s)?re(s):null}o=Date.now(),await ue({checkedAt:o,mode:n,latest:a,assetUrl:r,needsNode:i}),f={at:0,error:""}}catch(m){u=m.message,f={at:Date.now(),error:u},U()}const j=!!a&&G(a,e)>0,$=n==="npm"&&j?ve(i):null,K=$?!1:n==="binary"?!!r&&(process.platform!=="win32"||b()):!!k()&&(process.platform!=="win32"||b()&&!!E()),V=n==="npm"?ne({pkg:A,platform:process.platform}):null;return{current:e,latest:a,updateAvailable:j,mode:n,canSelfUpdate:K,assetUrl:r,stale:c,error:u,npmCommand:V,channel:n==="npm"?"npm":"release",service:b(),checkedAt:o,...n==="npm"?{node:process.versions.node,...i?{needsNode:i}:{}}:{},...$?{blocked:$}:{}}}let w=null,v=null;function je(e){const t=P()?"binary":"npm";return C?{current:e,latest:null,updateAvailable:!1,mode:t,canSelfUpdate:!1,stale:!1,error:"",npmCommand:null,channel:t==="npm"?"npm":"release",service:!1,disabled:!0}:((!w||(w.stale?!(f.at&&Date.now()-f.at<M):Date.now()-w.seenAt>F))&&!v&&(v=W(e).then(s=>{w={...s,seenAt:Date.now()}}).catch(()=>{}).finally(()=>{v=null})),w?{...w,seenAt:void 0,current:e}:{current:e,latest:null,updateAvailable:!1,mode:t,canSelfUpdate:!1,stale:!0,checking:!0,error:"",npmCommand:null,channel:t==="npm"?"npm":"release",service:b()})}function De(){w=null,v=null}async function $e(e){const t=process.execPath,n=l.dirname(t),s=l.join(n,`.chatpanel-gateway.new-${Date.now()}`),a=new AbortController,r=setTimeout(()=>a.abort(),ie);let c;try{let o;try{o=await fetch(e.assetUrl,{headers:J,redirect:"follow",signal:a.signal})}catch(i){throw new Error(`download failed: ${a.signal.aborted?"timed out":i?.cause?.code||i?.cause?.message||i?.message||i}`)}if(!o.ok)throw new Error(`download failed (HTTP ${o.status})`);if(!ce(o.url||e.assetUrl))throw new Error(`refused: the download was redirected to ${o.url}, which is not a ChatPanel release host`);c=Buffer.from(await o.arrayBuffer())}finally{clearTimeout(r)}if(c.length<5<<20)throw new Error(`the download was only ${(c.length/1024).toFixed(0)} KB — that is not the gateway, so nothing was replaced`);await I(s,c),process.platform!=="win32"&&await q(s,493),process.platform==="darwin"&&await new Promise(o=>S("xattr",["-c",s],()=>o()));const u=await new Promise(o=>S(s,["--version"],{timeout:6e4,windowsHide:!0},(i,d)=>o(i?"":String(d||"").trim())));if(!h(u))throw await X(s,{force:!0}),new Error("the downloaded gateway would not run, so it was discarded");return process.platform==="win32"&&await L(t,l.join(n,`chatpanel-gateway.old-${Date.now()}.exe`)),await L(s,t),h(u)}const O=(e,t=null,n="")=>Object.assign(new Error(e),{advice:t,raw:n});async function Se(e){if(C)throw new Error("Self-update is switched off on this gateway (CHATPANEL_SELF_UPDATE=off).");const t=await W(e,{force:!0});if(t.stale)throw new Error(`Could not reach the update server${t.error?` (${t.error})`:""}. Refusing to act on a stale check — try again in a few minutes.`);if(!t.updateAvailable)throw new Error(`Already on the latest ${t.channel} version (v${e}).`);if(t.blocked)throw O(`v${t.latest} was not installed. ${x(t.blocked)}`,t.blocked);if(!t.canSelfUpdate)throw new Error(t.mode==="npm"?`This gateway cannot update itself here. Run: ${t.npmCommand}`:"No downloadable build for this platform — install it with npm instead.");if(t.mode==="binary")try{return{from:e,to:await $e(t),mode:"binary"}}catch(a){const r=y(a.message,{platform:process.platform,channel:"binary"});throw r?O(`${x(r)}
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The download said: ${a.message}`,r,a.message):a}if(process.platform==="win32")return{from:e,to:t.latest,mode:"npm",deferred:`"${process.execPath}" "${E()}" install -g ${A}@latest --registry=${_} --no-fund --no-audit`};const n=await Ee();if(!n.ok){const a=ge(n.out),r=a?null:y(n.out,{platform:process.platform,node:process.versions.node,needsNode:t.needsNode}),c=n.out.slice(0,600);throw O(a?`${a}
|
|
4
|
+
|
|
5
|
+
npm said: ${c}`:r?`${x(r)}
|
|
6
|
+
|
|
7
|
+
npm said: ${c}`:`npm install failed: ${n.out.slice(0,800)}`,r,c)}n.via==="system-ca"&&console.log("[update] installed through the system's certificates — a proxy on this network re-signs npm's traffic");const s=me();if(!s||G(s,e)<=0)throw new Error(`npm ran, but the install at ${k()} is still ${s||"unreadable"} — the service launches a copy npm did not update. Run: ${t.npmCommand}`);return{from:e,to:s,mode:"npm"}}const p={state:"idle",mode:"",from:"",to:"",detail:"",advice:null,raw:"",startedAt:0,endedAt:0};function Re(){return{...p}}function Le(e,{restart:t=ae,apply:n=Se}={}){return p.state==="installing"||p.state==="restarting"?{...p,already:!0}:(Object.assign(p,{state:"installing",mode:P()?"binary":"npm",from:e,to:"",detail:"",advice:null,raw:"",startedAt:Date.now(),endedAt:0}),n(e).then(s=>{Object.assign(p,{state:"restarting",to:s.to,mode:s.mode,detail:s.deferred?`stopping to install v${s.to}, then relaunching`:`v${s.to} is installed; restarting the gateway into it`}),setTimeout(()=>{t({winInstall:s.deferred||""})||Object.assign(p,{state:"done",endedAt:Date.now(),detail:`v${s.to} is installed, but this gateway is not run by a service it can restart. Start it again yourself to run the new version.`})},400)}).catch(s=>{const a=String(s?.message||s);Object.assign(p,{state:"failed",endedAt:Date.now(),detail:a.slice(0,2400),advice:s?.advice||y(a,{platform:process.platform,channel:p.mode==="binary"?"binary":"npm"}),raw:String(s?.raw||"").slice(0,800)})}),{...p})}function Ie(){Object.assign(p,{state:"idle",mode:"",from:"",to:"",detail:"",advice:null,raw:"",startedAt:0,endedAt:0})}export{Ie as _resetUpdateJob,De as _resetUpdateStatus,W as checkForUpdate,G as cmpVersions,ce as downloadHostAllowed,Ee as installWithRetry,P as isCompiledBinary,ve as nodeGate,we as npmInstallArgs,fe as npmInstallEnv,k as npmPackageRoot,ge as npmPermissionHint,be as npmSpawn,Ue as resetUpdateBackoff,Se as selfUpdate,Le as startUpdate,ye as systemCaAvailable,Re as updateJob,je as updateStatus};
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.
|
|
1
|
+
const o="0.86.0";export{o as VERSION};
|