@gonzih/cc-discord 0.2.46 → 0.2.47

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.
Files changed (2) hide show
  1. package/dist/notifier.js +14 -1
  2. package/package.json +1 -1
package/dist/notifier.js CHANGED
@@ -274,7 +274,7 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
274
274
  function getLiveState(ns, targetChannelId) {
275
275
  let state = liveStates.get(ns);
276
276
  if (!state) {
277
- state = { text: "", toolStatus: "", targetChannelId, starting: false, liveStarted: false, finalTimer: null };
277
+ state = { text: "", toolStatus: "", targetChannelId, starting: false, liveStarted: false, finalTimer: null, pendingDone: false };
278
278
  liveStates.set(ns, state);
279
279
  }
280
280
  return state;
@@ -354,6 +354,13 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
354
354
  }
355
355
  // done: immediate finalization (fired by meta-agent-manager after result event)
356
356
  if (event === "done") {
357
+ if (state.starting) {
358
+ // startOrGetLiveMessage is still in flight — defer finalization to its .then() callback
359
+ // so we don't race: finalizeState runs before the Discord message exists → fallback
360
+ // sends a second plain message, leaving the live message orphaned with ▋.
361
+ state.pendingDone = true;
362
+ return;
363
+ }
357
364
  finalizeState(ns, state).catch((err) => {
358
365
  log("warn", `meta-agent done finalize failed (ns=${ns}):`, err.message);
359
366
  });
@@ -376,6 +383,12 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
376
383
  state.liveStarted = true;
377
384
  bot.updateLiveMessage(deliverTo, textDisplay);
378
385
  }
386
+ // done arrived while we were creating the message — finalize now
387
+ if (state.pendingDone) {
388
+ finalizeState(ns, state).catch((err) => {
389
+ log("warn", `meta-agent deferred done finalize failed (ns=${ns}):`, err.message);
390
+ });
391
+ }
379
392
  }).catch(() => { state.starting = false; });
380
393
  }
381
394
  // Text is buffered in state.text; applied when startOrGetLiveMessage resolves
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-discord",
3
- "version": "0.2.46",
3
+ "version": "0.2.47",
4
4
  "description": "Claude Code Discord bot — chat with Claude Code via Discord",
5
5
  "type": "module",
6
6
  "bin": {