@chatpanel/bridge 0.11.13 → 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 +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.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
|
|