@chatpanel/bridge 0.11.15 → 0.11.17
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 +78 -2
- 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.17",
|
|
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
|
@@ -39,6 +39,11 @@ const REASONING = process.env.CHATPANEL_CODEX_EFFORT ?? 'low'; // '' → respect
|
|
|
39
39
|
// straight from that file, plus a few common ids. The picker still accepts any
|
|
40
40
|
// free-text value, so an out-of-date curated entry is harmless.
|
|
41
41
|
const CODEX_KNOWN = ['gpt-5-codex', 'gpt-5', 'o3', 'o4-mini'];
|
|
42
|
+
// Set once Codex has reported that its managed requirements forbid approval_policy=never;
|
|
43
|
+
// cleared only by a bridge restart, which is when a policy could plausibly have changed.
|
|
44
|
+
let approvalPolicyBlocked = false;
|
|
45
|
+
export function resetApprovalPolicy() { approvalPolicyBlocked = false; }
|
|
46
|
+
|
|
42
47
|
export async function listModels() {
|
|
43
48
|
const set = new Set();
|
|
44
49
|
try {
|
|
@@ -234,7 +239,7 @@ function runCodex({ args, cwd, env, prompt, outFile, emit, signal }) {
|
|
|
234
239
|
/* no message file */
|
|
235
240
|
}
|
|
236
241
|
unlink(outFile).catch(() => {});
|
|
237
|
-
resolve({ code, stderr, text, streamed });
|
|
242
|
+
resolve({ code, stderr, text, streamed, policyBlocked: !!evState.policyBlocked });
|
|
238
243
|
});
|
|
239
244
|
|
|
240
245
|
child.stdin.write(prompt);
|
|
@@ -265,7 +270,11 @@ export async function chat({ messages, system, options, images }, emit, { signal
|
|
|
265
270
|
args.push('--dangerously-bypass-approvals-and-sandbox');
|
|
266
271
|
} else {
|
|
267
272
|
const sandbox = options.permissionMode === 'acceptEdits' ? 'workspace-write' : 'read-only';
|
|
268
|
-
args.push('-s', sandbox
|
|
273
|
+
args.push('-s', sandbox);
|
|
274
|
+
// `never` is what a headless run needs — but an organisation can pin approval_policy
|
|
275
|
+
// through Codex's managed requirements, and then every turn opened with a paragraph
|
|
276
|
+
// of warning and fell back to OnRequest anyway. Once Codex has said so, stop asking.
|
|
277
|
+
if (!approvalPolicyBlocked) args.push('-c', 'approval_policy=never');
|
|
269
278
|
}
|
|
270
279
|
if (REASONING) args.push('-c', `model_reasoning_effort=${REASONING}`);
|
|
271
280
|
// Ask Codex to emit reasoning SUMMARIES so the panel can stream the model's thinking.
|
|
@@ -303,6 +312,7 @@ export async function chat({ messages, system, options, images }, emit, { signal
|
|
|
303
312
|
|
|
304
313
|
try {
|
|
305
314
|
let result = await attempt();
|
|
315
|
+
if (result.policyBlocked) approvalPolicyBlocked = true;
|
|
306
316
|
|
|
307
317
|
// The failure this exists for: one of the user's OWN MCP servers could not authenticate
|
|
308
318
|
// or could not be reached, and took a turn with it that never needed that server. Drop it
|
|
@@ -334,6 +344,9 @@ export async function chat({ messages, system, options, images }, emit, { signal
|
|
|
334
344
|
// reasoning: { id, text } (only some models/efforts emit it)
|
|
335
345
|
// file_change: { id, changes:[{path}] }
|
|
336
346
|
// agent_message: { id, text } (the answer — read from -o outFile at close)
|
|
347
|
+
// web_search: { id, query, action:{ type, query?, url? } } (codex-cli 0.154)
|
|
348
|
+
// mcp_tool_call: { id, server, tool, arguments, result?, error?, status }
|
|
349
|
+
// todo_list: { id, items:[{ text, completed }] }
|
|
337
350
|
export function forwardEvent(ev, emit, state = { started: new Set(), reasoned: new Set(), n: 0 }) {
|
|
338
351
|
const t = ev.type || '';
|
|
339
352
|
const item = ev.item || {};
|
|
@@ -368,6 +381,69 @@ export function forwardEvent(ev, emit, state = { started: new Set(), reasoned: n
|
|
|
368
381
|
return;
|
|
369
382
|
}
|
|
370
383
|
|
|
384
|
+
// WEB SEARCH — Codex's own, not a command and not an MCP call, so it never reached the
|
|
385
|
+
// panel: a weekend-weather turn that searched four times showed no activity at all while
|
|
386
|
+
// the CLI printed "Searching the web" four times. Captured from codex-cli 0.154:
|
|
387
|
+
// item.started { id, type:'web_search', query:'', action:{ type:'other' } }
|
|
388
|
+
// item.completed { id, type:'web_search', query, action:{ type:'search', query } }
|
|
389
|
+
// (the query is only known at completion; an `open_page` action carries a url instead).
|
|
390
|
+
if (itype === 'web_search') {
|
|
391
|
+
const id = item.id || `ws_${state.n++}`;
|
|
392
|
+
const action = item.action && typeof item.action === 'object' ? item.action : {};
|
|
393
|
+
const query = item.query || action.query || '';
|
|
394
|
+
const url = action.url || '';
|
|
395
|
+
if (!state.started.has(id)) {
|
|
396
|
+
state.started.add(id);
|
|
397
|
+
emit({ type: 'tool', name: 'web_search', phase: 'start', callId: id, input: { query, ...(url ? { url } : {}) } });
|
|
398
|
+
}
|
|
399
|
+
if (completed || t === 'item.completed') {
|
|
400
|
+
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' });
|
|
401
|
+
}
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// MCP TOOL CALLS — the user's own servers, and ChatPanel's page tools relayed through the
|
|
406
|
+
// bridge. { id, server, tool, arguments, result?, error?, status }.
|
|
407
|
+
if (itype === 'mcp_tool_call') {
|
|
408
|
+
const id = item.id || `mcp_${state.n++}`;
|
|
409
|
+
const name = item.server ? `${item.server}/${item.tool || 'tool'}` : (item.tool || 'mcp');
|
|
410
|
+
if (!state.started.has(id)) {
|
|
411
|
+
state.started.add(id);
|
|
412
|
+
emit({ type: 'tool', name, phase: 'start', callId: id, input: item.arguments && typeof item.arguments === 'object' ? item.arguments : {} });
|
|
413
|
+
}
|
|
414
|
+
if (completed) {
|
|
415
|
+
const failed = item.status === 'failed' || item.error != null;
|
|
416
|
+
const err = item.error && typeof item.error === 'object' ? (item.error.message || JSON.stringify(item.error)) : item.error;
|
|
417
|
+
const res = item.result == null ? '' : typeof item.result === 'string' ? item.result : JSON.stringify(item.result);
|
|
418
|
+
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) });
|
|
419
|
+
}
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
// A plan Codex wrote for itself, shown once when it changes.
|
|
424
|
+
if (itype === 'todo_list' && Array.isArray(item.items) && item.items.length) {
|
|
425
|
+
const text = item.items.map((x) => `${x.completed ? '☑' : '☐'} ${x.text || ''}`).join('\n');
|
|
426
|
+
if (state.lastTodo !== text) { state.lastTodo = text; emit({ type: 'status', text: `Plan:\n${text}` }); }
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (itype === 'error' || t === 'error') {
|
|
431
|
+
const msg = String(item.message || ev.message || '');
|
|
432
|
+
if (!msg) return;
|
|
433
|
+
// The managed-requirements warning: long, per turn, and about a flag WE pass. Say it
|
|
434
|
+
// once in a sentence, and remember (see buildArgs) so the next turn does not earn it.
|
|
435
|
+
if (/approval_policy.*(disallowed|not in the allowed set)/i.test(msg)) {
|
|
436
|
+
state.policyBlocked = true;
|
|
437
|
+
if (!state.policyNoted) {
|
|
438
|
+
state.policyNoted = true;
|
|
439
|
+
emit({ type: 'status', text: 'Codex: your organisation pins approval_policy, so Codex will ask before actions it cannot run on its own. ChatPanel will stop passing its own setting.' });
|
|
440
|
+
}
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
emit({ type: 'status', text: `Codex: ${msg.slice(0, 300)}` });
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
|
|
371
447
|
if (itype === 'reasoning' || (!itype && t.includes('reasoning'))) {
|
|
372
448
|
// Emit each reasoning summary once (dedup the started/updated/completed repeats).
|
|
373
449
|
const id = item.id || `r_${state.n++}`;
|
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.17';
|
|
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
|
|