commands: switch AI commands to unified runtime

This commit is contained in:
2026-05-10 22:53:22 +03:00
parent 1b94760b21
commit 3d14e3c0d5
24 changed files with 465 additions and 3580 deletions
+47 -38
View File
@@ -2,67 +2,76 @@ import {ChatCommand} from "../base/chat-command";
import {Message} from "typescript-telegram-bot-api";
import {callbackCommands, commands} from "../index";
import {Environment} from "../common/environment";
import {boolToEmoji, getCurrentModel, getCurrentModelCapabilities, logError, replyToMessage} from "../util/utils";
import {getCurrentModel, logError, replyToMessage} from "../util/utils";
import {AiModelCapabilities} from "../model/ai-model-capabilities";
import {AiProvider} from "../model/ai-provider";
import {Command} from "../base/command";
import {formatRuntimeModelInfo, getRuntimeCapabilities} from "../ai/provider-model-runtime";
import {getProviderTools} from "../ai/tool-mappers";
import {prepareTelegramMarkdownV2} from "../util/markdown-v2-renderer";
export class Info extends Command {
command = ["info", "v"];
title = "/info";
description = "Info about bot";
title = Environment.commandTitles.info;
description = Environment.commandDescriptions.info;
async execute(msg: Message): Promise<void> {
const aiProvider = Environment.DEFAULT_AI_PROVIDER;
const aiModel = getCurrentModel();
let aiModelCapabilities: AiModelCapabilities | null = {};
if (!aiModel) return;
let aiModelCapabilities: AiModelCapabilities | null = null;
try {
aiModelCapabilities = await getCurrentModelCapabilities();
aiModelCapabilities = await getRuntimeCapabilities(aiProvider, aiModel);
} catch (e) {
logError(e);
await replyToMessage({message: msg, text: `Произошла ошибка: ${e}`}).catch(logError);
await replyToMessage({message: msg, text: Environment.getErrorText(e)}).catch(logError);
return;
}
const supportedProvidersLength = Object.keys(AiProvider).filter(key => isNaN(Number(key))).length;
const aiInfo = "```" +
"AI\n" +
`supported providers: ${Object.keys(AiProvider).filter(key => isNaN(Number(key))).length}\n\n` +
const getAiInfo = async () => {
return Environment.getInfoAiBlockText(
supportedProvidersLength,
await formatRuntimeModelInfo(aiProvider, aiModel, aiModelCapabilities),
);
};
`provider: ${aiProvider.toLowerCase()}\n` +
`model: ${aiModel}\n\n` +
`vision${aiModelCapabilities?.vision?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities?.vision?.supported)}\n` +
`ocr${aiModelCapabilities?.ocr?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities?.ocr?.supported)}\n` +
`thinking${aiModelCapabilities?.thinking?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities?.thinking?.supported)}\n` +
`tools${aiModelCapabilities?.tools?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities?.tools?.supported)}\n` +
`audio${aiModelCapabilities?.audio?.external ? "(ext)" : ""}: ${boolToEmoji(aiModelCapabilities?.audio?.supported)}` +
"```";
const getToolsInfo = async () => {
const tools = getProviderTools(aiProvider);
return Environment.getInfoToolsBlockText(tools.map(t => t.function.name));
};
const cmds = commands.filter(c => !(c instanceof ChatCommand));
const chatCmds = commands.filter(c => c instanceof ChatCommand);
const callbackCmds = callbackCommands;
const getCommandsInfo = async () => {
const cmds = commands.filter(c => !(c instanceof ChatCommand));
const chatCmds = commands.filter(c => c instanceof ChatCommand);
const callbackCmds = callbackCommands;
const publicCmdsLength = cmds.filter(c => c.requirements?.isPublic()).length;
const privateCmdsLength = cmds.length - publicCmdsLength;
const chatCmdsLength = chatCmds.length;
const callbackCmdsLength = callbackCmds.length;
const publicCmdsLength = cmds.filter(c => c.requirements?.isPublic()).length;
const privateCmdsLength = cmds.length - publicCmdsLength;
return Environment.getInfoCommandsBlockText({
publicCommands: publicCmdsLength,
privateCommands: privateCmdsLength,
chatCommands: chatCmdsLength,
callbackCommands: callbackCmdsLength,
});
};
const chatCmdsLength = chatCmds.length;
const callbackCmdsLength = callbackCmds.length;
const finalText = [
await getAiInfo(),
await getToolsInfo(),
await getCommandsInfo()
].join("\n");
const text =
aiInfo + "\n\n" +
"```" +
"Commands\n" +
`Public: ${publicCmdsLength}\n` +
`Private: ${privateCmdsLength}\n` +
`Chat: ${chatCmdsLength}\n` +
`Callback: ${callbackCmdsLength}\n` +
"```"
;
await replyToMessage({message: msg, text: text, parse_mode: "Markdown"}).catch(logError);
await replyToMessage({
message: msg,
text: prepareTelegramMarkdownV2(finalText, {mode: "final"}),
parse_mode: "MarkdownV2"
}).catch(logError);
}
}
}