From 26a831e2c3dbe79244737e71fe4e7da69760082d Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Sun, 15 Feb 2026 13:46:13 +0000 Subject: [PATCH] refactor(commands): dedupe auth choice agent model notes --- src/commands/auth-choice.apply-helpers.ts | 15 +++++++++++++++ src/commands/auth-choice.apply.huggingface.ts | 11 ++--------- src/commands/auth-choice.apply.xai.ts | 11 ++--------- 3 files changed, 19 insertions(+), 18 deletions(-) create mode 100644 src/commands/auth-choice.apply-helpers.ts diff --git a/src/commands/auth-choice.apply-helpers.ts b/src/commands/auth-choice.apply-helpers.ts new file mode 100644 index 000000000..8a10d830e --- /dev/null +++ b/src/commands/auth-choice.apply-helpers.ts @@ -0,0 +1,15 @@ +import type { ApplyAuthChoiceParams } from "./auth-choice.apply.js"; + +export function createAuthChoiceAgentModelNoter( + params: ApplyAuthChoiceParams, +): (model: string) => Promise { + return async (model: string) => { + if (!params.agentId) { + return; + } + await params.prompter.note( + `Default model set to ${model} for agent "${params.agentId}".`, + "Model configured", + ); + }; +} diff --git a/src/commands/auth-choice.apply.huggingface.ts b/src/commands/auth-choice.apply.huggingface.ts index 4de46d35b..9358505c3 100644 --- a/src/commands/auth-choice.apply.huggingface.ts +++ b/src/commands/auth-choice.apply.huggingface.ts @@ -9,6 +9,7 @@ import { normalizeApiKeyInput, validateApiKeyInput, } from "./auth-choice.api-key.js"; +import { createAuthChoiceAgentModelNoter } from "./auth-choice.apply-helpers.js"; import { applyDefaultModelChoice } from "./auth-choice.default-model.js"; import { ensureModelAllowlistEntry } from "./model-allowlist.js"; import { @@ -27,15 +28,7 @@ export async function applyAuthChoiceHuggingface( let nextConfig = params.config; let agentModelOverride: string | undefined; - const noteAgentModel = async (model: string) => { - if (!params.agentId) { - return; - } - await params.prompter.note( - `Default model set to ${model} for agent "${params.agentId}".`, - "Model configured", - ); - }; + const noteAgentModel = createAuthChoiceAgentModelNoter(params); let hasCredential = false; let hfKey = ""; diff --git a/src/commands/auth-choice.apply.xai.ts b/src/commands/auth-choice.apply.xai.ts index 0a3192080..df287a732 100644 --- a/src/commands/auth-choice.apply.xai.ts +++ b/src/commands/auth-choice.apply.xai.ts @@ -5,6 +5,7 @@ import { normalizeApiKeyInput, validateApiKeyInput, } from "./auth-choice.api-key.js"; +import { createAuthChoiceAgentModelNoter } from "./auth-choice.apply-helpers.js"; import { applyDefaultModelChoice } from "./auth-choice.default-model.js"; import { applyAuthProfileConfig, @@ -23,15 +24,7 @@ export async function applyAuthChoiceXAI( let nextConfig = params.config; let agentModelOverride: string | undefined; - const noteAgentModel = async (model: string) => { - if (!params.agentId) { - return; - } - await params.prompter.note( - `Default model set to ${model} for agent "${params.agentId}".`, - "Model configured", - ); - }; + const noteAgentModel = createAuthChoiceAgentModelNoter(params); let hasCredential = false; const optsKey = params.opts?.xaiApiKey?.trim();