Skip to content

Commit 3959464

Browse files
committed
feat(model): show favorites source hint when only default model is available
1 parent 0943a79 commit 3959464

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

src/bot/handlers/model.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
import { Context, InlineKeyboard } from "grammy";
22
import { selectModel, getFavoriteModels, fetchCurrentModel } from "../../model/manager.js";
33
import { formatModelForDisplay } from "../../model/types.js";
4-
import type { ModelInfo } from "../../model/types.js";
4+
import type { FavoriteModel, ModelInfo } from "../../model/types.js";
55
import { formatVariantForButton } from "../../variant/manager.js";
66
import { logger } from "../../utils/logger.js";
77
import { createMainKeyboard } from "../utils/keyboard.js";
88
import { getStoredAgent } from "../../agent/manager.js";
99
import { pinnedMessageManager } from "../../pinned/manager.js";
1010
import { keyboardManager } from "../../keyboard/manager.js";
11+
import { config } from "../../config.js";
1112
import {
1213
clearActiveInlineMenu,
1314
ensureActiveInlineMenu,
1415
replyWithInlineMenu,
1516
} from "./inline-menu.js";
1617
import { t } from "../../i18n/index.js";
1718

19+
function isOnlyConfigDefaultModel(models: FavoriteModel[]): boolean {
20+
if (models.length !== 1) {
21+
return false;
22+
}
23+
24+
const defaultProviderID = config.opencode.model.provider;
25+
const defaultModelID = config.opencode.model.modelId;
26+
27+
if (!defaultProviderID || !defaultModelID) {
28+
return false;
29+
}
30+
31+
return models[0].providerID === defaultProviderID && models[0].modelID === defaultModelID;
32+
}
33+
1834
/**
1935
* Handle model selection callback
2036
* @param ctx grammY context
@@ -112,9 +128,12 @@ export async function handleModelSelect(ctx: Context): Promise<boolean> {
112128
* @param currentModel Current model for highlighting
113129
* @returns InlineKeyboard with model selection buttons
114130
*/
115-
export async function buildModelSelectionMenu(currentModel?: ModelInfo): Promise<InlineKeyboard> {
131+
export async function buildModelSelectionMenu(
132+
currentModel?: ModelInfo,
133+
favoriteModels?: FavoriteModel[],
134+
): Promise<InlineKeyboard> {
116135
const keyboard = new InlineKeyboard();
117-
const favorites = await getFavoriteModels();
136+
const favorites = favoriteModels ?? (await getFavoriteModels());
118137

119138
if (favorites.length === 0) {
120139
logger.warn("[ModelHandler] No favorite models found");
@@ -145,7 +164,8 @@ export async function buildModelSelectionMenu(currentModel?: ModelInfo): Promise
145164
export async function showModelSelectionMenu(ctx: Context): Promise<void> {
146165
try {
147166
const currentModel = fetchCurrentModel();
148-
const keyboard = await buildModelSelectionMenu(currentModel);
167+
const favorites = await getFavoriteModels();
168+
const keyboard = await buildModelSelectionMenu(currentModel, favorites);
149169

150170
if (keyboard.inline_keyboard.length === 0) {
151171
await ctx.reply(t("model.menu.empty"));
@@ -161,6 +181,10 @@ export async function showModelSelectionMenu(ctx: Context): Promise<void> {
161181
text,
162182
keyboard,
163183
});
184+
185+
if (isOnlyConfigDefaultModel(favorites)) {
186+
await ctx.reply(t("model.menu.favorites_hint"));
187+
}
164188
} catch (err) {
165189
logger.error("[ModelHandler] Error showing model menu:", err);
166190
await ctx.reply(t("model.menu.error"));

src/i18n/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ export const en = {
170170
"model.change_error_callback": "Failed to change model",
171171
"model.menu.empty": "⚠️ No available models",
172172
"model.menu.current": "Current model: {name}\n\nSelect model:",
173+
"model.menu.favorites_hint": "ℹ️ The model list is built from favorites in OpenCode CLI.",
173174
"model.menu.error": "🔴 Failed to get models list",
174175

175176
"variant.model_not_selected_callback": "Error: model is not selected",

src/i18n/ru.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ export const ru: I18nDictionary = {
171171
"model.change_error_callback": "Ошибка при смене модели",
172172
"model.menu.empty": "⚠️ Нет доступных моделей",
173173
"model.menu.current": "Текущая модель: {name}\n\nВыберите модель:",
174+
"model.menu.favorites_hint":
175+
"ℹ️ Список моделей формируется из favorites в OpenCode CLI.",
174176
"model.menu.error": "🔴 Не удалось получить список моделей",
175177

176178
"variant.model_not_selected_callback": "Ошибка: модель не выбрана",

0 commit comments

Comments
 (0)