@gonzih/cc-discord 0.2.46 → 0.2.48
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/dist/meta-agent-manager.js +10 -10
- package/dist/notifier.js +25 -1
- package/package.json +1 -1
|
@@ -252,20 +252,20 @@ function wireStdoutToRedis(proc, ns, wire) {
|
|
|
252
252
|
if (rl?.overageStatus === "rejected" && !rateLimitNotified) {
|
|
253
253
|
rateLimitNotified = true;
|
|
254
254
|
const resetsAt = rl.resetsAt ? new Date(rl.resetsAt * 1000).toLocaleTimeString("en-US", { hour: "numeric", minute: "2-digit", timeZoneName: "short" }) : "soon";
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
role: "assistant",
|
|
259
|
-
content: `⏳ Rate limited — five-hour window exhausted. Resets at **${resetsAt}**. Session paused; send any message after reset to resume.`,
|
|
260
|
-
timestamp: new Date().toISOString(),
|
|
261
|
-
chatId: 0,
|
|
262
|
-
};
|
|
263
|
-
wire.discord.publishOutgoing(ns, alertMsg).catch(() => { });
|
|
264
|
-
// Fire done so notifier finalizes the live message
|
|
255
|
+
const alertContent = `⏳ Rate limited — five-hour window exhausted. Resets at **${resetsAt}**. Session paused; send any message after reset to resume.`;
|
|
256
|
+
// 1. Close the current turn first — finalizes any real response text already in the live state.
|
|
257
|
+
// If this is a pure rate-limit turn (no preceding text), done is a no-op in the notifier.
|
|
265
258
|
rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
|
|
266
259
|
id: crypto.randomUUID(), source: "claude", role: "assistant",
|
|
267
260
|
content: "", event: "done", timestamp: new Date().toISOString(), chatId: 0,
|
|
268
261
|
})).catch(() => { });
|
|
262
|
+
// 2. Send alert tagged as "rate_limit" so the notifier delivers it as a standalone message,
|
|
263
|
+
// not accumulated into whatever text the current live state already holds.
|
|
264
|
+
rawRedis.publish(discordChatOutgoing(ns), JSON.stringify({
|
|
265
|
+
id: crypto.randomUUID(), source: "claude", role: "assistant",
|
|
266
|
+
content: alertContent, event: "rate_limit",
|
|
267
|
+
timestamp: new Date().toISOString(), chatId: 0,
|
|
268
|
+
})).catch(() => { });
|
|
269
269
|
// Kill the process — API calls will hang until reset anyway
|
|
270
270
|
setTimeout(() => {
|
|
271
271
|
try {
|
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;
|
|
@@ -352,8 +352,26 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
|
|
|
352
352
|
scheduleFinal(ns, state);
|
|
353
353
|
return;
|
|
354
354
|
}
|
|
355
|
+
// rate_limit: delivered after the current turn's "done" — send as a standalone message,
|
|
356
|
+
// never accumulate into live state text (which already finalized above via "done").
|
|
357
|
+
if (event === "rate_limit") {
|
|
358
|
+
const alertContent = parsed.content ?? "";
|
|
359
|
+
if (alertContent) {
|
|
360
|
+
bot.sendToChannelById(deliverTo, `← [${ns}]\n${alertContent}`).catch((err) => {
|
|
361
|
+
log("warn", `rate_limit alert send failed (ns=${ns}):`, err.message);
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
355
366
|
// done: immediate finalization (fired by meta-agent-manager after result event)
|
|
356
367
|
if (event === "done") {
|
|
368
|
+
if (state.starting) {
|
|
369
|
+
// startOrGetLiveMessage is still in flight — defer finalization to its .then() callback
|
|
370
|
+
// so we don't race: finalizeState runs before the Discord message exists → fallback
|
|
371
|
+
// sends a second plain message, leaving the live message orphaned with ▋.
|
|
372
|
+
state.pendingDone = true;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
357
375
|
finalizeState(ns, state).catch((err) => {
|
|
358
376
|
log("warn", `meta-agent done finalize failed (ns=${ns}):`, err.message);
|
|
359
377
|
});
|
|
@@ -376,6 +394,12 @@ export function startNotifier(bot, notifyChannelId, namespace, redis, handleUser
|
|
|
376
394
|
state.liveStarted = true;
|
|
377
395
|
bot.updateLiveMessage(deliverTo, textDisplay);
|
|
378
396
|
}
|
|
397
|
+
// done arrived while we were creating the message — finalize now
|
|
398
|
+
if (state.pendingDone) {
|
|
399
|
+
finalizeState(ns, state).catch((err) => {
|
|
400
|
+
log("warn", `meta-agent deferred done finalize failed (ns=${ns}):`, err.message);
|
|
401
|
+
});
|
|
402
|
+
}
|
|
379
403
|
}).catch(() => { state.starting = false; });
|
|
380
404
|
}
|
|
381
405
|
// Text is buffered in state.text; applied when startOrGetLiveMessage resolves
|