ui(redstone): dismiss /model keyboard on selection

selectModel was re-rendering the full picker with the  moved to the
new pick. Per design feedback, drop the keyboard once a choice is made
— the callback toast plus a confirmation body is enough. Keeps the
chat tidy after the switch.

editMessageText without reply_markup clears the inline keyboard.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-14 00:04:36 +02:00
parent aae9ddd429
commit a9a8bbe3dd

View File

@@ -684,31 +684,16 @@ async function selectModel(ctx: Context, modelId: string) {
return;
}
kvSet("llm_model", modelId);
await ctx.answerCallbackQuery({ text: `model: ${modelId}` });
// Re-render the picker so the ✅ moves to the new pick.
await ctx.answerCallbackQuery({ text: `model set: ${modelId}` });
// Dismiss the keyboard and replace the picker body with a confirmation.
// editMessageText with no reply_markup clears the inline keyboard.
try {
const models = await fetchOpenRouterModels();
const usable = models.filter((m) => m.supported_parameters?.includes("tools"));
const ROUTER_RE = /^openrouter\/(free|auto)\b/;
const routers = usable.filter((m) => ROUTER_RE.test(m.id));
const rest = usable.filter((m) => !ROUTER_RE.test(m.id))
.sort((a, b) => {
const af = isFreeModel(a), bf = isFreeModel(b);
if (af !== bf) return af ? -1 : 1;
return (a.name || a.id).localeCompare(b.name || b.id);
});
const list = [...routers, ...rest].slice(0, 20);
const kb = new InlineKeyboard();
for (const m of list) {
kb.text(modelButtonLabel(m, m.id === modelId), `model:${m.id}`).row();
}
const header =
`<b>🧠 LLM model picker</b>\n\n` +
`Active: <code>${escape(modelId)}</code>\n\n` +
`🟢 free · 💰 paid · 🛠 tools · 🧠 thinking`;
await ctx.editMessageText(header, { parse_mode: "HTML", reply_markup: kb });
await ctx.editMessageText(
`<b>🧠 LLM model</b>\n\nActive: <code>${escape(modelId)}</code>\n\n<i>Switched. The new model takes effect on the next message.</i>`,
{ parse_mode: "HTML" },
);
} catch {
/* leave keyboard as-is if refresh fails */
/* edit can fail if the original message is too old; the toast already confirmed */
}
}