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.
This commit is contained in:
Ivan Pereira
2026-02-23 10:49:23 +00:00
parent 76dbc20064
commit 2c5b558271
3 changed files with 6 additions and 5 deletions
+1 -2
View File
@@ -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);
+2
View File
@@ -0,0 +1,2 @@
export const PERPLEXITY_USER_AGENT = "Perplexity/641 CFNetwork/1568 Darwin/25.2.0";
export const PERPLEXITY_API_VERSION = "2.18";
+3 -3
View File
@@ -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<Uint8Array> {
@@ -214,7 +214,7 @@ function buildRequestBody(params: SearchParams): Record<string, unknown> {
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<string, str
Referer: "https://www.perplexity.ai/",
"User-Agent": PERPLEXITY_USER_AGENT,
"X-App-ApiClient": "default",
"X-App-ApiVersion": "2.18",
"X-App-ApiVersion": PERPLEXITY_API_VERSION,
"X-Perplexity-Request-Reason": "submit",
"X-Request-ID": requestId,
};