From aed722c52b735f9596c258c05fde95653b28e407 Mon Sep 17 00:00:00 2001 From: Mario Zechner Date: Sat, 4 Apr 2026 03:50:13 +0200 Subject: [PATCH] fix: handle telegram compact command --- index.ts | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.ts b/index.ts index 23e821f..c7bcfa8 100644 --- a/index.ts +++ b/index.ts @@ -755,6 +755,24 @@ export default function (pi: ExtensionAPI) { return; } + if (lower === "/compact") { + if (!ctx.isIdle()) { + await sendTextReply(firstMessage.chat.id, firstMessage.message_id, "Cannot compact while pi is busy. Send \"stop\" first."); + return; + } + ctx.compact({ + onComplete: () => { + void sendTextReply(firstMessage.chat.id, firstMessage.message_id, "Compaction completed."); + }, + onError: (error) => { + const message = error instanceof Error ? error.message : String(error); + void sendTextReply(firstMessage.chat.id, firstMessage.message_id, `Compaction failed: ${message}`); + }, + }); + await sendTextReply(firstMessage.chat.id, firstMessage.message_id, "Compaction started."); + return; + } + if (lower === "/status") { let totalInput = 0; let totalOutput = 0; @@ -806,7 +824,7 @@ export default function (pi: ExtensionAPI) { await sendTextReply( firstMessage.chat.id, firstMessage.message_id, - `Send me a message and I will forward it to pi. Send \"stop\" to abort the current turn.`, + `Send me a message and I will forward it to pi. Commands: /status, /compact, stop.`, ); if (config.allowedUserId === undefined && firstMessage.from) { config.allowedUserId = firstMessage.from.id;