Replace brittle error text detection with isError flag
renderPerplexityResult was pattern-matching content text prefixes to decide whether to render in error style. This was tightly coupled to exact message strings in index.ts — a wording change would silently break the error styling. Set isError: true in details on every error return path in execute, and check details.isError in the renderer instead.
This commit is contained in:
@@ -9,6 +9,7 @@ interface PerplexityResultDetails {
|
||||
uuid?: unknown;
|
||||
toolCallId?: unknown;
|
||||
error?: unknown;
|
||||
isError?: unknown;
|
||||
}
|
||||
function extractTextContent(result: AgentToolResult<PerplexityResultDetails>): string | undefined {
|
||||
if (!Array.isArray(result?.content)) {
|
||||
@@ -34,14 +35,6 @@ function extractTextContent(result: AgentToolResult<PerplexityResultDetails>): s
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function isErrorText(text: string | undefined): boolean {
|
||||
if (!text) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return text.startsWith("Authentication failed:") || text.startsWith("Perplexity search failed:");
|
||||
}
|
||||
|
||||
export function renderPerplexityResult(
|
||||
result: AgentToolResult<PerplexityResultDetails>,
|
||||
options: ToolRenderResultOptions,
|
||||
@@ -69,7 +62,7 @@ export function renderPerplexityResult(
|
||||
return new Text(theme.fg("error", `Perplexity error: ${error}`), 0, 0);
|
||||
}
|
||||
|
||||
if (isErrorText(contentText)) {
|
||||
if (details.isError === true) {
|
||||
return new Text(theme.fg("error", truncate(contentText ?? "Perplexity request failed", 200)), 0, 0);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user