@chatpanel/bridge 0.11.14 → 0.11.16
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/package.json +1 -1
- package/src/engines/antigravity.js +94 -19
- package/src/engines/codex.js +55 -0
- package/src/mcp-local.js +0 -0
- package/src/server.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/bridge",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.16",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Local bridge that exposes the AI coding agents installed on your machine — Claude Code (CLI), Codex (CLI), and Antigravity CLI (formerly Gemini CLI, which remains available for business/enterprise) — to the ChatPanel Chrome extension over a localhost SSE endpoint. Bring your own agent.",
|
|
6
6
|
"keywords": [
|
|
@@ -46,6 +46,58 @@ export async function listModels() {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
export const newAgyState = () => ({ started: new Set(), finalText: '' });
|
|
50
|
+
|
|
51
|
+
// Translate one `agy --output-format stream-json` line into the bridge's streaming
|
|
52
|
+
// vocabulary. Schema, captured from agy 1.2.2:
|
|
53
|
+
// {event:'init', init:{cwd, tools:[…]}}
|
|
54
|
+
// {event:'step_update', step_update:{ step_index, state:'ACTIVE'|'DONE',
|
|
55
|
+
// step_type:'user_input'|'agent_response'|'tool', text_delta?, tool_name?,
|
|
56
|
+
// tool_info:{ name, parameters, output? }, usage? }}
|
|
57
|
+
// {event:'result', result:{ status:'SUCCESS', response, usage }}
|
|
58
|
+
// Returns { streamed } — whether a piece of the ANSWER went out (tool activity does not
|
|
59
|
+
// count, so a run that only ran tools still gets its final text from `result`).
|
|
60
|
+
export function forwardAgyLine(line, emit, state = newAgyState()) {
|
|
61
|
+
const t = String(line || '').trim();
|
|
62
|
+
if (!t) return { streamed: false };
|
|
63
|
+
let ev;
|
|
64
|
+
try { ev = JSON.parse(t); } catch {
|
|
65
|
+
// Not JSON: the CLI printed something for a human (a warning, a banner). Show it.
|
|
66
|
+
emit({ type: 'delta', text: `${t}\n` });
|
|
67
|
+
return { streamed: true };
|
|
68
|
+
}
|
|
69
|
+
const kind = ev.event || ev.type || '';
|
|
70
|
+
if (kind === 'init') { emit({ type: 'status', text: 'Antigravity working' }); return { streamed: false }; }
|
|
71
|
+
if (kind === 'result') {
|
|
72
|
+
const res = ev.result || {};
|
|
73
|
+
state.finalText = typeof res.response === 'string' ? res.response : '';
|
|
74
|
+
if (res.status && res.status !== 'SUCCESS') emit({ type: 'status', text: `Antigravity: ${res.status}` });
|
|
75
|
+
return { streamed: false };
|
|
76
|
+
}
|
|
77
|
+
if (kind !== 'step_update') return { streamed: false };
|
|
78
|
+
const st = ev.step_update || {};
|
|
79
|
+
if (st.step_type === 'tool') {
|
|
80
|
+
const id = `agy_${st.step_index ?? state.started.size}`;
|
|
81
|
+
const info = st.tool_info && typeof st.tool_info === 'object' ? st.tool_info : {};
|
|
82
|
+
const name = st.tool_name || info.name || 'tool';
|
|
83
|
+
if (!state.started.has(id)) {
|
|
84
|
+
state.started.add(id);
|
|
85
|
+
emit({ type: 'tool', name, phase: 'start', callId: id, input: info.parameters && typeof info.parameters === 'object' ? info.parameters : {} });
|
|
86
|
+
}
|
|
87
|
+
if (st.state === 'DONE') {
|
|
88
|
+
const failed = !!info.error || st.state === 'ERROR';
|
|
89
|
+
const output = info.output == null ? '' : typeof info.output === 'string' ? info.output : JSON.stringify(info.output);
|
|
90
|
+
emit({ type: 'tool', name, phase: 'done', callId: id, status: failed ? `error: ${String(info.error || 'failed').slice(0, 80)}` : 'ok', result: String(failed ? info.error || '' : output).slice(0, 4000) });
|
|
91
|
+
}
|
|
92
|
+
return { streamed: false };
|
|
93
|
+
}
|
|
94
|
+
if (st.step_type === 'agent_response' && typeof st.text_delta === 'string' && st.text_delta) {
|
|
95
|
+
emit({ type: 'delta', text: st.text_delta });
|
|
96
|
+
return { streamed: true };
|
|
97
|
+
}
|
|
98
|
+
return { streamed: false };
|
|
99
|
+
}
|
|
100
|
+
|
|
49
101
|
let installed = false;
|
|
50
102
|
let lastProbe = 0;
|
|
51
103
|
export async function available() {
|
|
@@ -99,18 +151,23 @@ export async function chat({ messages, system, options, images }, emit, { signal
|
|
|
99
151
|
// `-p` runs one prompt non-interactively. --model picks the model.
|
|
100
152
|
// --dangerously-skip-permissions auto-approves tool use (headless has no human
|
|
101
153
|
// approver) only when the user opted into bypassPermissions.
|
|
102
|
-
const
|
|
103
|
-
if (options.model)
|
|
104
|
-
if (options.permissionMode === 'bypassPermissions')
|
|
154
|
+
const baseArgs = ['-p', prompt];
|
|
155
|
+
if (options.model) baseArgs.push('--model', options.model);
|
|
156
|
+
if (options.permissionMode === 'bypassPermissions') baseArgs.push('--dangerously-skip-permissions');
|
|
105
157
|
// Drop caller extras that would auto-approve tools (shared sanitizer).
|
|
106
|
-
pushExtraArgs(
|
|
158
|
+
pushExtraArgs(baseArgs, options.extraArgs, FORBIDDEN.antigravity, emit);
|
|
107
159
|
|
|
108
|
-
|
|
160
|
+
// STRUCTURED OUTPUT FIRST. agy 1.2+ streams `--output-format stream-json`: one NDJSON
|
|
161
|
+
// event per line, with every tool step's name, parameters and output. Plain text — which
|
|
162
|
+
// is all this engine ever read — has no tools in it at all, so a turn that ran six
|
|
163
|
+
// commands showed the panel one answer and nothing else. An older agy that does not know
|
|
164
|
+
// the flag exits non-zero naming it; we fall back to text once, out loud.
|
|
165
|
+
const run = (structured) => new Promise((resolve, reject) => {
|
|
166
|
+
const args = structured ? [...baseArgs, '--output-format', 'stream-json'] : baseArgs;
|
|
109
167
|
let child;
|
|
110
168
|
try {
|
|
111
169
|
child = spawn('agy', args, { cwd, stdio: ['ignore', 'pipe', 'pipe'], env: { ...process.env }, ...spawnGroupOpts });
|
|
112
170
|
} catch (e) {
|
|
113
|
-
cleanup();
|
|
114
171
|
return reject(new Error(`Failed to start agy: ${e.message}`));
|
|
115
172
|
}
|
|
116
173
|
|
|
@@ -118,44 +175,62 @@ export async function chat({ messages, system, options, images }, emit, { signal
|
|
|
118
175
|
|
|
119
176
|
let out = '';
|
|
120
177
|
let err = '';
|
|
178
|
+
let buf = '';
|
|
121
179
|
let streamed = false;
|
|
180
|
+
const state = newAgyState();
|
|
122
181
|
let idleTimer;
|
|
123
182
|
const armIdle = () => {
|
|
124
183
|
clearTimeout(idleTimer);
|
|
125
184
|
idleTimer = setTimeout(() => {
|
|
126
185
|
child.kill('SIGKILL');
|
|
127
|
-
cleanup();
|
|
128
186
|
reject(new Error(`Antigravity timed out — no output for ${Math.round(IDLE_MS / 1000)}s.`));
|
|
129
187
|
}, IDLE_MS);
|
|
130
188
|
};
|
|
131
189
|
armIdle();
|
|
132
190
|
|
|
191
|
+
const forward = (line) => {
|
|
192
|
+
const r = forwardAgyLine(line, emit, state);
|
|
193
|
+
if (r.streamed) streamed = true;
|
|
194
|
+
};
|
|
133
195
|
child.stdout.on('data', (d) => {
|
|
134
196
|
armIdle();
|
|
135
197
|
const s = d.toString();
|
|
136
198
|
out += s;
|
|
137
|
-
streamed = true;
|
|
138
|
-
|
|
199
|
+
if (!structured) { streamed = true; emit({ type: 'delta', text: s }); return; }
|
|
200
|
+
buf += s;
|
|
201
|
+
let nl;
|
|
202
|
+
while ((nl = buf.indexOf('\n')) >= 0) {
|
|
203
|
+
forward(buf.slice(0, nl));
|
|
204
|
+
buf = buf.slice(nl + 1);
|
|
205
|
+
}
|
|
139
206
|
});
|
|
140
207
|
child.stderr.on('data', (d) => { armIdle(); err += d.toString(); });
|
|
141
208
|
child.on('error', (e) => {
|
|
142
209
|
clearTimeout(idleTimer);
|
|
143
210
|
detach();
|
|
144
|
-
cleanup();
|
|
145
211
|
reject(new Error(`Failed to start agy: ${e.message}`));
|
|
146
212
|
});
|
|
147
213
|
child.on('close', (code) => {
|
|
148
214
|
clearTimeout(idleTimer);
|
|
149
215
|
detach();
|
|
150
|
-
|
|
151
|
-
if (
|
|
152
|
-
|
|
153
|
-
if (!streamed) emit({ type: 'delta', text: out.trim() || '(no output)' });
|
|
154
|
-
emit({ type: 'done', text: '' });
|
|
155
|
-
resolve();
|
|
156
|
-
} else {
|
|
157
|
-
reject(new Error(summarizeCliError('Antigravity', code, err, out)));
|
|
158
|
-
}
|
|
216
|
+
if (signal?.aborted) { resolve({ code: 0, aborted: true }); return; } // Stop pressed — end quietly
|
|
217
|
+
if (structured && buf.trim()) forward(buf);
|
|
218
|
+
resolve({ code, out, err, streamed, state });
|
|
159
219
|
});
|
|
160
220
|
});
|
|
221
|
+
|
|
222
|
+
try {
|
|
223
|
+
let r = await run(true);
|
|
224
|
+
if (r.aborted) return;
|
|
225
|
+
if (r.code !== 0 && !r.streamed && /output-format|unknown flag|flag provided but not defined/i.test(r.err)) {
|
|
226
|
+
emit({ type: 'status', text: 'This Antigravity CLI has no structured output; showing its text only. Update it with `agy update` to see tool activity.' });
|
|
227
|
+
r = await run(false);
|
|
228
|
+
if (r.aborted) return;
|
|
229
|
+
}
|
|
230
|
+
if (r.code !== 0) throw new Error(summarizeCliError('Antigravity', r.code, r.err, r.out));
|
|
231
|
+
if (!r.streamed) emit({ type: 'delta', text: (r.state?.finalText || r.out).trim() || '(no output)' });
|
|
232
|
+
emit({ type: 'done', text: '' });
|
|
233
|
+
} finally {
|
|
234
|
+
cleanup();
|
|
235
|
+
}
|
|
161
236
|
}
|
package/src/engines/codex.js
CHANGED
|
@@ -334,6 +334,9 @@ export async function chat({ messages, system, options, images }, emit, { signal
|
|
|
334
334
|
// reasoning: { id, text } (only some models/efforts emit it)
|
|
335
335
|
// file_change: { id, changes:[{path}] }
|
|
336
336
|
// agent_message: { id, text } (the answer — read from -o outFile at close)
|
|
337
|
+
// web_search: { id, query, action:{ type, query?, url? } } (codex-cli 0.154)
|
|
338
|
+
// mcp_tool_call: { id, server, tool, arguments, result?, error?, status }
|
|
339
|
+
// todo_list: { id, items:[{ text, completed }] }
|
|
337
340
|
export function forwardEvent(ev, emit, state = { started: new Set(), reasoned: new Set(), n: 0 }) {
|
|
338
341
|
const t = ev.type || '';
|
|
339
342
|
const item = ev.item || {};
|
|
@@ -368,6 +371,58 @@ export function forwardEvent(ev, emit, state = { started: new Set(), reasoned: n
|
|
|
368
371
|
return;
|
|
369
372
|
}
|
|
370
373
|
|
|
374
|
+
// WEB SEARCH — Codex's own, not a command and not an MCP call, so it never reached the
|
|
375
|
+
// panel: a weekend-weather turn that searched four times showed no activity at all while
|
|
376
|
+
// the CLI printed "Searching the web" four times. Captured from codex-cli 0.154:
|
|
377
|
+
// item.started { id, type:'web_search', query:'', action:{ type:'other' } }
|
|
378
|
+
// item.completed { id, type:'web_search', query, action:{ type:'search', query } }
|
|
379
|
+
// (the query is only known at completion; an `open_page` action carries a url instead).
|
|
380
|
+
if (itype === 'web_search') {
|
|
381
|
+
const id = item.id || `ws_${state.n++}`;
|
|
382
|
+
const action = item.action && typeof item.action === 'object' ? item.action : {};
|
|
383
|
+
const query = item.query || action.query || '';
|
|
384
|
+
const url = action.url || '';
|
|
385
|
+
if (!state.started.has(id)) {
|
|
386
|
+
state.started.add(id);
|
|
387
|
+
emit({ type: 'tool', name: 'web_search', phase: 'start', callId: id, input: { query, ...(url ? { url } : {}) } });
|
|
388
|
+
}
|
|
389
|
+
if (completed || t === 'item.completed') {
|
|
390
|
+
emit({ type: 'tool', name: 'web_search', phase: 'done', callId: id, status: 'ok', result: url ? `Opened ${url}` : query ? `Searched the web for ${query}` : 'Searched the web' });
|
|
391
|
+
}
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
394
|
+
|
|
395
|
+
// MCP TOOL CALLS — the user's own servers, and ChatPanel's page tools relayed through the
|
|
396
|
+
// bridge. { id, server, tool, arguments, result?, error?, status }.
|
|
397
|
+
if (itype === 'mcp_tool_call') {
|
|
398
|
+
const id = item.id || `mcp_${state.n++}`;
|
|
399
|
+
const name = item.server ? `${item.server}/${item.tool || 'tool'}` : (item.tool || 'mcp');
|
|
400
|
+
if (!state.started.has(id)) {
|
|
401
|
+
state.started.add(id);
|
|
402
|
+
emit({ type: 'tool', name, phase: 'start', callId: id, input: item.arguments && typeof item.arguments === 'object' ? item.arguments : {} });
|
|
403
|
+
}
|
|
404
|
+
if (completed) {
|
|
405
|
+
const failed = item.status === 'failed' || item.error != null;
|
|
406
|
+
const err = item.error && typeof item.error === 'object' ? (item.error.message || JSON.stringify(item.error)) : item.error;
|
|
407
|
+
const res = item.result == null ? '' : typeof item.result === 'string' ? item.result : JSON.stringify(item.result);
|
|
408
|
+
emit({ type: 'tool', name, phase: 'done', callId: id, status: failed ? `error: ${String(err || 'failed').slice(0, 80)}` : 'ok', result: String(failed ? err || '' : res).slice(0, 4000) });
|
|
409
|
+
}
|
|
410
|
+
return;
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
// A plan Codex wrote for itself, shown once when it changes.
|
|
414
|
+
if (itype === 'todo_list' && Array.isArray(item.items) && item.items.length) {
|
|
415
|
+
const text = item.items.map((x) => `${x.completed ? '☑' : '☐'} ${x.text || ''}`).join('\n');
|
|
416
|
+
if (state.lastTodo !== text) { state.lastTodo = text; emit({ type: 'status', text: `Plan:\n${text}` }); }
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
if (itype === 'error' || t === 'error') {
|
|
421
|
+
const msg = item.message || ev.message || '';
|
|
422
|
+
if (msg) emit({ type: 'status', text: `Codex: ${String(msg).slice(0, 300)}` });
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
|
|
371
426
|
if (itype === 'reasoning' || (!itype && t.includes('reasoning'))) {
|
|
372
427
|
// Emit each reasoning summary once (dedup the started/updated/completed repeats).
|
|
373
428
|
const id = item.id || `r_${state.n++}`;
|
package/src/mcp-local.js
CHANGED
|
Binary file
|
package/src/server.js
CHANGED
|
@@ -67,7 +67,7 @@ import {
|
|
|
67
67
|
// Hardcoded (not read from package.json) so it survives Bun's single-file
|
|
68
68
|
// --compile, where package.json isn't on a readable FS. CI fails the publish if
|
|
69
69
|
// this drifts from package.json, so the two can't silently diverge.
|
|
70
|
-
const VERSION = '0.11.
|
|
70
|
+
const VERSION = '0.11.16';
|
|
71
71
|
const HOST = process.env.CHATPANEL_BRIDGE_HOST || '127.0.0.1';
|
|
72
72
|
const PORT = Number(process.env.CHATPANEL_BRIDGE_PORT) || 4319;
|
|
73
73
|
|