feat(ai): improve runtime capability reporting and context settings

Add explicit chat capability tracking, expose formatted runtime capabilities
in the info command, and support a max context size option for user AI settings.

Also update Ollama base URL resolution to use OLLAMA_ADDRESS and simplify
provider chat command execution.
This commit is contained in:
2026-05-11 02:01:44 +03:00
parent d2464b9b21
commit 3848dd82d9
15 changed files with 850 additions and 336 deletions
+20 -26
View File
@@ -2,13 +2,13 @@ import {ChatCommand} from "../base/chat-command";
import {Message} from "typescript-telegram-bot-api";
import {callbackCommands, commands} from "../index";
import {Environment} from "../common/environment";
import {getCurrentModel, logError, replyToMessage} from "../util/utils";
import {AiModelCapabilities} from "../model/ai-model-capabilities";
import {logError, replyToMessage} from "../util/utils";
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";
import {resolveEffectiveAiProviderForUser} from "../common/user-ai-settings";
import {getFormattedCapabilities} from "../ai/provider-model-runtime";
export class Info extends Command {
command = ["info", "v"];
@@ -17,30 +17,10 @@ export class Info extends Command {
description = Environment.commandDescriptions.info;
async execute(msg: Message): Promise<void> {
const aiProvider = Environment.DEFAULT_AI_PROVIDER;
const aiModel = getCurrentModel();
if (!aiModel) return;
let aiModelCapabilities: AiModelCapabilities | null = null;
try {
aiModelCapabilities = await getRuntimeCapabilities(aiProvider, aiModel);
} catch (e) {
logError(e);
await replyToMessage({message: msg, text: Environment.getErrorText(e)}).catch(logError);
return;
}
const supportedProvidersLength = Object.keys(AiProvider).filter(key => isNaN(Number(key))).length;
const getAiInfo = async () => {
return Environment.getInfoAiBlockText(
supportedProvidersLength,
await formatRuntimeModelInfo(aiProvider, aiModel, aiModelCapabilities),
);
};
if (!msg.from) return;
const getToolsInfo = async () => {
const tools = getProviderTools(aiProvider);
const tools = getProviderTools(provider);
return Environment.getInfoToolsBlockText(tools.map(t => t.function.name));
};
@@ -61,13 +41,27 @@ export class Info extends Command {
});
};
const provider = await resolveEffectiveAiProviderForUser(msg.from.id);
// const aiProvidersLength = Object.keys(AiProvider).filter(key => isNaN(Number(key))).length;
const aiProviders = Object.keys(AiProvider).map(p => p.toLowerCase());
const finalText = [
await getAiInfo(),
`\`\`\`${Environment.runtimeProviderLabelText}`,
`${Environment.infoSupportedProvidersLabelText}: ${aiProviders.join(", ")}`,
`${Environment.runtimeProviderCurrentLabelText}: ${provider.toLowerCase()}`,
"```",
"",
`\`\`\`${Environment.runtimeCapabilitiesLabelText}`,
(await getFormattedCapabilities(provider)).join("\n"),
"```",
"",
await getToolsInfo(),
await getCommandsInfo()
].join("\n");
await replyToMessage({
message: msg,
text: prepareTelegramMarkdownV2(finalText, {mode: "final"}),