From a11bb5353969b241022144b6699959ed01a638ed Mon Sep 17 00:00:00 2001 From: Xiaonuo Date: Tue, 21 Apr 2026 10:50:18 +0800 Subject: [PATCH] fix: address review feedback from PR #1 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. switch 后提示重启 gateway 以生效 2. auxiliary tasks 从 config.yaml 动态读取,不再硬编码 3. Telegram 删消息加 3s delay,确保 hermes 先处理 4. api_key_env 已在前一个 commit 修复 Ref: PR #1 review by tuanzi Signed-off-by: Xiaonuo --- src/commands/models.ts | 48 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/src/commands/models.ts b/src/commands/models.ts index c24b99f..6be456a 100644 --- a/src/commands/models.ts +++ b/src/commands/models.ts @@ -36,7 +36,7 @@ interface Config { [key: string]: unknown; } -const AUXILIARY_TASKS = [ +const DEFAULT_AUXILIARY_TASKS = [ "vision", "web_extract", "compression", @@ -47,6 +47,18 @@ const AUXILIARY_TASKS = [ "approval", ]; +function getAuxiliaryTasks(): string[] { + try { + const config = loadConfig(); + const aux = config.auxiliary || {}; + const tasks = Object.keys(aux).filter( + (k) => typeof aux[k] === "object" && aux[k]?.provider !== undefined + ); + if (tasks.length > 0) return tasks; + } catch {} + return DEFAULT_AUXILIARY_TASKS; +} + // ── Helpers ──────────────────────────────────────────────────────────── function loadConfig(): Config { @@ -324,7 +336,7 @@ function switchConfig(opts: SwitchOptions) { } saveConfig(config); - console.log("\nConfig saved. New sessions will use the updated settings."); + console.log("\nConfig saved. Run 'hermes gateway restart' or start a new session to apply."); } async function switchTelegram(opts: SwitchOptions) { @@ -386,16 +398,19 @@ async function switchTelegram(opts: SwitchOptions) { if (result.ok) { console.log(`Sent: ${command}`); console.log(opts.global ? "Persistent change (--global)." : "Current session only."); - // Clean up the command message + // Clean up the command message after a delay so hermes can process it if (result.result?.message_id) { - await fetch(`https://api.telegram.org/bot${token}/deleteMessage`, { - method: "POST", - headers: { "Content-Type": "application/json" }, - body: JSON.stringify({ - chat_id: chatId, - message_id: result.result.message_id, - }), - }).catch(() => {}); + const msgId = result.result.message_id; + setTimeout(async () => { + await fetch(`https://api.telegram.org/bot${token}/deleteMessage`, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ + chat_id: chatId, + message_id: msgId, + }), + }).catch(() => {}); + }, 3000); } } else { console.error(`Telegram API error: ${result.description}`); @@ -476,11 +491,12 @@ export async function models(args: string[]) { i++; } else if (args[i] === "--aux" && i + 1 < args.length) { const task = args[i + 1]; - if (!AUXILIARY_TASKS.includes(task)) { - console.error(`Unknown auxiliary task: ${task}`); - console.error(`Available: ${AUXILIARY_TASKS.join(", ")}`); - process.exit(1); - } + const knownTasks = getAuxiliaryTasks(); + if (!knownTasks.includes(task)) { + console.error(`Unknown auxiliary task: ${task}`); + console.error(`Available: ${knownTasks.join(", ")}`); + process.exit(1); + } auxTasks.push(task); i += 2; } else {