agentgui 1.0.947 → 1.0.949

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.
@@ -88,8 +88,8 @@ const SYNC_PATH = '/sync';
88
88
  let _ws = null;
89
89
  let _wsReady = null; // Promise that resolves when ws is OPEN
90
90
  let _nextReqId = 1;
91
- const _pending = new Map(); // requestId { resolve, reject }
92
- const _sessionListeners = new Map(); // sessionId Set<(event)=>void>
91
+ const _pending = new Map(); // requestId -> { resolve, reject }
92
+ const _sessionListeners = new Map(); // sessionId -> Set<(event)=>void>
93
93
  const _statusListeners = new Set(); // fn(state) where state in 'open'|'closed'|'error'|'reconnecting'
94
94
  let _reconnectAttempts = 0;
95
95
  let _reconnectTimer = null;
@@ -172,7 +172,7 @@ function ensureWs(base) {
172
172
  else p.resolve(msg.d);
173
173
  return;
174
174
  }
175
- // Unsolicited broadcast route by sessionId to subscribers.
175
+ // Unsolicited broadcast - route by sessionId to subscribers.
176
176
  // Server may send a single event or a batch (array) per ws-optimizer.
177
177
  const items = Array.isArray(msg) ? msg : [msg];
178
178
  for (const item of items) {
@@ -231,9 +231,9 @@ export async function listAgentModels(base, agentId) {
231
231
  // ---------- Streaming chat (WS) ----------
232
232
  //
233
233
  // Yields events of shape:
234
- // { type: 'text', text: '...' } assistant text deltas
235
- // { type: 'tool', block: {...} } tool_use blocks
236
- // { type: 'result', block: {...} } terminal result block
234
+ // { type: 'text', text: '...' } - assistant text deltas
235
+ // { type: 'tool', block: {...} } - tool_use blocks
236
+ // { type: 'result', block: {...} } - terminal result block
237
237
  // { type: 'error', error: '...' }
238
238
  //
239
239
  // Caller signature kept compatible with the previous HTTP/SSE impl.
@@ -268,7 +268,11 @@ export async function* streamChat(base, { model, messages, signal, agentId, resu
268
268
  const finish = () => { done = true; if (resolveWait) { resolveWait(); resolveWait = null; } };
269
269
 
270
270
  const unsub = addSessionListener(sessionId, (ev) => {
271
- if (ev.type === 'streaming_progress') {
271
+ if (ev.type === 'streaming_session') {
272
+ // claude's real session id - surface it so the host can --resume this
273
+ // conversation on the next turn (multi-turn continuity).
274
+ if (ev.claudeSessionId) push({ type: 'session', sessionId: ev.claudeSessionId });
275
+ } else if (ev.type === 'streaming_progress') {
272
276
  const block = ev.block;
273
277
  if (block?.type === 'text' && block.text) push({ type: 'text', text: block.text });
274
278
  else if (block?.type === 'tool_use') push({ type: 'tool', block });
@@ -282,12 +286,12 @@ export async function* streamChat(base, { model, messages, signal, agentId, resu
282
286
  }
283
287
  });
284
288
 
285
- // If the websocket drops mid-stream, streaming_complete will never arrive
289
+ // If the websocket drops mid-stream, streaming_complete will never arrive -
286
290
  // surface an error and end the iterator instead of hanging forever.
287
291
  const onWs = (s) => { if ((s === 'closed' || s === 'error') && !done) { errored = errored || 'connection lost during stream'; finish(); } };
288
292
  const unsubWs = onWsStatus ? onWsStatus(onWs) : null;
289
293
 
290
- // Wire AbortSignal to chat.cancel and end the iterator immediately so the
294
+ // Wire AbortSignal to chat.cancel - and end the iterator immediately so the
291
295
  // caller's busy state clears even if the server never emits a final event.
292
296
  const onAbort = () => { wsCall(base, 'chat.cancel', { sessionId }).catch(() => {}); finish(); };
293
297
  if (signal) {