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.
This commit is contained in:
Ivan Pereira
2026-07-14 03:26:27 +01:00
parent 39d977c403
commit 5b6bb41c3f
8 changed files with 13 additions and 40 deletions
+3 -10
View File
@@ -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
+1 -4
View File
@@ -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,
+2 -10
View File
@@ -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<infer T> ? 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"}`);
}
+2 -7
View File
@@ -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 {
-1
View File
@@ -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;
}