@chatpanel/gateway 0.6.109 → 0.7.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.
Files changed (80) hide show
  1. package/README.md +24 -4
  2. package/bin/chatpanel-gateway-bin.mjs +1 -24
  3. package/bin/chatpanel-gateway.js +3 -97
  4. package/package.json +1 -7
  5. package/src/access-log-store.js +1 -45
  6. package/src/agent.js +2 -256
  7. package/src/anthropic.js +3 -83
  8. package/src/backup-decrypt.js +1 -45
  9. package/src/backup-ingest.js +6 -120
  10. package/src/bridge-supervisor.js +3 -212
  11. package/src/bridge.js +4 -252
  12. package/src/budget.js +1 -117
  13. package/src/config.js +1 -209
  14. package/src/configstore.js +1 -181
  15. package/src/connect-agents.js +22 -179
  16. package/src/diarize-engine.js +1 -188
  17. package/src/egress.js +2 -0
  18. package/src/engine-ledger-store.js +1 -150
  19. package/src/engine.js +1 -132
  20. package/src/entitlement-refresh.js +1 -84
  21. package/src/entitlement.js +1 -76
  22. package/src/extraction.js +4 -294
  23. package/src/freegate.js +1 -47
  24. package/src/gate.js +1 -75
  25. package/src/gateway-token.js +1 -60
  26. package/src/history-store.js +1 -251
  27. package/src/job.js +3 -148
  28. package/src/knowledge.js +3 -215
  29. package/src/local-status.js +6 -102
  30. package/src/log.js +1 -21
  31. package/src/mcp-cli.js +19 -113
  32. package/src/mcp.js +34 -546
  33. package/src/memory-store.js +1 -176
  34. package/src/memory.js +2 -642
  35. package/src/model-integrity.js +1 -82
  36. package/src/model-ledger.js +1 -229
  37. package/src/model-runtime.js +1 -37
  38. package/src/models.js +1 -92
  39. package/src/ner-engine.js +1 -318
  40. package/src/ner.js +1 -113
  41. package/src/observability.js +1 -123
  42. package/src/openai.js +2 -84
  43. package/src/ort.js +1 -52
  44. package/src/parakeet-engine.js +2 -228
  45. package/src/pocket-tts-engine.js +1 -520
  46. package/src/prefs-store.js +1 -149
  47. package/src/project-store.js +1 -139
  48. package/src/project.js +1 -171
  49. package/src/recruit.js +3 -424
  50. package/src/recruiting.js +1 -93
  51. package/src/redact.js +2 -123
  52. package/src/responses.js +2 -80
  53. package/src/router.js +1 -292
  54. package/src/rrf.js +1 -93
  55. package/src/scorecard-store.js +1 -92
  56. package/src/scorecard.js +1 -336
  57. package/src/search-index.js +2 -134
  58. package/src/secure-fetch.js +1 -58
  59. package/src/sentencepiece.js +1 -184
  60. package/src/server.js +10 -2290
  61. package/src/service.js +11 -189
  62. package/src/shape.js +5 -121
  63. package/src/sqlite-store.js +3 -212
  64. package/src/stream.js +5 -182
  65. package/src/structured.js +4 -902
  66. package/src/stt-engine.js +1 -486
  67. package/src/stt-models.js +1 -144
  68. package/src/subject-kinds.js +1 -6
  69. package/src/subject-name.js +1 -97
  70. package/src/team-board.js +6 -338
  71. package/src/team-record.js +1 -226
  72. package/src/team-store.js +1 -261
  73. package/src/team.js +1 -303
  74. package/src/toolrelay.js +3 -122
  75. package/src/tts-engine.js +1 -453
  76. package/src/tts-models.js +1 -254
  77. package/src/tts-remote.js +1 -109
  78. package/src/tts-voice-resolve.js +1 -78
  79. package/src/tts-voices.js +1 -192
  80. package/src/update.js +1 -305
@@ -1,105 +1,9 @@
1
- // local-status.js — one view of ChatPanel's local runtime: the bridge and the gateway.
2
- //
3
- // U3 of docs/bridge-gateway-unification.md: a person should be able to ask "what's running
4
- // locally?" once and get a straight answer, without knowing there are two services on two
5
- // ports. This is the read side of that — it probes both over HTTP and reports. It does NOT
6
- // control either service (start/stop stays with each module's own installer, which owns its
7
- // launchd/systemd unit); managing another module's service from here would duplicate the
8
- // knowledge of how to do it and drift.
9
- //
10
- // The bridge is OPTIONAL from the gateway's side and the gateway is OPTIONAL from the
11
- // bridge's — so a missing one is reported plainly, never as an error.
1
+ import{loadConfig as u}from"./config.js";function k(){try{return`http://127.0.0.1:${u().port||4320}`}catch{return"http://127.0.0.1:4320"}}function g(){try{return String(u().bridge?.url||"http://127.0.0.1:4319").replace(/\/+$/,"")}catch{return"http://127.0.0.1:4319"}}async function s(n,e="/health"){try{const t=await fetch(n+e,{signal:AbortSignal.timeout(2500)});return t.ok?{ok:!0,data:await t.json().catch(()=>({}))}:{ok:!1,reason:`HTTP ${t.status}`}}catch(t){return{ok:!1,reason:t?.name==="TimeoutError"?"no response":t?.message||"unreachable"}}}async function y({gatewayUrl:n,bridgeUrl:e}={}){const t=n||k(),i=e||g(),[l,a]=await Promise.all([s(t),s(i)]),o=a.ok?await s(i,"/skills").then(r=>r.ok?(r.data.skills||[]).length:null).catch(()=>null):null;return{gateway:{url:t,running:l.ok,version:l.ok?l.data.version:null,tier:l.ok?l.data.tier:null,reason:l.ok?null:l.reason},bridge:{url:i,running:a.ok,version:a.ok?a.data.version:null,agents:a.ok?(a.data.agents||[]).filter(r=>r.available).length:null,skills:o??(a.ok?a.data.skills?.count??null:null),reason:a.ok?null:a.reason}}}function w(n){const e=(o,r,c)=>{const d=r.running?"●":"○",h=r.running?`${o} running · v${r.version}`:`${o} not running${r.reason?` (${r.reason})`:""}`;return` ${d} ${h}
2
+ ${c}`},t=e("Gateway",n.gateway,n.gateway.running?`Privacy layer: redaction, routing, voice. ${n.gateway.url}`:"Optional upgrade (redaction, routing, voice). Start with: chatpanel-gateway --install"),i=n.bridge.running?`Local agents & skills${n.bridge.agents!=null?` · ${n.bridge.agents} agent(s)`:""}${n.bridge.skills!=null?` · ${n.bridge.skills} skill(s)`:""}. ${n.bridge.url}`:"Runs your local coding agents and skills. Start with: curl -fsSL https://dl.chatpanel.net/bridge/install.sh | bash",l=e("Bridge",n.bridge,i),a=n.bridge.running&&n.gateway.running?"Both running — local traffic can route through the gateway's privacy layer.":n.bridge.running?"Bridge up. The gateway is an optional upgrade.":n.gateway.running?"Gateway up. Start the bridge to use local agents and skills.":"Neither running.";return`ChatPanel local
12
3
 
13
- import { loadConfig } from './config.js';
4
+ ${t}
14
5
 
15
- function gatewayUrl() {
16
- try {
17
- return `http://127.0.0.1:${loadConfig().port || 4320}`;
18
- } catch {
19
- return 'http://127.0.0.1:4320';
20
- }
21
- }
6
+ ${l}
22
7
 
23
- function bridgeUrl() {
24
- try {
25
- return String(loadConfig().bridge?.url || 'http://127.0.0.1:4319').replace(/\/+$/, '');
26
- } catch {
27
- return 'http://127.0.0.1:4319';
28
- }
29
- }
30
-
31
- async function probe(url, path = '/health') {
32
- try {
33
- const res = await fetch(url + path, { signal: AbortSignal.timeout(2500) });
34
- if (!res.ok) return { ok: false, reason: `HTTP ${res.status}` };
35
- return { ok: true, data: await res.json().catch(() => ({})) };
36
- } catch (e) {
37
- return { ok: false, reason: e?.name === 'TimeoutError' ? 'no response' : (e?.message || 'unreachable') };
38
- }
39
- }
40
-
41
- /**
42
- * A structured picture of the local runtime — for the `local` command and for the gateway
43
- * to log at startup. Pure except the two probes; the caller decides how to render it.
44
- */
45
- export async function localStatus({ gatewayUrl: gwOverride, bridgeUrl: brOverride } = {}) {
46
- const gwUrl = gwOverride || gatewayUrl();
47
- const brUrl = brOverride || bridgeUrl();
48
- const [gw, br] = await Promise.all([probe(gwUrl), probe(brUrl)]);
49
- const skills = br.ok ? await probe(brUrl, '/skills').then((r) => (r.ok ? (r.data.skills || []).length : null)).catch(() => null) : null;
50
- return {
51
- gateway: {
52
- url: gwUrl,
53
- running: gw.ok,
54
- version: gw.ok ? gw.data.version : null,
55
- tier: gw.ok ? gw.data.tier : null,
56
- reason: gw.ok ? null : gw.reason,
57
- },
58
- bridge: {
59
- url: brUrl,
60
- running: br.ok,
61
- version: br.ok ? br.data.version : null,
62
- agents: br.ok ? (br.data.agents || []).filter((a) => a.available).length : null,
63
- skills: skills ?? (br.ok ? br.data.skills?.count ?? null : null),
64
- reason: br.ok ? null : br.reason,
65
- },
66
- };
67
- }
68
-
69
- /** Human-readable block for the CLI. */
70
- export function formatLocalStatus(s) {
71
- const line = (name, m, extra) => {
72
- const dot = m.running ? '●' : '○';
73
- const head = m.running ? `${name} running · v${m.version}` : `${name} not running${m.reason ? ` (${m.reason})` : ''}`;
74
- return ` ${dot} ${head}\n ${extra}`;
75
- };
76
- const gw = line('Gateway', s.gateway, s.gateway.running
77
- ? `Privacy layer: redaction, routing, voice. ${s.gateway.url}`
78
- : `Optional upgrade (redaction, routing, voice). Start with: chatpanel-gateway --install`);
79
- const brExtra = s.bridge.running
80
- ? `Local agents & skills${s.bridge.agents != null ? ` · ${s.bridge.agents} agent(s)` : ''}${s.bridge.skills != null ? ` · ${s.bridge.skills} skill(s)` : ''}. ${s.bridge.url}`
81
- : `Runs your local coding agents and skills. Start with: curl -fsSL https://dl.chatpanel.net/bridge/install.sh | bash`;
82
- const br = line('Bridge', s.bridge, brExtra);
83
- const summary = s.bridge.running && s.gateway.running
84
- ? 'Both running — local traffic can route through the gateway\'s privacy layer.'
85
- : s.bridge.running
86
- ? 'Bridge up. The gateway is an optional upgrade.'
87
- : s.gateway.running
88
- ? 'Gateway up. Start the bridge to use local agents and skills.'
89
- : 'Neither running.';
90
- return `ChatPanel local\n\n${gw}\n\n${br}\n\n ${summary}\n`;
91
- }
92
-
93
- /**
94
- * One-line note for the gateway to log at startup, so the operator sees the unified picture
95
- * without running anything. Never throws; a probe failure just says "not detected".
96
- */
97
- export async function bridgePresenceNote(brOverride) {
98
- const url = brOverride || bridgeUrl();
99
- const br = await probe(url);
100
- if (br.ok) {
101
- const n = (br.data.skills?.count ?? null);
102
- return `bridge detected at ${url} (v${br.data.version}${n != null ? `, ${n} skills` : ''}) — its agents and skills are available through this gateway.`;
103
- }
104
- return `bridge not detected at ${url} — a running gateway (0.6.92+) starts its embedded bridge itself; if this one did not, check ~/.chatpanel/gateway.log. The gateway runs fine without it, minus local agents/skills.`;
105
- }
8
+ ${a}
9
+ `}async function $(n){const e=n||g(),t=await s(e);if(t.ok){const i=t.data.skills?.count??null;return`bridge detected at ${e} (v${t.data.version}${i!=null?`, ${i} skills`:""}) — its agents and skills are available through this gateway.`}return`bridge not detected at ${e} — a running gateway (0.6.92+) starts its embedded bridge itself; if this one did not, check ~/.chatpanel/gateway.log. The gateway runs fine without it, minus local agents/skills.`}export{$ as bridgePresenceNote,w as formatLocalStatus,y as localStatus};
package/src/log.js CHANGED
@@ -1,21 +1 @@
1
- // Timestamped console. Gateway logs (NER lifecycle, per-request redaction lines,
2
- // entitlement refresh) are useless for debugging without a clock — prefix every
3
- // console line with a local YYYY-MM-DD HH:MM:SS stamp. Call once at startup,
4
- // before anything logs. Idempotent (won't double-wrap if called twice).
5
-
6
- let installed = false;
7
-
8
- function stamp(d = new Date()) {
9
- const p = (n, w = 2) => String(n).padStart(w, '0');
10
- return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} `
11
- + `${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
12
- }
13
-
14
- export function installTimestampedConsole() {
15
- if (installed) return;
16
- installed = true;
17
- for (const method of ['log', 'info', 'warn', 'error']) {
18
- const orig = console[method].bind(console);
19
- console[method] = (...args) => orig(`[${stamp()}]`, ...args);
20
- }
21
- }
1
+ let n=!1;function s(t=new Date){const e=(o,r=2)=>String(o).padStart(r,"0");return`${t.getFullYear()}-${e(t.getMonth()+1)}-${e(t.getDate())} ${e(t.getHours())}:${e(t.getMinutes())}:${e(t.getSeconds())}`}function l(){if(!n){n=!0;for(const t of["log","info","warn","error"]){const e=console[t].bind(console);console[t]=(...o)=>e(`[${s()}]`,...o)}}}export{l as installTimestampedConsole};
package/src/mcp-cli.js CHANGED
@@ -1,113 +1,19 @@
1
- // `chatpanel-gateway tools list | tools schema <tool> | call <tool> '<json>'` — the same
2
- // tools the MCP server offers, reached from a shell.
3
- //
4
- // An MCP connection is a standing cost: every tool's schema sits in the agent's context on
5
- // every turn, called or not. A shell verb costs nothing until it is used — `tools list`
6
- // prints names and one-liners, `tools schema` pulls ONE schema at the moment of calling,
7
- // `call` runs the tool. So an agent that has only a shell (a skill's `scripts/`, a CI job,
8
- // a CLI with no MCP support) reaches history, memory and briefs at a cost that scales with
9
- // use rather than with how many tools exist. The daemon's secrets never move: the CLI
10
- // talks to the gateway exactly as the MCP server does, over loopback with the gateway
11
- // token, and prints results.
12
- //
13
- // Exit codes, so a script can tell them apart: 0 the tool answered; 1 the tool itself
14
- // reported an error (a real tool-level failure — the record was not found); 2 a usage or
15
- // transport failure (bad JSON, unknown verb, gateway unreachable).
16
-
17
- import { readFileSync } from 'node:fs';
18
- import { handleRpc } from './mcp.js';
19
-
20
- const USAGE = [
21
- 'Usage:',
22
- ' chatpanel-gateway tools list names and one-liners (no schemas)',
23
- ' chatpanel-gateway tools schema <tool> one tool\'s full input schema',
24
- ' chatpanel-gateway call <tool> [\'<json>\'] run a tool; arguments as a JSON object',
25
- ' chatpanel-gateway call <tool> --file <path> arguments from a JSON file (no shell quoting)',
26
- '',
27
- 'Exit codes: 0 ok · 1 the tool reported an error · 2 usage or transport failure',
28
- ].join('\n');
29
-
30
- /** First sentence, whitespace collapsed, capped — enough to choose a tool, not to call it. */
31
- export function oneLiner(description, max = 100) {
32
- const s = String(description || '').replace(/\s+/g, ' ').trim();
33
- const cut = s.search(/[.!?]\s/);
34
- const first = cut > 20 ? s.slice(0, cut + 1) : s;
35
- return first.length > max ? `${first.slice(0, max - 1).trimEnd()}…` : first;
36
- }
37
-
38
- export function formatToolsList(tools) {
39
- const width = Math.min(24, Math.max(...tools.map((t) => t.name.length), 4));
40
- return tools.map((t) => {
41
- const req = Array.isArray(t.inputSchema?.required) && t.inputSchema.required.length ? `(${t.inputSchema.required.join(', ')})` : '()';
42
- return `${t.name.padEnd(width)} ${req.padEnd(22)} ${oneLiner(t.description)}`;
43
- }).join('\n');
44
- }
45
-
46
- function parseArgs(argv) {
47
- const rest = [...argv];
48
- let file = null;
49
- const i = rest.indexOf('--file');
50
- if (i >= 0) { file = rest[i + 1]; rest.splice(i, 2); }
51
- return { rest, file };
52
- }
53
-
54
- /**
55
- * Run one CLI invocation. Returns the exit code; writes through `out`/`err` so a test can
56
- * capture without a process. `rpc` is the MCP dispatcher — `handleRpc` in production.
57
- */
58
- export async function runMcpCli(argv, { out = (s) => process.stdout.write(s), err = (s) => process.stderr.write(s), rpc = handleRpc } = {}) {
59
- const [verb, ...more] = argv;
60
- const list = async () => (await rpc({ jsonrpc: '2.0', id: 1, method: 'tools/list' }))?.result?.tools || [];
61
-
62
- if (verb === 'tools') {
63
- const [sub, name] = more;
64
- if (sub === 'list') {
65
- out(`${formatToolsList(await list())}\n`);
66
- return 0;
67
- }
68
- if (sub === 'schema') {
69
- if (!name) { err(`tools schema: which tool?\n${USAGE}\n`); return 2; }
70
- const tool = (await list()).find((t) => t.name === name);
71
- if (!tool) { err(`no tool named "${name}". Run: chatpanel-gateway tools list\n`); return 2; }
72
- out(`${JSON.stringify({ name: tool.name, description: tool.description, inputSchema: tool.inputSchema }, null, 2)}\n`);
73
- return 0;
74
- }
75
- err(`${USAGE}\n`);
76
- return 2;
77
- }
78
-
79
- if (verb === 'call') {
80
- const { rest, file } = parseArgs(more);
81
- const [name, inline] = rest;
82
- if (!name) { err(`call: which tool?\n${USAGE}\n`); return 2; }
83
- let args = {};
84
- try {
85
- const text = file ? readFileSync(file, 'utf8') : (inline ?? '{}');
86
- args = JSON.parse(text);
87
- } catch (e) {
88
- err(`call: arguments must be a JSON object (${e.message})\n`);
89
- return 2;
90
- }
91
- if (!args || typeof args !== 'object' || Array.isArray(args)) { err('call: arguments must be a JSON object\n'); return 2; }
92
- let reply;
93
- try {
94
- reply = await rpc({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name, arguments: args } });
95
- } catch (e) {
96
- err(`call: ${e.message}\n`);
97
- return 2;
98
- }
99
- if (reply?.error) { err(`call: ${reply.error.message}\n`); return 2; }
100
- const text = (reply?.result?.content || []).filter((c) => c.type === 'text').map((c) => c.text).join('\n');
101
- if (reply?.result?.isError) {
102
- // The gateway being down looks like a tool error from the MCP layer; it is transport.
103
- const transport = /fetch failed|ECONNREFUSED|not running|unreachable/i.test(text);
104
- err(`${text}\n`);
105
- return transport ? 2 : 1;
106
- }
107
- out(`${text}\n`);
108
- return 0;
109
- }
110
-
111
- err(`${USAGE}\n`);
112
- return 2;
113
- }
1
+ import{readFileSync as g}from"node:fs";import{handleRpc as y}from"./mcp.js";const m=["Usage:"," chatpanel-gateway tools list names and one-liners (no schemas)"," chatpanel-gateway tools schema <tool> one tool's full input schema"," chatpanel-gateway call <tool> ['<json>'] run a tool; arguments as a JSON object"," chatpanel-gateway call <tool> --file <path> arguments from a JSON file (no shell quoting)","","Exit codes: 0 ok · 1 the tool reported an error · 2 usage or transport failure"].join(`
2
+ `);function $(o,e=100){const t=String(o||"").replace(/\s+/g," ").trim(),n=t.search(/[.!?]\s/),r=n>20?t.slice(0,n+1):t;return r.length>e?`${r.slice(0,e-1).trimEnd()}…`:r}function S(o){const e=Math.min(24,Math.max(...o.map(t=>t.name.length),4));return o.map(t=>{const n=Array.isArray(t.inputSchema?.required)&&t.inputSchema.required.length?`(${t.inputSchema.required.join(", ")})`:"()";return`${t.name.padEnd(e)} ${n.padEnd(22)} ${$(t.description)}`}).join(`
3
+ `)}function w(o){const e=[...o];let t=null;const n=e.indexOf("--file");return n>=0&&(t=e[n+1],e.splice(n,2)),{rest:e,file:t}}async function x(o,{out:e=r=>process.stdout.write(r),err:t=r=>process.stderr.write(r),rpc:n=y}={}){const[r,...f]=o,d=async()=>(await n({jsonrpc:"2.0",id:1,method:"tools/list"}))?.result?.tools||[];if(r==="tools"){const[u,i]=f;if(u==="list")return e(`${S(await d())}
4
+ `),0;if(u==="schema"){if(!i)return t(`tools schema: which tool?
5
+ ${m}
6
+ `),2;const s=(await d()).find(p=>p.name===i);return s?(e(`${JSON.stringify({name:s.name,description:s.description,inputSchema:s.inputSchema},null,2)}
7
+ `),0):(t(`no tool named "${i}". Run: chatpanel-gateway tools list
8
+ `),2)}return t(`${m}
9
+ `),2}if(r==="call"){const{rest:u,file:i}=w(f),[s,p]=u;if(!s)return t(`call: which tool?
10
+ ${m}
11
+ `),2;let l={};try{const a=i?g(i,"utf8"):p??"{}";l=JSON.parse(a)}catch(a){return t(`call: arguments must be a JSON object (${a.message})
12
+ `),2}if(!l||typeof l!="object"||Array.isArray(l))return t(`call: arguments must be a JSON object
13
+ `),2;let c;try{c=await n({jsonrpc:"2.0",id:1,method:"tools/call",params:{name:s,arguments:l}})}catch(a){return t(`call: ${a.message}
14
+ `),2}if(c?.error)return t(`call: ${c.error.message}
15
+ `),2;const h=(c?.result?.content||[]).filter(a=>a.type==="text").map(a=>a.text).join(`
16
+ `);if(c?.result?.isError){const a=/fetch failed|ECONNREFUSED|not running|unreachable/i.test(h);return t(`${h}
17
+ `),a?2:1}return e(`${h}
18
+ `),0}return t(`${m}
19
+ `),2}export{S as formatToolsList,$ as oneLiner,x as runMcpCli};