@chatpanel/bridge 0.11.10 → 0.11.14
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/claude.js +30 -3
- package/src/server.js +4 -1
- package/src/update.js +34 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chatpanel/bridge",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.14",
|
|
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": [
|
package/src/engines/claude.js
CHANGED
|
@@ -189,6 +189,7 @@ function runClaude({ prompt, args, cwd, emit, signal }) {
|
|
|
189
189
|
let stdout = '';
|
|
190
190
|
let stderr = '';
|
|
191
191
|
let streamedAny = false;
|
|
192
|
+
const flow = { sawText: false, tail: '', boundary: false };
|
|
192
193
|
let resultText = '';
|
|
193
194
|
|
|
194
195
|
let idleTimer;
|
|
@@ -215,7 +216,7 @@ function runClaude({ prompt, args, cwd, emit, signal }) {
|
|
|
215
216
|
} catch {
|
|
216
217
|
continue; // not a JSON event line
|
|
217
218
|
}
|
|
218
|
-
const r = handleMessage(msg, emit, streamedAny, cwd);
|
|
219
|
+
const r = handleMessage(msg, emit, streamedAny, cwd, flow);
|
|
219
220
|
if (r.streamed) streamedAny = true;
|
|
220
221
|
if (r.result != null) resultText = r.result;
|
|
221
222
|
}
|
|
@@ -254,14 +255,35 @@ function toolResultText(content) {
|
|
|
254
255
|
// Map one stream-json message to emit() calls. Returns { streamed, result }.
|
|
255
256
|
// The CLI's stream-json mirrors the SDK message shapes. Exported so the custom
|
|
256
257
|
// engine can reuse it for agents that emit Claude-style stream-json.
|
|
257
|
-
|
|
258
|
+
// WHERE ONE TEXT ENDS AND THE NEXT BEGINS. Claude Code narrates before it acts ("I'll check the
|
|
259
|
+
// catalog first…"), calls its tools, then answers — two assistant messages, both streamed as
|
|
260
|
+
// text deltas. Concatenated as they arrive they read "…writing the table.> Assuming", and a
|
|
261
|
+
// note or a chat bubble shows the blockquote marker glued to the previous sentence. `flow`
|
|
262
|
+
// (one object per run, passed by the caller) remembers how the last text ended and whether a
|
|
263
|
+
// tool call happened since; the next text after a tool call gets a paragraph break unless the
|
|
264
|
+
// previous text already ended with one. A caller that passes no `flow` gets the old
|
|
265
|
+
// behaviour — the custom engine reuses this and does not need it.
|
|
266
|
+
function textBoundary(flow, emit) {
|
|
267
|
+
if (!flow) return;
|
|
268
|
+
if (flow.boundary && flow.sawText && !/\n$/.test(flow.tail)) emit({ type: 'delta', text: '\n\n' });
|
|
269
|
+
flow.boundary = false;
|
|
270
|
+
}
|
|
271
|
+
function noteText(flow, text) {
|
|
272
|
+
if (!flow || !text) return;
|
|
273
|
+
flow.sawText = true;
|
|
274
|
+
flow.tail = text.slice(-2);
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
export function handleMessage(msg, emit, alreadyStreamed, cwdForSteps = '', flow = null) {
|
|
258
278
|
const out = { streamed: false, result: null };
|
|
259
279
|
if (msg.type === 'stream_event') {
|
|
260
280
|
const ev = msg.event;
|
|
261
281
|
if (ev?.type === 'content_block_delta') {
|
|
262
282
|
if (ev.delta?.type === 'text_delta') {
|
|
263
283
|
out.streamed = true;
|
|
284
|
+
textBoundary(flow, emit);
|
|
264
285
|
emit({ type: 'delta', text: ev.delta.text });
|
|
286
|
+
noteText(flow, ev.delta.text);
|
|
265
287
|
} else if (ev.delta?.type === 'thinking_delta') {
|
|
266
288
|
emit({ type: 'reasoning', text: ev.delta.thinking || '' });
|
|
267
289
|
}
|
|
@@ -269,6 +291,7 @@ export function handleMessage(msg, emit, alreadyStreamed, cwdForSteps = '') {
|
|
|
269
291
|
} else if (msg.type === 'assistant') {
|
|
270
292
|
for (const block of msg.message?.content || []) {
|
|
271
293
|
if (block.type === 'tool_use') {
|
|
294
|
+
if (flow) flow.boundary = true;
|
|
272
295
|
// PHASE-BASED, like the Codex engine: the panel renders a step with the call's
|
|
273
296
|
// arguments and then fills in its status and output when the result arrives. The old
|
|
274
297
|
// single `summary` event produced one anonymous line per call and no outcome — you
|
|
@@ -281,7 +304,9 @@ export function handleMessage(msg, emit, alreadyStreamed, cwdForSteps = '') {
|
|
|
281
304
|
});
|
|
282
305
|
} else if (block.type === 'text' && !alreadyStreamed) {
|
|
283
306
|
out.streamed = true;
|
|
307
|
+
textBoundary(flow, emit);
|
|
284
308
|
emit({ type: 'delta', text: block.text });
|
|
309
|
+
noteText(flow, block.text);
|
|
285
310
|
}
|
|
286
311
|
}
|
|
287
312
|
} else if (msg.type === 'user') {
|
|
@@ -476,6 +501,8 @@ async function sdkChat({ messages, system, options }, emit, { signal } = {}) {
|
|
|
476
501
|
: { behavior: 'deny', message: `${toolName} blocked — set this agent's permission mode in ChatPanel to enable it.` };
|
|
477
502
|
|
|
478
503
|
let streamedAny = false;
|
|
504
|
+
|
|
505
|
+
const flow = { sawText: false, tail: '', boundary: false };
|
|
479
506
|
let resultText = '';
|
|
480
507
|
const iterator = query({
|
|
481
508
|
prompt: buildCliPrompt(messages),
|
|
@@ -495,7 +522,7 @@ async function sdkChat({ messages, system, options }, emit, { signal } = {}) {
|
|
|
495
522
|
});
|
|
496
523
|
try {
|
|
497
524
|
for await (const message of iterator) {
|
|
498
|
-
const r = handleMessage(message, emit, streamedAny, cwd);
|
|
525
|
+
const r = handleMessage(message, emit, streamedAny, cwd, flow);
|
|
499
526
|
if (r.streamed) streamedAny = true;
|
|
500
527
|
if (r.result != null) resultText = r.result;
|
|
501
528
|
}
|
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.14';
|
|
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
|
|
|
@@ -445,6 +445,9 @@ async function handleHealth(res) {
|
|
|
445
445
|
json(res, 200, {
|
|
446
446
|
ok: true, version: VERSION, agents, update,
|
|
447
447
|
workspace: DEFAULT_WORKSPACE,
|
|
448
|
+
// WHO STARTED THIS PROCESS — additive. ChatPanel Desktop sets CHATPANEL_MANAGED_BY=desktop on
|
|
449
|
+
// the login service it registers; a client can then say so instead of offering install.sh.
|
|
450
|
+
...(process.env.CHATPANEL_MANAGED_BY ? { managedBy: String(process.env.CHATPANEL_MANAGED_BY).slice(0, 32) } : {}),
|
|
448
451
|
...(skills ? { skills } : {}),
|
|
449
452
|
});
|
|
450
453
|
}
|
package/src/update.js
CHANGED
|
@@ -24,6 +24,18 @@ const LATEST_API = `https://api.github.com/repos/${REPO}/releases/latest`;
|
|
|
24
24
|
const CHECK_EVERY_MS = 6 * 60 * 60 * 1000; // 6h
|
|
25
25
|
const CACHE = path.join(os.homedir(), '.chatpanel', 'update-check.json');
|
|
26
26
|
const UA = { 'User-Agent': 'chatpanel-bridge-updater' };
|
|
27
|
+
// THIS CHECK RUNS INSIDE /health. Every client heartbeat — the extension, the desktop's
|
|
28
|
+
// supervisor, the gateway's model list — waits on it. An un-timed fetch to GitHub therefore
|
|
29
|
+
// made every one of them wait for a VPN to give up on api.github.com, and the desktop gives a
|
|
30
|
+
// health answer 2.5s before calling the bridge dead. So: a short timeout, and after a failure
|
|
31
|
+
// no retry for a while — a failed check that was re-attempted on every call kept the stall
|
|
32
|
+
// going for as long as the network was bad.
|
|
33
|
+
const FETCH_TIMEOUT_MS = Math.max(500, Number(process.env.CHATPANEL_UPDATE_TIMEOUT_MS) || 5000);
|
|
34
|
+
const RETRY_AFTER_FAILURE_MS = 10 * 60 * 1000; // 10min
|
|
35
|
+
let lastFailure = { at: 0, error: '' };
|
|
36
|
+
|
|
37
|
+
/** Test seam: forget the last failure so the next unforced check reaches the network. */
|
|
38
|
+
export function resetUpdateBackoff() { lastFailure = { at: 0, error: '' }; }
|
|
27
39
|
|
|
28
40
|
// Release asset name for THIS platform (matches release-binaries.yml outputs).
|
|
29
41
|
// macOS publishes arm64 only; Intel Macs use `npx` (managed → no self-update).
|
|
@@ -95,21 +107,41 @@ export async function checkForUpdate(current, { force = false } = {}) {
|
|
|
95
107
|
if (!force && cache && Date.now() - cache.checkedAt < CHECK_EVERY_MS) {
|
|
96
108
|
latest = cache.latest;
|
|
97
109
|
assetUrl = cache.assetUrl;
|
|
110
|
+
} else if (!force && lastFailure.at && Date.now() - lastFailure.at < RETRY_AFTER_FAILURE_MS) {
|
|
111
|
+
// The network said no a moment ago. Asking again on every health poll would make every
|
|
112
|
+
// poll as slow as the failure; the answer is what it was, and says so.
|
|
113
|
+
error = lastFailure.error;
|
|
114
|
+
fallBackToCache();
|
|
98
115
|
} else {
|
|
116
|
+
// An explicit timer, not AbortSignal.timeout: that one's timer is unref'd, so in a
|
|
117
|
+
// process with nothing else to do (a test, a CLI one-shot) the loop can exit before it
|
|
118
|
+
// fires and the fetch is neither answered nor abandoned.
|
|
119
|
+
const ctl = new AbortController();
|
|
120
|
+
const timer = setTimeout(() => ctl.abort(), FETCH_TIMEOUT_MS);
|
|
99
121
|
try {
|
|
100
|
-
const res = await fetch(LATEST_API, {
|
|
122
|
+
const res = await fetch(LATEST_API, {
|
|
123
|
+
headers: { Accept: 'application/vnd.github+json', ...UA },
|
|
124
|
+
signal: ctl.signal,
|
|
125
|
+
});
|
|
101
126
|
if (res.ok) {
|
|
102
127
|
const data = await res.json();
|
|
103
128
|
latest = parseVersion(data.tag_name) || parseVersion(data.name);
|
|
104
129
|
assetUrl = want ? (data.assets || []).find((a) => a.name === want)?.browser_download_url || null : null;
|
|
105
130
|
await writeCache({ checkedAt: Date.now(), latest, assetUrl });
|
|
131
|
+
lastFailure = { at: 0, error: '' };
|
|
106
132
|
} else {
|
|
107
133
|
error = res.status === 403 ? 'GitHub rate limit (60/hour per IP) — try again later' : `HTTP ${res.status}`;
|
|
134
|
+
lastFailure = { at: Date.now(), error };
|
|
108
135
|
fallBackToCache();
|
|
109
136
|
}
|
|
110
137
|
} catch (e) {
|
|
111
|
-
error =
|
|
138
|
+
error = ctl.signal.aborted
|
|
139
|
+
? `GitHub did not answer within ${Math.round(FETCH_TIMEOUT_MS / 1000)}s`
|
|
140
|
+
: e?.message || String(e);
|
|
141
|
+
lastFailure = { at: Date.now(), error };
|
|
112
142
|
fallBackToCache();
|
|
143
|
+
} finally {
|
|
144
|
+
clearTimeout(timer);
|
|
113
145
|
}
|
|
114
146
|
}
|
|
115
147
|
const updateAvailable = !!latest && cmp(latest, current) > 0;
|