diff --git a/src/config.ts b/src/config.ts index 4fdf99e..61dd4f8 100644 --- a/src/config.ts +++ b/src/config.ts @@ -56,7 +56,7 @@ export function resolveSearchDefaults( params: { model?: string; incognito?: boolean }, config: PerplexityConfig, ): { model: string; incognito: boolean } { - const envModel = process.env.PI_PERPLEXITY_MODEL || undefined; + const envModel = process.env.PI_PERPLEXITY_MODEL?.trim() || undefined; const envIncognito = process.env.PI_PERPLEXITY_INCOGNITO || undefined; const model = params.model diff --git a/src/index.ts b/src/index.ts index d7182dc..b53d916 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,6 +12,7 @@ import { formatForLLM } from "./search/format.js"; import { searchPerplexity } from "./search/client.js"; import { renderPerplexityCall } from "./render/call.js"; import { renderPerplexityResult } from "./render/result.js"; +import { errorMessage } from "./render/util.js"; import { AuthError, SearchError } from "./search/types.js"; export default function (pi: ExtensionAPI) { @@ -115,17 +116,18 @@ export default function (pi: ExtensionAPI) { if (error instanceof AuthError) { return { content: [{ type: "text", text: `Authentication failed: ${error.message}` }], - details: { sourceCount, queryMs }, + details: { sourceCount, queryMs, isError: true }, }; } if (error instanceof SearchError) { if (error.code === "AUTH") { + // Clear cached token on auth rejection so next call triggers re-login. await clearToken().catch(() => undefined); } return { content: [{ type: "text", text: `Perplexity search failed: ${error.message}` }], - details: { sourceCount, queryMs }, + details: { sourceCount, queryMs, isError: true }, }; } @@ -133,10 +135,10 @@ export default function (pi: ExtensionAPI) { content: [ { type: "text", - text: `Perplexity search failed: ${(error as Error).message || "Unknown error"}`, + text: `Perplexity search failed: ${errorMessage(error)}`, }, ], - details: { sourceCount, queryMs }, + details: { sourceCount, queryMs, isError: true }, }; } },