@chatpanel/gateway 0.98.1 → 0.99.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 +7 -3
- package/bin/chatpanel-gateway.js +7 -7
- package/package.json +2 -2
- package/src/event.js +1 -1
- package/src/install-copies.js +1 -0
- package/src/version.js +1 -1
package/README.md
CHANGED
|
@@ -65,9 +65,13 @@ running process), and waits until the new version — and its bridge — answer.
|
|
|
65
65
|
`chatpanel-gateway` runs it in the foreground instead, for a terminal; if another gateway already
|
|
66
66
|
holds 4320 it says which one and exits.
|
|
67
67
|
|
|
68
|
-
**
|
|
69
|
-
PATH, so `chatpanel-gateway` still
|
|
70
|
-
`
|
|
68
|
+
**Two copies on one machine (the standalone binary and npm): the newest wins.** `install.sh` put
|
|
69
|
+
`~/.local/bin` first on your PATH, so `chatpanel-gateway` may still mean the old binary there — but
|
|
70
|
+
`chatpanel-gateway --install` from any copy hands off to the newest one on PATH, which takes over
|
|
71
|
+
the login service, turns `~/.local/bin/chatpanel-gateway` into a link to itself (so the name means
|
|
72
|
+
the active install from every PATH entry) and names any other older copy with the command that
|
|
73
|
+
removes it. `chatpanel-gateway --status` lists every copy, its version, which one PATH runs and
|
|
74
|
+
which one answers the port. `--install --force` keeps an older copy on purpose.
|
|
71
75
|
|
|
72
76
|
On Windows, if `chatpanel-gateway` is "not recognized" right after `npm i -g`, npm's global bin
|
|
73
77
|
folder is not on that shell's PATH yet: open a new PowerShell, or run it by path —
|
package/bin/chatpanel-gateway.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
3
|
-
`)}process.argv.includes("--json")?console.log(JSON.stringify(
|
|
4
|
-
${
|
|
5
|
-
`).map(
|
|
6
|
-
`)}`),console.error(" `chatpanel-gateway --status` shows what is registered; running `chatpanel-gateway` in a terminal shows the start-up itself."));
|
|
7
|
-
`));break;default:console.error(`unknown option: ${
|
|
8
|
-
Usage: chatpanel-gateway [mcp|tools list|tools schema <tool>|call <tool> '<json>'|local|connect|pair|link|policy|--audit|--install|--uninstall|--stop|--status|--version|--bridge]`),process.exit(2)}}}catch(
|
|
2
|
+
const r=process.argv[2],P={"--bridge":"chatpanel-bridge","--mcp-stdio":"chatpanel-bridge-mcp",mcp:"chatpanel-history-mcp","--extract-worker":"chatpanel-extract"},k=(e=process.argv)=>e.includes("--mcp-stdio")?P["--mcp-stdio"]:P[e[2]]||"chatpanel-gateway";try{process.title=k()}catch{}if(!process.versions.bun&&r!=="--version"&&r!=="-v"){const[e,t]=String(process.versions.node||"0.0").split(".").map(Number);(e<22||e===22&&t<13)&&(console.error(`ChatPanel Gateway needs Node.js 22.13 or newer — this is ${process.version}.`),console.error("Update Node (https://nodejs.org, or `nvm install 22`), then run this again — or use the standalone binary, which carries its own runtime:"),console.error(" curl -fsSL https://dl.chatpanel.net/install.sh | bash"),process.exit(1))}try{if(r==="--extract-worker"){process.env.CHATPANEL_EXTRACT_WORKER_IMPORTED="1";const{runExtractWorker:e}=await import("../src/extract/worker.js");e()}else if(r==="--bridge"){if(process.env.CHATPANEL_BRIDGE_EMBEDDED="1",process.argv.splice(2,1),!process.argv.includes("--mcp-stdio")&&!process.argv.includes("--version")){const{trustSystemCertificates:e,systemCaWantedOnDisk:t}=await import("../src/system-ca.js");e({enabled:t()})}await import("@chatpanel/bridge/src/server.js")}else if(r==="--mcp-stdio")process.env.CHATPANEL_BRIDGE_EMBEDDED="1",await import("@chatpanel/bridge/src/server.js");else if(r==="mcp"){const{runMcpServer:e}=await import("../src/mcp.js");await e()}else if(r==="tools"||r==="call"){const{runMcpCli:e}=await import("../src/mcp-cli.js");process.exit(await e(process.argv.slice(2)))}else if(r==="policy"){const{loadPolicy:e,formatPolicy:t,PolicyLoadError:w}=await import("../src/policy.js");try{const i=await e();process.argv.includes("--json")?console.log(JSON.stringify(i?{...i,label:void 0}:null,null,2)):console.log(t(i))}catch(i){throw i instanceof w&&(console.error(`org policy: ${i.message}`),process.exit(78)),i}}else if(r==="--audit"){const{egressAudit:e,formatAudit:t}=await import("../src/egress.js"),{loadConfig:w}=await import("../src/config.js"),{readFileSync:i}=await import("node:fs"),{join:v}=await import("node:path"),y=await import("node:os"),c=w(),a=`http://127.0.0.1:${c.port||4320}`;let o=null,l=`no gateway running at ${a}`;try{const u=i(process.env.CHATPANEL_GATEWAY_TOKEN_PATH||v(y.homedir(),".chatpanel","gateway-token"),"utf8").trim(),m=await fetch(`${a}/audit`,{headers:{authorization:`Bearer ${u}`},signal:AbortSignal.timeout(2500)});if(m.ok)o=await m.json();else if(m.status===404){const g=await fetch(`${a}/health`,{signal:AbortSignal.timeout(2500)}).then(f=>f.json()).catch(()=>null);l=`the gateway running at ${a}${g?.version?` (${g.version})`:""} predates --audit (0.7.0) — restart it after updating`}else l=`the gateway at ${a} refused the audit (HTTP ${m.status}) — is ~/.chatpanel/gateway-token readable?`}catch{}if(!o){const{VERSION:u}=await import("../src/server.js"),{systemCaWanted:m}=await import("../src/system-ca.js"),g=m(c),{partnerDevicesOnDisk:f}=await import("../src/link-host.js"),h=c.link?.enabled===!1?[]:f(...c.link?.path?[c.link.path]:[]);o={...e(c,{ledger:null,version:u,linkPartners:h,certificates:{on:!1,added:0,wanted:g,why:g?"no gateway is running; when one starts it adds this computer's list":"switched off (tls.systemCa: false, or CHATPANEL_SYSTEM_CA=off)"}}),observed:[]},console.log(`(${l}; showing what the current config allows)
|
|
3
|
+
`)}process.argv.includes("--json")?console.log(JSON.stringify(o,null,2)):console.log(t(o))}else if(r==="sandbox"){const{srtModuleUrl:e}=await import("../src/worker-sandbox.js");!process.env.CHATPANEL_SRT_MODULE&&e()&&(process.env.CHATPANEL_SRT_MODULE=e());const{runSandboxCli:t}=await import("@chatpanel/bridge/src/sandbox.js"),{sandboxCommand:w}=await import("../src/sandbox-cli.js"),{loadConfig:i}=await import("../src/config.js"),{readFileSync:v}=await import("node:fs"),{join:y}=await import("node:path"),c=await import("node:os");let a="";try{a=v(process.env.CHATPANEL_GATEWAY_TOKEN_PATH||y(c.homedir(),".chatpanel","gateway-token"),"utf8").trim()}catch{}process.exit(await w(process.argv.slice(3),{cfg:i(),token:a,local:o=>t(o)}))}else if(r==="pair"){const{loadConfig:e}=await import("../src/config.js"),{readFileSync:t}=await import("node:fs"),{join:w}=await import("node:path"),i=await import("node:os"),y=`http://127.0.0.1:${e().port||4320}`,c=process.env.CHATPANEL_GATEWAY_TOKEN_PATH||w(i.homedir(),".chatpanel","gateway-token");try{const a=t(c,"utf8").trim(),o=await fetch(`${y}/pair/code`,{method:"POST",headers:{authorization:`Bearer ${a}`},signal:AbortSignal.timeout(2500)}),l=await o.json().catch(()=>({}));if(o.status===404)throw new Error(`the gateway at ${y} predates pairing (0.9.0) — update and restart it`);if(!o.ok)throw new Error(l.error||`HTTP ${o.status}`);console.log(`Pairing code: ${l.display||l.code} (one use, expires in 5 minutes)`),console.log('Enter it in ChatPanel → Settings → Coding Agents → "Pairing code".')}catch(a){console.error(`could not get a pairing code from the gateway at ${y}: ${a?.message||a}${/ENOENT/.test(String(a?.message))?` (no token at ${c} — has the gateway started once?)`:""}`),process.exit(1)}}else if(r==="link"){const{linkCommand:e}=await import("../src/link-cli.js"),{loadConfig:t}=await import("../src/config.js"),{readFileSync:w}=await import("node:fs"),{join:i}=await import("node:path"),v=await import("node:os"),c=`http://127.0.0.1:${t().port||4320}`,a=process.env.CHATPANEL_GATEWAY_TOKEN_PATH||i(v.homedir(),".chatpanel","gateway-token");let o="";try{o=w(a,"utf8").trim()}catch{console.error(`no gateway token at ${a} — has the gateway started once?`),process.exit(1)}const l=async(m,g,f)=>{try{const h=await fetch(`${c}${g}`,{method:m,headers:{authorization:`Bearer ${o}`,...f?{"content-type":"application/json"}:{}},body:f?JSON.stringify(f):void 0,signal:AbortSignal.timeout(2e4)});return{status:h.status,json:await h.json().catch(()=>null)}}catch(h){return{status:0,json:{error:{message:`no gateway answering at ${c} (${h?.message||h})`}}}}},u=process.stdin.isTTY?async m=>{const{createInterface:g}=await import("node:readline/promises"),f=g({input:process.stdin,output:process.stdout});try{return/^y(es)?$/i.test((await f.question(m)).trim())}finally{f.close()}}:null;process.exit(await e(process.argv.slice(3),{call:l,ask:u}))}else if(r==="local"){const{localStatus:e,formatLocalStatus:t}=await import("../src/local-status.js");process.stdout.write(t(await e()))}else if(r==="connect"){const{connectAgents:e,formatConnect:t}=await import("../src/connect-agents.js"),w=process.argv.includes("--dry-run")||process.argv.includes("-n");process.stdout.write(t(e({dryRun:w}),{dryRun:w}))}else if(r==="--confined"||r===void 0&&process.env.CHATPANEL_CONFINED!=="1"&&await(await import("../src/confine-start.js")).confinedByPolicy()){const{startConfined:e}=await import("../src/confine-start.js");await e({by:r==="--confined"?"flag":"policy"})}else{const{start:e,VERSION:t}=await import("../src/server.js"),{installService:w,uninstallService:i,serviceReport:v,stopService:y,pathWithDir:c}=await import("../src/service.js");switch(r){case"--stop":y(),console.log("ChatPanel Gateway: stopped (auto-start is still registered; `--install` or a login starts it again).");break;case"--version":case"-v":console.log(t);break;case"--fetch-apple-helper":{const{ensureAppleHelper:a,appleHelperWanted:o}=await import("../src/apple-helper-fetch.js"),l=await import("node:os");if(!o({release:l.release()})){console.log("Apple’s on-device model needs an Apple Silicon Mac on macOS 26 or later — nothing to fetch here.");break}try{const{loadConfig:u}=await import("../src/config.js"),m=await a({version:t,registries:u().registries||{},onProgress:g=>{g.phase==="download"&&console.log(`fetching the Apple on-device helper (v${g.version}) from ${new URL(g.url).host}…`)}});console.log(`Apple on-device helper: ${m}`)}catch(u){console.error(`could not fetch the Apple on-device helper: ${u?.message||u}`),process.exit(1)}break}case"--install":{try{const{ensureAppleHelper:d,appleHelperWanted:$,findAppleHelper:s}=await import("../src/apple-helper-fetch.js"),A=await import("node:os");if($({release:A.release()})&&!s()){const{loadConfig:b}=await import("../src/config.js");await d({version:t,registries:b().registries||{}}),console.log("Apple on-device helper: fetched (this install came without it).")}}catch(d){console.log(`Apple on-device helper: not fetched (${String(d?.message||d).slice(0,160)}) — \`chatpanel-gateway --fetch-apple-helper\` tries again; everything else works without it.`)}const a=process.argv.includes("--force"),{gatewayCommands:o,newerCopy:l,handoffLine:u,retireStandaloneGateway:m,installCopyLines:g}=await import("../src/install-copies.js"),f=o(),h=a||process.env.CHATPANEL_INSTALL_HANDOFF?null:l(f,t);if(h){console.log(u(h,t));const{spawnSync:d}=await import("node:child_process"),$=/\.cmd$/i.test(h.path),s=d($?`"${h.path}"`:h.path,process.argv.slice(2),{stdio:"inherit",shell:$,env:{...process.env,CHATPANEL_INSTALL_HANDOFF:"1"}});s.error&&(console.error(` could not run ${h.path}: ${s.error.message} — run it yourself: ${h.path} --install`),process.exit(1)),process.exit(s.status??1)}const n=await w({version:t,force:a}),p=n.health;if(n.newer){const d=p.managedBy&&p.managedBy!=="gateway"?` (run by the ${p.managedBy.replace(/-child$/,"")} app)`:"";console.log(`ChatPanel Privacy Gateway v${p.version} is already running at ${p.url}${d} — newer than this copy (v${t}). Nothing was changed.`),console.log(" To bring this copy up to date: npm i -g @chatpanel/gateway --ignore-scripts (or re-run install.sh), then chatpanel-gateway --install"),console.log(` To run this older v${t} instead anyway: chatpanel-gateway --install --force`);break}if(n.ok){const d=n.deferredTo?` — the ${n.deferredTo} app's gateway (v${p.version}) is the one answering right now; this install takes over at the next login`:"",$=n.replaced?`, replacing v${n.replaced}`:"";n.unchanged?console.log(`ChatPanel Privacy Gateway v${p.version}: already running at ${p.url} and registered to start at login — nothing was changed, nothing was restarted.`):console.log(`ChatPanel Privacy Gateway v${p.version}: running at ${p.url}${$}, starts at login${n.wsl?" (Windows login, through wsl.exe)":""}${d}.`);let s=null;for(let A=0;A<30;A++){try{s=(await(await fetch(`${p.url}/health`,{signal:AbortSignal.timeout(1500)})).json())?.bridge||null}catch{s=null}if(s&&s.mode!=="starting")break;await new Promise(b=>setTimeout(b,500))}if(s?["embedded","standalone","adopted"].includes(s.mode)?console.log(` bridge: ${s.mode}${s.version?` v${s.version}`:""} — local agents are available.`):console.error(` ⚠ bridge: ${s.why||s.mode}`):console.log(" bridge: this gateway does not report one yet — `chatpanel-gateway --status` shows it once it is up."),s?.version){const{staleBridgeCommands:A,staleBridgeLines:b}=await import("../src/service.js");for(const C of b(A({embedded:s.version}),{embedded:s.version}))console.log(C)}}else p.ok?(console.error(`ChatPanel Privacy Gateway: v${t} is registered to start at login, but v${p.version} still answers at ${p.url} 40 s later.`),console.error(" Something starts it back faster than it can be replaced — `chatpanel-gateway --status` says what holds the port; `--stop`, then `--install`, separates the two steps.")):(console.error(`ChatPanel Privacy Gateway: login auto-start is registered, but nothing answered at ${p.url} after 40 s.`),n.errLog&&console.error(` last of the error log:
|
|
4
|
+
${n.errLog.split(`
|
|
5
|
+
`).map(d=>` ${d}`).join(`
|
|
6
|
+
`)}`),console.error(" `chatpanel-gateway --status` shows what is registered; running `chatpanel-gateway` in a terminal shows the start-up itself."));const T=n.ok?m({copies:f,version:t}):null;for(const d of g({copies:f,version:t,retired:T,force:a}))console.log(d);try{const{pruneForeignPrebuilds:d,pruneLine:$}=await import("../src/prune-install.js"),s=$(d({log:A=>console.error(A)}));s&&console.log(s)}catch{}n.launcher==="powershell"&&console.log(" (VBScript is not installed here, so the login launcher is PowerShell — a console flashes for an instant at login.)"),n.path?.added?console.log(` Added ${n.path.dir} to your PATH — \`chatpanel-gateway\` works in a NEW terminal.`):n.path?.error?console.log(` Could not add ${n.path.dir} to your PATH (${n.path.error}) — add it yourself to run \`chatpanel-gateway\` by name.`):n.path?.dir&&n.wsl&&c(process.env.PATH||"",n.path.dir)!==null&&console.log(` Tip: add it to your PATH -> export PATH="${n.path.dir}:$PATH"`),p.ok||process.exit(1);break}case"--uninstall":i(),console.log("ChatPanel Privacy Gateway: removed login auto-start.");break;case"--status":{console.log(await v());try{const{gatewayCommands:a,statusCopyLines:o}=await import("../src/install-copies.js"),{probeHealth:l}=await import("../src/service.js");for(const u of o({copies:a(),version:t,running:await l()}))console.log(u)}catch(a){console.log(` (could not list the installed copies: ${a?.message||a})`)}try{const{loadConfig:a}=await import("../src/config.js"),{sandboxProblems:o}=await import("../src/configstore.js");for(const l of o(a()))console.log(` ⚠ ${l}`)}catch{}break}case void 0:await e();break;case"--help":case"-h":console.log([`ChatPanel Privacy Gateway v${t}`,""," chatpanel-gateway --install run after every install or upgrade: login auto-start, replace an older one, wait for it and its bridge"," chatpanel-gateway run in the foreground, in this terminal"," chatpanel-gateway --status what starts it, what answers on the port, which copy is on PATH, how agents are sandboxed"," chatpanel-gateway sandbox what the sandbox is doing; `sandbox allow <agent> aws` lets one agent use a sign-in"," chatpanel-gateway --stop stop it (on Windows, before `npm i -g`)"," chatpanel-gateway --uninstall remove login auto-start"," chatpanel-gateway local the bridge and the gateway, one view"," chatpanel-gateway pair a one-time code for a browser the gateway does not recognise"," chatpanel-gateway link ChatPanel Link: paired devices; `link pair --partner <name>` lets a partner server in (shown and confirmed first); `link revoke <id>`; `link route <mode>`"," chatpanel-gateway connect point your CLI agents (Codex, Claude Code, …) at it"," chatpanel-gateway --audit every host it has contacted, and every host its config allows"," chatpanel-gateway --version print the version"].join(`
|
|
7
|
+
`));break;default:console.error(`unknown option: ${r}
|
|
8
|
+
Usage: chatpanel-gateway [mcp|tools list|tools schema <tool>|call <tool> '<json>'|local|connect|pair|link|policy|--audit|--install|--uninstall|--stop|--status|--version|--bridge]`),process.exit(2)}}}catch(e){console.error(`error: ${e.message}`),process.exit(1)}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/gateway",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.99.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.46.1",
|
|
27
|
-
"@chatpanel/events": "^0.
|
|
27
|
+
"@chatpanel/events": "^0.361.0",
|
|
28
28
|
"@chatpanel/pii": "^0.15.0",
|
|
29
29
|
"@huggingface/transformers": "^4.2.0",
|
|
30
30
|
"defuddle": "^0.19.4",
|
package/src/event.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{isRef as n}from"./ref.js";const
|
|
1
|
+
import{isRef as n}from"./ref.js";const c=1,E=Object.freeze({turn:["started","ended"],assistant:["prompted","message","reasoning"],context:["assembled","attached","expanded","retrieved"],capability:["offered","granted","denied","activated","revoked","invoked","resulted"],privacy:["redacted","egress"],policy:["changed","guard_denied"],data:["created","updated","deleted"],automation:["fired","suppressed"],shim:["fired"]}),v=Object.freeze(Object.entries(E).flatMap(([e,r])=>r.map(s=>`${e}.${s}`))),w=Object.freeze(["user","rule","schedule","model","agent","channel"]),x=Object.freeze(["global","site","tab","session","agent"]),u=Object.freeze(["R","M","L","C","A","X","H"]),S=Object.freeze(["pure","idempotent","replay-safe","non-replayable"]),I=Object.freeze(["none","redacted","delegated"]);class a extends Error{constructor(r,s,d=null){super(s),this.name="EventError",this.code=r,this.detail=d}}const t=e=>typeof e=="string"&&e.length>0,o=e=>typeof e=="number"&&Number.isFinite(e),l=e=>Array.isArray(e);function i(e){return!!e&&w.includes(e.kind)&&t(e.id)}function A(e){return!!e&&x.includes(e.kind)&&t(e.id)}const O={"turn.started":e=>t(e.turnId),"turn.ended":e=>t(e.turnId),"assistant.prompted":e=>t(e.turnId)&&n(e.ref),"assistant.message":e=>t(e.turnId)&&n(e.ref),"assistant.reasoning":e=>t(e.turnId)&&n(e.ref),"context.assembled":e=>o(e.budget)&&o(e.used)&&!!e.parts&&typeof e.parts=="object"&&l(e.resident)&&e.resident.every(n)&&o(e.reachableCount),"context.attached":e=>n(e.ref),"context.expanded":e=>n(e.ref)&&o(e.tokens),"context.retrieved":e=>t(e.tool)&&o(e.count)&&l(e.sources)&&e.sources.every(r=>r&&typeof r=="object"&&o(r.rank)),"capability.offered":e=>t(e.capability)&&t(e.reason),"capability.granted":e=>t(e.capability)&&i(e.actor),"capability.denied":e=>t(e.capability)&&i(e.actor),"capability.activated":e=>t(e.capability)&&u.includes(e.classUsed),"capability.revoked":e=>t(e.capability)&&t(e.cause),"capability.invoked":e=>t(e.capability)&&i(e.actor)&&A(e.scope)&&S.includes(e.effects)&&(e.effects==="pure"||t(e.idempotencyKey)),"capability.resulted":e=>t(e.capability)&&typeof e.ok=="boolean"&&u.includes(e.classUsed)&&!!e.cost&&o(e.cost.ms),"privacy.redacted":e=>!!e.counts&&typeof e.counts=="object"&&Object.values(e.counts).every(o),"privacy.egress":e=>t(e.host)&&typeof e.redacted=="boolean"&&typeof e.controlled=="boolean","policy.changed":e=>t(e.dial)&&i(e.actor)&&"from"in e&&"to"in e,"policy.guard_denied":e=>t(e.capability)&&t(e.reason),"data.created":e=>n(e.ref),"data.updated":e=>n(e.ref),"data.deleted":e=>n(e.ref)&&typeof e.shredded=="boolean","automation.fired":e=>t(e.ruleId)&&u.includes(e.classUsed),"automation.suppressed":e=>t(e.ruleId)&&t(e.reason),"shim.fired":e=>t(e.shimId)&&(e.engine==null||t(e.engine))};function y(e){if(!e||typeof e!="object")throw new a("SHAPE","event must be an object");if(e.v!==c)throw new a("VERSION",`expected v=${c}, got ${e.v} — upcast first`,e.v);if(!t(e.id))throw new a("SHAPE","id required");if(!t(e.host))throw new a("SHAPE","host required");if(!Number.isInteger(e.seq)||e.seq<0)throw new a("SHAPE","seq must be a non-negative integer");if(!l(e.causes)||!e.causes.every(t))throw new a("SHAPE","causes must be string[]");if(!o(e.at))throw new a("SHAPE","at required (advisory wall clock)");if(!v.includes(e.type))throw new a("TYPE",`unknown type ${e.type}`,e.type);if(!e.payload||typeof e.payload!="object")throw new a("SHAPE","payload required");const r=O[e.type];if(r&&!r(e.payload))throw new a("PAYLOAD",`payload invalid for ${e.type}`,e.type);return e}function k(e){try{return y(e),!0}catch{return!1}}function P({host:e,seq:r=0,now:s=()=>Date.now(),newId:d}){if(!t(e))throw new a("SHAPE","host required");const b=d||(()=>globalThis.crypto.randomUUID());let f=r;return{get host(){return e},get seq(){return f},append(p,h,g=[]){const m=Object.freeze({v:c,id:b(),host:e,seq:f++,causes:Object.freeze([...g]),at:s(),type:p,payload:h});return y(m)}}}export{w as ACTOR_KINDS,v as ALL_TYPES,u as CLASSES,c as CURRENT_VERSION,S as EFFECTS,I as EGRESS,E as EVENT_TYPES,a as EventError,x as SCOPE_KINDS,P as createAppender,k as isValidEvent,y as validateEvent};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import G from"node:os";import y from"node:path";import{statSync as N,lstatSync as D,readFileSync as F,unlinkSync as I,symlinkSync as B}from"node:fs";import{spawnSync as V}from"node:child_process";import{isCompiledBinary as K,hostFacts as M}from"@chatpanel/events/runtime-host.js";import{compareVersions as A,realPath as j,commandDir as O}from"./service.js";const d="chatpanel-gateway",H="@chatpanel/gateway",$={npm:"the npm package",binary:"the standalone binary",checkout:"a source checkout"},R=t=>{try{return N(t).isFile()}catch{return!1}},h=(t,o)=>{const n=String(t||"").trim().replace(/[\\/]+$/,"");return o==="win32"?n.toLowerCase():n};function U({platform:t=process.platform,home:o=G.homedir(),env:n=process.env}={}){return t==="win32"?y.win32.join(n.LOCALAPPDATA||y.win32.join(o,"AppData","Local"),"ChatPanel",`${d}.exe`):y.posix.join(o,".local","bin",d)}function z(t,{run:o=V,env:n=process.env}={}){try{const s=o(t,["--version"],{encoding:"utf8",timeout:15e3,killSignal:"SIGKILL",windowsHide:!0,stdio:["ignore","pipe","ignore"],env:{...n,CHATPANEL_SELF_UPDATE:"off",CHATPANEL_RUNTIME_AUTO:"off"}}),r=/(\d+\.\d+\.\d+)/.exec(String(s?.stdout||""));return r?r[1]:""}catch{return""}}function g(t,o,n){try{const s=JSON.parse(o(n.join(t,"package.json")));return s?.name===H&&s.version?String(s.version):""}catch{return""}}function Z({pathEnv:t=process.env.PATH||"",platform:o=process.platform,isFile:n=R,real:s=j,read:r=i=>F(i,"utf8"),versionOf:p=z}={}){const i=o==="win32"?y.win32:y.posix,c=o==="win32",l=c?[`${d}.cmd`,`${d}.exe`]:[d],e=[],a=new Set;for(const u of String(t).split(c?";":":")){const f=h(u,o);if(!f)continue;const w=l.map(m=>i.join(f,m)).find(m=>n(m));if(!w)continue;let v=s(w),x="binary",k="",C="";const L=/^(.*[/\\]node_modules[/\\]@chatpanel[/\\]gateway)[/\\]/.exec(v),T=c?/\.cmd$/i.test(w)?[i.join(f,"node_modules","@chatpanel","gateway")].find(m=>g(m,r,i)):"":L&&g(L[1],r,i)?L[1]:"";if(T){x="npm",k=g(T,r,i),v=i.join(T,"bin",`${d}.js`);const m=i.join(f,c?"npm.cmd":"npm");C=`${n(m)?m:"npm"} rm -g ${H}`}else/[/\\]bin[/\\]chatpanel-gateway\.js$/.test(v)&&g(i.dirname(i.dirname(v)),r,i)?(x="checkout",k=g(i.dirname(i.dirname(v)),r,i)):(k=p(v),C=c?`del "${w}"`:`rm "${w}"`);const b=h(v,o);a.has(b)||(a.add(b),e.push({path:w,dir:f,target:v,kind:x,version:k,first:e.length===0,remove:C}))}return e}function P({execPath:t=process.execPath,argv1:o=process.argv[1]||"",real:n=j,compiled:s=K(M())}={}){return n(s?t:y.resolve(o))}const S=(t,o=P(),n=process.platform)=>!!o&&h(t.target,n)===h(o,n);function E(t,o){let n=null;for(const s of t||[])!s.version||A(s.version,o)<=0||(!n||A(s.version,n.version)>0)&&(n=s);return n}const _=(t,o)=>(t||[]).filter(n=>n.version&&A(n.version,o)<0);function nn({copies:t=[],version:o="",command:n=(()=>{const e=O();return e?y.join(e,d):""})(),standalone:s=U(),platform:r=process.platform,self:p=P(),lstat:i=D,unlink:c=I,symlink:l=B}={}){const e=_(t,o).find(a=>a.kind==="binary"&&h(a.path,r)===h(s,r)&&!S(a,p,r));if(!e)return null;if(r==="win32"||!n||h(n,r)===h(s,r))return{remove:e.remove,was:e.version,path:e.path};try{return i(s).isFile()?(c(s),l(n,s),{linked:s,to:n,was:e.version}):{remove:e.remove,was:e.version,path:e.path}}catch(a){return{remove:e.remove,was:e.version,path:e.path,error:a?.message||String(a)}}}function tn(t,o){return`ChatPanel Privacy Gateway: this copy is v${o}, but v${t.version} is installed at ${t.path} (${$[t.kind]}) — handing --install to the newer one.`}function en({copies:t=[],version:o="",retired:n=null,self:s=P(),platform:r=process.platform,force:p=!1}={}){const i=[];n?.linked&&i.push(` ✓ ${n.linked} (v${n.was}, the standalone binary) is now a link to this v${o} — \`chatpanel-gateway\` means this copy from every PATH entry.`);const c=n?.linked?h(n.linked,r):"";for(const e of _(t,o)){if(S(e,s,r)||h(e.path,r)===c)continue;const a=e.first?" — and it is first on your PATH, so typing `chatpanel-gateway` runs THAT copy":"";i.push(` ⚠ An older ChatPanel Gateway is still installed: ${e.path} (v${e.version}, ${$[e.kind]}). It is not the one that runs now${a}.`),e.remove&&i.push(` Remove it: ${e.remove}`),n?.error&&h(e.path,r)===h(n.path,r)&&i.push(` (could not replace it with a link: ${n.error})`)}const l=E(t,o);return l&&p&&i.push(` ⚠ A newer ChatPanel Gateway is installed at ${l.path} (v${l.version}, ${$[l.kind]}); this v${o} runs because of --force. \`${l.path} --install\` makes the newer one the service.`),i}function on({copies:t=[],version:o="",running:n=null,self:s=P(),platform:r=process.platform}={}){const p=[],i=n?.ok?String(n.version||""):"",c=t.find(a=>a.first),l=new Set(t.map(a=>a.version||"?"));if(t.length>1||c&&i&&c.version&&c.version!==i){p.push(`installs: ${t.length} ${t.length===1?"copy":"copies"} of chatpanel-gateway on PATH${l.size>1?", not the same version":""}`);const a=Math.max(...t.map(u=>u.path.length));for(const u of t){const f=[u.first?"first on PATH — what `chatpanel-gateway` runs":"",S(u,s,r)?"this command":""].filter(Boolean);p.push(` ${u.path.padEnd(a)} ${u.version?`v${u.version}`:"version unknown"} ${$[u.kind]}${f.length?` ← ${f.join("; ")}`:""}`)}c&&i&&c.version&&c.version!==i&&p.push(` ✕ \`chatpanel-gateway\` on your PATH is v${c.version} (${c.path}), but the gateway running is v${i} — the command you type is not the copy that runs.`)}const e=E(t,o);if(e&&!S(e,s,r)){const a=i&&A(e.version,i)>0?` and than the running v${i}`:"";p.push(` ✕ v${e.version} at ${e.path} (${$[e.kind]}) is newer than this command (v${o})${a} — \`${e.path} --install\` makes it the one that runs.`)}return p}export{$ as KIND_LABEL,z as binaryVersion,Z as gatewayCommands,tn as handoffLine,en as installCopyLines,S as isSelf,E as newerCopy,_ as olderCopies,nn as retireStandaloneGateway,P as selfTarget,U as standaloneGatewayPath,on as statusCopyLines};
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const o="0.
|
|
1
|
+
const o="0.99.0";export{o as VERSION};
|