fix(config): simplify current model label
This commit is contained in:
+13
-3
@@ -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",
|
||||||
|
|||||||
@@ -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 }),
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user