From 5b6bb41c3f3dfcf21acdd868a0b393cfbf492bbe Mon Sep 17 00:00:00 2001 From: Ivan Pereira <183991+ivanrvpereira@users.noreply.github.com> Date: Tue, 14 Jul 2026 03:26:27 +0100 Subject: [PATCH] refactor: drop dead model/limit plumbing and unused render helper resolveSearchDefaults no longer accepts a per-call model override and SearchParams no longer carries limit; neither was reachable from the tool schema (limit is applied client-side in formatForLLM). Also fold asPositiveNumber into asPositiveInteger and simplify recency matching. --- src/config.ts | 13 +++---------- src/index.ts | 5 +---- src/render/call.ts | 12 ++---------- src/render/util.ts | 9 ++------- src/search/client.ts | 1 - test/config.test.ts | 8 ++++---- test/e2e-models.test.ts | 1 - test/render.test.ts | 4 +--- 8 files changed, 13 insertions(+), 40 deletions(-) diff --git a/src/config.ts b/src/config.ts index 61dd4f8..51ed8a8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -48,22 +48,15 @@ export async function saveConfig(config: PerplexityConfig, configPath: string = await chmod(configPath, 0o600); } -/** - * Resolve effective values using priority: per-call param > env var > config file > default. - * Returns the model and incognito values to use for a search. - */ +/** Resolve effective search defaults from env vars, config file, and per-call incognito override. */ export function resolveSearchDefaults( - params: { model?: string; incognito?: boolean }, + params: { incognito?: boolean }, config: PerplexityConfig, ): { model: string; incognito: boolean } { const envModel = process.env.PI_PERPLEXITY_MODEL?.trim() || undefined; const envIncognito = process.env.PI_PERPLEXITY_INCOGNITO || undefined; - const model = params.model - ?? envModel - ?? config.model - ?? "pplx_pro_upgraded"; - + const model = envModel ?? config.model ?? "pplx_pro_upgraded"; const incognito = params.incognito ?? (envIncognito !== undefined ? envIncognito !== "false" && envIncognito !== "0" : undefined) ?? config.incognito diff --git a/src/index.ts b/src/index.ts index f77dd46..f02402a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -73,9 +73,7 @@ export default function (pi: ExtensionAPI) { const config = await loadConfig(); const { model, incognito } = resolveSearchDefaults( - { - ...(params.incognito !== undefined ? { incognito: params.incognito } : {}), - }, + params.incognito !== undefined ? { incognito: params.incognito } : {}, config, ); @@ -85,7 +83,6 @@ export default function (pi: ExtensionAPI) { model, incognito, ...(params.recency !== undefined ? { recency: params.recency } : {}), - ...(params.limit !== undefined ? { limit: params.limit } : {}), }, auth, signal, diff --git a/src/render/call.ts b/src/render/call.ts index af33b7f..b4fa20c 100644 --- a/src/render/call.ts +++ b/src/render/call.ts @@ -6,28 +6,20 @@ interface PerplexityCallArgs { query?: unknown; recency?: unknown; limit?: unknown; - model?: unknown; incognito?: unknown; } -const RECENCY_VALUES = new Set(["hour", "day", "week", "month", "year"] as const); +const RECENCY_VALUES: readonly string[] = ["hour", "day", "week", "month", "year"]; export function renderPerplexityCall(args: PerplexityCallArgs, theme: Theme): Text { const query = asString(args?.query)?.trim(); const recencyRaw = asString(args?.recency)?.trim().toLowerCase(); - const recency = recencyRaw && RECENCY_VALUES.has(recencyRaw as (typeof RECENCY_VALUES extends Set ? T : never)) - ? recencyRaw - : undefined; + const recency = recencyRaw && RECENCY_VALUES.includes(recencyRaw) ? recencyRaw : undefined; const limit = asPositiveInteger(args?.limit); - const model = asString(args?.model)?.trim(); const incognito = typeof args?.incognito === "boolean" ? args.incognito : undefined; let text = theme.fg("toolTitle", theme.bold("perplexity_search ")); text += query ? theme.fg("muted", truncate(query, 90)) : theme.fg("warning", "(missing query)"); - if (model) { - text += theme.fg("dim", ` • ${model}`); - } - if (typeof incognito === "boolean") { text += theme.fg("dim", ` • incognito ${incognito ? "on" : "off"}`); } diff --git a/src/render/util.ts b/src/render/util.ts index 7b7d0b0..0dd7ed5 100644 --- a/src/render/util.ts +++ b/src/render/util.ts @@ -13,16 +13,11 @@ export function asNumber(value: unknown): number | undefined { return typeof value === "number" && Number.isFinite(value) ? value : undefined; } -export function asPositiveNumber(value: unknown): number | undefined { +export function asPositiveInteger(value: unknown): number | undefined { if (typeof value !== "number" || !Number.isFinite(value) || value <= 0) { return undefined; } - return value; -} - -export function asPositiveInteger(value: unknown): number | undefined { - const n = asPositiveNumber(value); - return n !== undefined ? Math.floor(n) : undefined; + return Math.floor(value); } export function truncate(text: string, maxLength: number): string { diff --git a/src/search/client.ts b/src/search/client.ts index 6fe40af..29e9dac 100644 --- a/src/search/client.ts +++ b/src/search/client.ts @@ -9,7 +9,6 @@ const PERPLEXITY_ENDPOINT = "https://www.perplexity.ai/rest/sse/perplexity_ask"; export interface SearchParams { query: string; recency?: "hour" | "day" | "week" | "month" | "year"; - limit?: number; model: string; incognito: boolean; } diff --git a/test/config.test.ts b/test/config.test.ts index 74437ea..668b0a7 100644 --- a/test/config.test.ts +++ b/test/config.test.ts @@ -6,7 +6,7 @@ import { join } from "node:path"; let loadConfig: (configPath?: string) => Promise; let saveConfig: (config: import("../src/config.js").PerplexityConfig, configPath?: string) => Promise; let resolveSearchDefaults: ( - params: { model?: string; incognito?: boolean }, + params: { incognito?: boolean }, config: import("../src/config.js").PerplexityConfig, ) => { model: string; incognito: boolean }; @@ -142,16 +142,16 @@ describe("resolveSearchDefaults", () => { } }); - test("per-call params override everything", () => { + test("per-call incognito overrides env/config without exposing model override", () => { const originalModel = process.env.PI_PERPLEXITY_MODEL; try { process.env.PI_PERPLEXITY_MODEL = "experimental"; const result = resolveSearchDefaults( - { model: "claude46sonnetthinking", incognito: false }, + { incognito: false }, { model: "gpt54", incognito: true }, ); - expect(result.model).toBe("claude46sonnetthinking"); + expect(result.model).toBe("experimental"); expect(result.incognito).toBe(false); } finally { if (originalModel === undefined) delete process.env.PI_PERPLEXITY_MODEL; diff --git a/test/e2e-models.test.ts b/test/e2e-models.test.ts index 1dcb698..b2f71ce 100644 --- a/test/e2e-models.test.ts +++ b/test/e2e-models.test.ts @@ -51,7 +51,6 @@ describe("Perplexity model selection e2e", () => { query: "Say exactly OK", model, incognito: true, - limit: 1, }, token, ); diff --git a/test/render.test.ts b/test/render.test.ts index d60dacd..54f59e2 100644 --- a/test/render.test.ts +++ b/test/render.test.ts @@ -9,18 +9,16 @@ const theme = { } as any; describe("renderPerplexityCall", () => { - test("shows the selected model in the tool call row", () => { + test("shows query filters in the tool call row", () => { const rendered = renderPerplexityCall( { query: "latest Node release notes", - model: "claude46sonnetthinking", recency: "week", limit: 5, }, theme, ).render(200).join("\n"); - expect(rendered).toContain("claude46sonnetthinking"); expect(rendered).toContain("week"); expect(rendered).toContain("limit 5"); });