fix(config): simplify current model label

This commit is contained in:
Ivan Pereira
2026-03-21 21:02:44 +00:00
parent 041d30651a
commit fcc7613edc
2 changed files with 51 additions and 4 deletions
+13 -3
View File
@@ -29,6 +29,14 @@ function formatCurrentConfig(config: { model?: string; incognito?: boolean }): s
return `Model: ${modelDisplay}\nIncognito: ${incognito}`; return `Model: ${modelDisplay}\nIncognito: ${incognito}`;
} }
function formatModelOption(model: { value: string; label: string }, currentModel?: string): string {
return model.value === currentModel ? `${model.label} [current]` : model.label;
}
function parseSelectedModel(selected: string): string {
return selected.replace(/ \[current\]$/, "");
}
interface ConfigCommandDeps { interface ConfigCommandDeps {
getConfigPath: () => string; getConfigPath: () => string;
loadConfig: () => Promise<PerplexityConfig>; loadConfig: () => Promise<PerplexityConfig>;
@@ -62,13 +70,15 @@ export function registerPerplexityConfigCommand(
return; return;
} }
const modelLabels = KNOWN_MODELS.map((m) => `${m.label} (${m.value})`); const modelOptions = KNOWN_MODELS.map((model) => formatModelOption(model, config.model));
const selected = await ctx.ui.select("Default model", modelLabels); const selected = await ctx.ui.select("Default model", modelOptions);
if (selected === undefined || selected === null) { if (selected === undefined || selected === null) {
ctx.ui.notify("Perplexity config unchanged.", "info"); ctx.ui.notify("Perplexity config unchanged.", "info");
return; return;
} }
const selectedModel = KNOWN_MODELS[modelLabels.indexOf(selected)]?.value ?? selected; const normalizedSelection = parseSelectedModel(selected);
const selectedModel = KNOWN_MODELS.find((model) => model.label === normalizedSelection)?.value
?? normalizedSelection;
const incognito = await ctx.ui.confirm( const incognito = await ctx.ui.confirm(
"Incognito mode", "Incognito mode",
+38 -1
View File
@@ -19,6 +19,43 @@ afterEach(async () => {
}); });
describe("perplexity-config command", () => { describe("perplexity-config command", () => {
test("marks the configured model as current in the select options", async () => {
let handler: ((args: string, ctx: any) => Promise<void>) | undefined;
await saveConfig({ model: "gpt54", incognito: false }, configPath);
registerPerplexityConfigCommand(
{
registerCommand(name: string, command: { handler: (args: string, ctx: any) => Promise<void> }) {
expect(name).toBe("perplexity-config");
handler = command.handler;
},
} as any,
{
getConfigPath: () => configPath,
loadConfig: () => loadConfig(configPath),
saveConfig: (config) => saveConfig(config, configPath),
},
);
expect(handler).toBeDefined();
let options: string[] = [];
await handler!("", {
ui: {
select: async (_label: string, receivedOptions: string[]) => {
options = receivedOptions;
return "GPT-5.4 [current]";
},
confirm: async () => false,
notify: () => undefined,
},
});
expect(options).toContain("GPT-5.4 [current]");
});
test("writes selected config to disk", async () => { test("writes selected config to disk", async () => {
let handler: ((args: string, ctx: any) => Promise<void>) | undefined; let handler: ((args: string, ctx: any) => Promise<void>) | undefined;
@@ -41,7 +78,7 @@ describe("perplexity-config command", () => {
const notifications: Array<{ message: string; level: string }> = []; const notifications: Array<{ message: string; level: string }> = [];
await handler!("", { await handler!("", {
ui: { ui: {
select: async () => "GPT-5.4 (gpt54)", select: async () => "GPT-5.4",
confirm: async () => false, confirm: async () => false,
notify: (message: string, level: string) => notifications.push({ message, level }), notify: (message: string, level: string) => notifications.push({ message, level }),
}, },