fix: handle telegram compact command

This commit is contained in:
Mario Zechner
2026-04-04 03:50:13 +02:00
parent caf3617747
commit aed722c52b
+19 -1
View File
@@ -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;