@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.
- package/README.md +24 -4
- package/bin/chatpanel-gateway-bin.mjs +1 -24
- package/bin/chatpanel-gateway.js +3 -97
- package/package.json +1 -7
- package/src/access-log-store.js +1 -45
- package/src/agent.js +2 -256
- package/src/anthropic.js +3 -83
- package/src/backup-decrypt.js +1 -45
- package/src/backup-ingest.js +6 -120
- package/src/bridge-supervisor.js +3 -212
- package/src/bridge.js +4 -252
- package/src/budget.js +1 -117
- package/src/config.js +1 -209
- package/src/configstore.js +1 -181
- package/src/connect-agents.js +22 -179
- package/src/diarize-engine.js +1 -188
- package/src/egress.js +2 -0
- package/src/engine-ledger-store.js +1 -150
- package/src/engine.js +1 -132
- package/src/entitlement-refresh.js +1 -84
- package/src/entitlement.js +1 -76
- package/src/extraction.js +4 -294
- package/src/freegate.js +1 -47
- package/src/gate.js +1 -75
- package/src/gateway-token.js +1 -60
- package/src/history-store.js +1 -251
- package/src/job.js +3 -148
- package/src/knowledge.js +3 -215
- package/src/local-status.js +6 -102
- package/src/log.js +1 -21
- package/src/mcp-cli.js +19 -113
- package/src/mcp.js +34 -546
- package/src/memory-store.js +1 -176
- package/src/memory.js +2 -642
- package/src/model-integrity.js +1 -82
- package/src/model-ledger.js +1 -229
- package/src/model-runtime.js +1 -37
- package/src/models.js +1 -92
- package/src/ner-engine.js +1 -318
- package/src/ner.js +1 -113
- package/src/observability.js +1 -123
- package/src/openai.js +2 -84
- package/src/ort.js +1 -52
- package/src/parakeet-engine.js +2 -228
- package/src/pocket-tts-engine.js +1 -520
- package/src/prefs-store.js +1 -149
- package/src/project-store.js +1 -139
- package/src/project.js +1 -171
- package/src/recruit.js +3 -424
- package/src/recruiting.js +1 -93
- package/src/redact.js +2 -123
- package/src/responses.js +2 -80
- package/src/router.js +1 -292
- package/src/rrf.js +1 -93
- package/src/scorecard-store.js +1 -92
- package/src/scorecard.js +1 -336
- package/src/search-index.js +2 -134
- package/src/secure-fetch.js +1 -58
- package/src/sentencepiece.js +1 -184
- package/src/server.js +10 -2290
- package/src/service.js +11 -189
- package/src/shape.js +5 -121
- package/src/sqlite-store.js +3 -212
- package/src/stream.js +5 -182
- package/src/structured.js +4 -902
- package/src/stt-engine.js +1 -486
- package/src/stt-models.js +1 -144
- package/src/subject-kinds.js +1 -6
- package/src/subject-name.js +1 -97
- package/src/team-board.js +6 -338
- package/src/team-record.js +1 -226
- package/src/team-store.js +1 -261
- package/src/team.js +1 -303
- package/src/toolrelay.js +3 -122
- package/src/tts-engine.js +1 -453
- package/src/tts-models.js +1 -254
- package/src/tts-remote.js +1 -109
- package/src/tts-voice-resolve.js +1 -78
- package/src/tts-voices.js +1 -192
- package/src/update.js +1 -305
package/src/local-status.js
CHANGED
|
@@ -1,105 +1,9 @@
|
|
|
1
|
-
|
|
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
|
-
|
|
4
|
+
${t}
|
|
14
5
|
|
|
15
|
-
|
|
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
|
-
|
|
24
|
-
|
|
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
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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};
|