@chatpanel/bridge 0.10.33 → 0.10.34

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chatpanel/bridge",
3
- "version": "0.10.33",
3
+ "version": "0.10.34",
4
4
  "type": "module",
5
5
  "description": "Local bridge that exposes the AI coding agents installed on your machine \u2014 Claude Code (CLI), Codex (CLI), and Antigravity CLI (formerly Gemini CLI, which remains available for business/enterprise) \u2014 to the ChatPanel Chrome extension over a localhost SSE endpoint. Bring your own agent.",
6
6
  "keywords": [
@@ -166,6 +166,18 @@ function runClaude({ prompt, args, cwd, emit, signal }) {
166
166
  });
167
167
  }
168
168
 
169
+ // A tool_result's content is either a string or Anthropic's block array. Flatten to text and
170
+ // cap it: the panel truncates for display anyway, and an un-capped file read would otherwise
171
+ // push megabytes through the SSE for no benefit.
172
+ function toolResultText(content) {
173
+ let text = '';
174
+ if (typeof content === 'string') text = content;
175
+ else if (Array.isArray(content)) {
176
+ text = content.map((c) => (typeof c === 'string' ? c : (c?.text || ''))).filter(Boolean).join('\n');
177
+ }
178
+ return text.length > 4000 ? `${text.slice(0, 4000)}…` : text;
179
+ }
180
+
169
181
  // Map one stream-json message to emit() calls. Returns { streamed, result }.
170
182
  // The CLI's stream-json mirrors the SDK message shapes. Exported so the custom
171
183
  // engine can reuse it for agents that emit Claude-style stream-json.
@@ -184,12 +196,33 @@ export function handleMessage(msg, emit, alreadyStreamed, cwdForSteps = '') {
184
196
  } else if (msg.type === 'assistant') {
185
197
  for (const block of msg.message?.content || []) {
186
198
  if (block.type === 'tool_use') {
187
- emit({ type: 'tool', name: block.name, summary: toolSummary(block, cwdForSteps) });
199
+ // PHASE-BASED, like the Codex engine: the panel renders a step with the call's
200
+ // arguments and then fills in its status and output when the result arrives. The old
201
+ // single `summary` event produced one anonymous line per call and no outcome — you
202
+ // could see that Claude did something, never what it returned. `summary` is still
203
+ // sent so an older extension keeps the line it used to draw.
204
+ emit({
205
+ type: 'tool', name: block.name, phase: 'start',
206
+ callId: block.id, input: block.input,
207
+ summary: toolSummary(block, cwdForSteps),
208
+ });
188
209
  } else if (block.type === 'text' && !alreadyStreamed) {
189
210
  out.streamed = true;
190
211
  emit({ type: 'delta', text: block.text });
191
212
  }
192
213
  }
214
+ } else if (msg.type === 'user') {
215
+ // Claude reports every tool's OUTCOME as a tool_result block on a synthetic user message.
216
+ // Pairing it with the call by tool_use_id is what turns the step list into a readable
217
+ // log: each action shows ok / error and the text the tool actually returned.
218
+ for (const block of msg.message?.content || []) {
219
+ if (block.type !== 'tool_result') continue;
220
+ emit({
221
+ type: 'tool', phase: 'done', callId: block.tool_use_id,
222
+ status: block.is_error ? 'error' : 'ok',
223
+ result: toolResultText(block.content),
224
+ });
225
+ }
193
226
  } else if (msg.type === 'result') {
194
227
  if (msg.subtype === 'success') out.result = msg.result || '';
195
228
  else emit({ type: 'status', text: `(${msg.subtype})` });
@@ -86,8 +86,23 @@ function opencodeJson(emit) {
86
86
  streamed = true;
87
87
  emit({ type: 'delta', text: ev.part.text });
88
88
  } else if (ev.type === 'tool' || ev.type === 'tool_use') {
89
+ // Phase-based where opencode gives us enough to pair a call with its outcome: its tool
90
+ // parts carry a callID and a state that moves running → completed/error. Without that we
91
+ // still emit a start, so the step at least appears (the old behaviour).
89
92
  const p = ev.part || {};
90
- emit({ type: 'tool', name: p.tool || p.name || p.type || 'tool', summary: '' });
93
+ const name = p.tool || p.name || p.type || 'tool';
94
+ const callId = p.callID || p.callId || p.id || undefined;
95
+ const state = p.state || {};
96
+ const status = String(state.status || '').toLowerCase();
97
+ if (status === 'completed' || status === 'error') {
98
+ emit({
99
+ type: 'tool', name, phase: 'done', callId,
100
+ status: status === 'error' ? 'error' : 'ok',
101
+ result: String(state.output || state.error || '').slice(0, 4000),
102
+ });
103
+ } else {
104
+ emit({ type: 'tool', name, phase: 'start', callId, input: state.input || p.input, summary: '' });
105
+ }
91
106
  } else if (ev.type === 'error') {
92
107
  const msg = ev.error?.data?.message || ev.error?.message || ev.error?.name || 'error';
93
108
  emit({ type: 'status', text: String(msg).slice(0, 300) });
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.10.33';
70
+ const VERSION = '0.10.34';
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