Add asPositiveInteger helper, use for limit display

This commit is contained in:
Ivan Pereira
2026-02-23 10:49:46 +00:00
parent 56ef5533a3
commit 431a814e9a
2 changed files with 8 additions and 3 deletions
+3 -3
View File
@@ -1,6 +1,6 @@
import type { Theme } from "@mariozechner/pi-coding-agent";
import { Text } from "@mariozechner/pi-tui";
import { asString, asPositiveNumber, truncate } from "./util.js";
import { asString, asPositiveInteger, truncate } from "./util.js";
interface PerplexityCallArgs {
query?: unknown;
@@ -15,7 +15,7 @@ export function renderPerplexityCall(args: PerplexityCallArgs, theme: Theme): Te
const recency = recencyRaw && RECENCY_VALUES.has(recencyRaw as (typeof RECENCY_VALUES extends Set<infer T> ? T : never))
? recencyRaw
: undefined;
const limit = asPositiveNumber(args?.limit);
const limit = asPositiveInteger(args?.limit);
let text = theme.fg("toolTitle", theme.bold("perplexity_search "));
text += query ? theme.fg("muted", truncate(query, 90)) : theme.fg("warning", "(missing query)");
@@ -25,7 +25,7 @@ export function renderPerplexityCall(args: PerplexityCallArgs, theme: Theme): Te
}
if (typeof limit === "number") {
text += theme.fg("dim", ` • limit ${Math.round(limit)}`);
text += theme.fg("dim", ` • limit ${limit}`);
}
return new Text(text, 0, 0);
+5
View File
@@ -20,6 +20,11 @@ export function asPositiveNumber(value: unknown): number | undefined {
return value;
}
export function asPositiveInteger(value: unknown): number | undefined {
const n = asPositiveNumber(value);
return n !== undefined ? Math.floor(n) : undefined;
}
export function truncate(text: string, maxLength: number): string {
if (text.length <= maxLength) {
return text;