fix(images): cache Telegram photos by unique_id and pass base64 to LLM commands

Stop reading image files inside gemini/mistral commands; use pre-encoded image data from message parts

Rework loadImagesIfExists / loadImagesFromFileIds to return cached file_unique_ids and download only missing sizes

Encode cached images to base64 when assembling the reply chain

Make getPhotoMaxSize synchronous (returns PhotoSize), and map to URL only when needed

Await MessageStore.put / UserStore.put and prefetch single-image downloads on message receipt
This commit is contained in:
2026-01-29 20:58:08 +03:00
parent 4945db86c0
commit 9e30086af2
5 changed files with 59 additions and 33 deletions
+2 -1
View File
@@ -1,6 +1,6 @@
import {StoredMessage} from "../model/stored-message";
import {Message} from "typescript-telegram-bot-api";
import {extractTextMessage, isStoredMessage} from "../util/utils";
import {extractTextMessage, getPhotoMaxSize, isStoredMessage} from "../util/utils";
import {messageDao} from "../index";
export class MessageStore {
@@ -22,6 +22,7 @@ export class MessageStore {
fromId: m.from.id,
text: extractTextMessage(m),
date: m.date ?? 0,
photoMaxSizeFilePath: m.photo ? [getPhotoMaxSize(m.photo).file_unique_id] : null
};
this.map.set(this.key(msg.chatId, msg.id), msg);
+2 -1
View File
@@ -9,7 +9,7 @@ export class UserStore {
return this.map;
}
static async put(u: User) {
static async put(u: User): Promise<StoredUser> {
const user: StoredUser = {
id: u.id,
isBot: u.is_bot,
@@ -22,6 +22,7 @@ export class UserStore {
this.map.set(u.id, user);
await userDao.insert(userDao.mapTo([u]));
return user;
}
static async get(id: number): Promise<StoredUser | null> {