From 2c5b5582710304073ecf6860049e23d8c5d08595 Mon Sep 17 00:00:00 2001 From: Ivan Pereira <183991+ivanrvpereira@users.noreply.github.com> Date: Mon, 23 Feb 2026 10:49:23 +0000 Subject: [PATCH] Extract shared Perplexity API constants to src/constants.ts PERPLEXITY_USER_AGENT and PERPLEXITY_API_VERSION were duplicated in auth/login.ts and search/client.ts. Centralise both so updates only need to happen in one place. --- src/auth/login.ts | 3 +-- src/constants.ts | 2 ++ src/search/client.ts | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 src/constants.ts diff --git a/src/auth/login.ts b/src/auth/login.ts index 163e967..3cbce3a 100644 --- a/src/auth/login.ts +++ b/src/auth/login.ts @@ -4,14 +4,13 @@ import { promisify } from "node:util"; import { AuthError } from "../search/types.js"; import { errorMessage } from "../render/util.js"; import { loadToken, saveToken } from "./storage.js"; +import { PERPLEXITY_USER_AGENT, PERPLEXITY_API_VERSION } from "../constants.js"; const DESKTOP_AUTH_HELP = "Install the Perplexity desktop app and sign in, or set PI_AUTH_NO_BORROW=1 to skip desktop token borrowing."; const OTP_AUTH_HELP = "Provide credentials via PI_PERPLEXITY_EMAIL and PI_PERPLEXITY_OTP, or run interactively to enter email and OTP."; const AUTH_BASE_URL = "https://www.perplexity.ai/api/auth"; -const PERPLEXITY_USER_AGENT = "Perplexity/641 CFNetwork/1568 Darwin/25.2.0"; -const PERPLEXITY_API_VERSION = "2.18"; const execFileAsync = promisify(execFile); diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..13e517d --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,2 @@ +export const PERPLEXITY_USER_AGENT = "Perplexity/641 CFNetwork/1568 Darwin/25.2.0"; +export const PERPLEXITY_API_VERSION = "2.18"; diff --git a/src/search/client.ts b/src/search/client.ts index c0efcb3..8f745d0 100644 --- a/src/search/client.ts +++ b/src/search/client.ts @@ -2,9 +2,9 @@ import { mergeEvent, readSseEvents } from "./stream.js"; import type { SearchResult, StreamEvent, WebResult } from "./types.js"; import { SearchError } from "./types.js"; import { errorMessage } from "../render/util.js"; +import { PERPLEXITY_USER_AGENT, PERPLEXITY_API_VERSION } from "../constants.js"; const PERPLEXITY_ENDPOINT = "https://www.perplexity.ai/rest/sse/perplexity_ask"; -const PERPLEXITY_USER_AGENT = "Perplexity/641 CFNetwork/1568 Darwin/25.2.0"; function streamFromText(text: string): ReadableStream { @@ -214,7 +214,7 @@ function buildRequestBody(params: SearchParams): Record { attachments: [], frontend_uuid: crypto.randomUUID(), frontend_context_uuid: crypto.randomUUID(), - version: "2.18", + version: PERPLEXITY_API_VERSION, language: "en-US", timezone, search_recency_filter: params.recency ?? null, @@ -234,7 +234,7 @@ function buildRequestHeaders(jwt: string, requestId: string): Record