From dd5c8b08a6503f8dea3fc0eb933c50213744469e Mon Sep 17 00:00:00 2001 From: Loki FastStart Date: Sat, 9 May 2026 22:31:00 +0000 Subject: [PATCH] fix: DRY handleModelAction via applyModelSelection + prefix comment handleModelAction now delegates to applyModelSelection instead of reimplementing settings write + confirmation. Added coupling comment on CALLBACK_PREFIX constant. --- src/gateway/model-command.ts | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/src/gateway/model-command.ts b/src/gateway/model-command.ts index 0e98848..3118f8a 100644 --- a/src/gateway/model-command.ts +++ b/src/gateway/model-command.ts @@ -28,7 +28,7 @@ export const MODEL_ACTION_ID = "model_select"; const SETTINGS_PATH = join(homedir(), ".pi", "agent", "settings.json"); -/** Callback data prefix used by @chat-adapter/telegram */ +/** Callback data prefix used by @chat-adapter/telegram (coupled: if adapter changes this, buttons break) */ const CALLBACK_PREFIX = "chat:"; export interface ModelCommandContext { @@ -157,23 +157,13 @@ export async function handleModelAction(event: { thread: any; }): Promise { const alias = event.value; - if (!alias) return; + if (!alias || !MODEL_ALIASES[alias]) return; - const settings = readSettings(); - const resolved = MODEL_ALIASES[alias]; - if (!resolved) return; + const postFn = async (_t: any, text: string) => { + if (!event.thread) return; + try { await event.thread.post({ markdown: text }); } + catch { try { await event.thread.post(text); } catch {} } + }; - settings.defaultProvider = resolved.provider; - settings.defaultModel = resolved.model; - writeSettings(settings); - - // Post confirmation to the thread - if (event.thread) { - try { - await event.thread.post({ markdown: `✅ Switched to *${resolved.label}*` }); - } catch { - try { await event.thread.post(`✅ Switched to ${resolved.label}`); } catch {} - } - } - console.log(`[roundhouse] /model (button): switched to ${resolved.provider}/${resolved.model}`); + await applyModelSelection(alias, null, event.thread, postFn); }