/clear из лички: выбор чата кнопками с подтверждением

- /clear в личке с ботом показывает чаты с контекстом диалога (название и число реплик), дальше подтверждение
- /clear <ID чата> в личке — сразу подтверждение для этого чата; в группе /clear работает как раньше
- Общий хелпер chatTitle для /archive и /clear

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
yunogasai
2026-09-25 15:17:18 +02:00
parent f5d1ea6be2
commit 08108f5e1f
7 changed files with 99 additions and 17 deletions

View File

@@ -7,7 +7,7 @@ import type { Persona } from "../../types.js";
import type { ChatHistoryService } from "../chat-history-service.js";
import type { ChatMemberService } from "../chat-member-service.js";
import { stripPastReasoning } from "./history-compat.js";
import { chatThreadId } from "./memory.js";
import { chatIdOfThread, chatThreadId } from "./memory.js";
import { buildInstructions, buildUserText, type Question } from "./prompts.js";
import { createListChatMembersTool } from "./tools/list-chat-members-tool.js";
import { createReadChatMessagesTool } from "./tools/read-chat-messages-tool.js";
@@ -117,8 +117,23 @@ export const createAssistantService = ({
/** Начать диалог с чистого листа: удаляем тред чата из Memory. Архив чата не трогаем. */
const clearDialog = (chatId: number): Promise<void> => memory.deleteThread(chatThreadId(chatId));
/** Чаты, где есть контекст диалога, и сколько в нём реплик — для выбора в личке с ботом. */
const dialogChats = async (): Promise<{ chatId: number; messages: number }[]> => {
const { threads } = await memory.listThreads({ perPage: false });
const chatIds = threads.flatMap((thread) => {
const chatId = chatIdOfThread(thread.id);
return chatId === undefined ? [] : [chatId];
});
const chats = await Promise.all(chatIds.map(async (chatId) => ({ chatId, messages: await dialogSize(chatId) })));
return chats.filter((chat) => chat.messages > 0).sort((a, b) => b.messages - a.messages);
};
/** Боту стоит скачивать фото, только если модель умеет их смотреть. */
return { answer, dialogSize, clearDialog, canSeeImages: imageInput };
return { answer, dialogSize, clearDialog, dialogChats, canSeeImages: imageInput };
};
export type AssistantService = ReturnType<typeof createAssistantService>;