genson1808/dsh-web-search-perplexity-account

dsh-web-search-perplexity-account

Perplexity consumer-account (Pro) web search provider for DeepSeek Harness — login with browser SSO / email OTP, no API key billed. Ported from oh-my-pi.

Uncategorizeddeepseek-harnessperplexityweb-search

dsh-web-search-perplexity

Perplexity search provider for DeepSeek Harness with oh-my-pi's full auth chain: consumer account session (Pro included), billed Sonar API key, OpenRouter, or anonymous — each tried in order with fallback. Includes a complete login flow: browser SSO, email OTP (with TOTP challenge support), macOS desktop-app session borrowing, and API-key paste. Ported from oh-my-pi's perplexity.ts adapter.

This package unifies all Perplexity search modes in one provider: consumer account sessions (Pro included), direct Sonar API keys, OpenRouter routing, and anonymous fallback. Pin it in your profile with searchProvider: perplexity-account.

How it works

  • Registers the perplexity-account WebSearchProvider into ctx.web.
  • Auth chain per search (oh-my-pi's order; each failure falls through to the next): config cookies → session token (config / $PERPLEXITY_SESSION_TOKEN / stored record) → Perplexity API key (config / $PERPLEXITY_API_KEY / stored record) → OpenRouter key ($OPENROUTER_API_KEY, routes perplexity/sonar-pro) → anonymous.
  • Account mode talks to https://www.perplexity.ai/rest/sse/perplexity_ask over SSE; the session JWT rides as the __Secure-next-auth.session-token cookie — that is what unlocks the account's Pro model selection (a bearer header would silently degrade to anonymous turbo).
  • API-key mode POSTs chat/completions with search_mode: "web", num_search_results, max_tokens, temperature, web_search_options, and native domain/date/language filters.
  • Registers two login flows with ctx.authorization (rendered by every harness UI):
    • Perplexity (account session) — browser SSO opens a temp-profile Chrome and captures the session cookie over the DevTools protocol; email OTP walks CSRF → code → optional TOTP challenge; native borrowing reads a legacy ai.perplexity.mac install.
    • Perplexity (API key) — a masked paste prompt.
  • Records live in the credential store under primary scope web-search-perplexity/session and web-search-perplexity/api-key (with automatic reading fallback to legacy web-search-perplexity-account/* records); the provider re-reads them per search, so a login takes effect without restart.

Install

Clone and build the plugin:

git clone https://github.com/genson1808/dsh-web-search-perplexity
cd dsh-web-search-perplexity
npm install && npm run build

Add it to your DeepSeek Harness profile:

dsh plugin add /path/to/dsh-web-search-perplexity

The package declares dsh.bundle, so dsh plugin add appends it to dsh.profile.bundles and its shipped cordis.patch.yml inserts the loader entry automatically.

Configuration

Mounting is automatic; selecting it as the active provider and tuning it happen in the profile's cordis.patch.yml:

- id: web
  config:
    searchProvider: perplexity-account
- id: <entry-id>   # shown in Settings → Plugins → Plugin list
  config:
    sessionToken: !!js process.env.PERPLEXITY_SESSION_TOKEN  # or leave unset and sign in via the authorization UI
    model: experimental          # consumer model_preference; default 'experimental'
    searchRecency: week          # optional: hour|day|week|month|year
    timeoutMs: 60000             # optional
FieldDefaultMeaning
cookies$PERPLEXITY_COOKIESRaw Cookie header from a logged-in perplexity.ai session (highest precedence)
sessionToken$PERPLEXITY_SESSION_TOKENValue of __Secure-next-auth.session-token; falls back to the credential record
apiKey$PERPLEXITY_API_KEYBilled Sonar API key; falls back to the api-key credential record
openRouterKey$OPENROUTER_API_KEYOpenRouter key — routes perplexity/<apiModel>
modelexperimentalConsumer model_preference (Sonar on paid plans)
apiModelsonar-proAPI-mode model
apiMaxTokens8192API-mode max_tokens
apiTemperature0.2API-mode sampling temperature
numSearchResults20API-mode num_search_results
useResponsesApi$PERPLEXITY_RESPONSES=1API-mode transport: Responses API SSE instead of chat/completions
searchRecency(unset)search_recency_filter: hour, day, week, month, year
timeoutMs60000Hard per-request timeout

To sign in interactively, run the harness's login/authorization UI and pick Perplexity (account session) — browser SSO is the default method — or Perplexity (API key) to store a Sonar API key. In the web interface, the plugin appears as Enabled under Settings → Plugins → Plugin list → Global plugins; no card is rendered under Plugin configuration (which requires a client-side browser bundle), so tuning parameters are configured exclusively via the profile patch (cordis.patch.yml) or environment variables.

Query directives

site: / -site:, after:, before:, and lang: directives map onto Perplexity's native search_domain_filter, date, and language filters (so the engine is not double-constrained); other operators pass through as text signal. Recency is dropped when explicit after:/before: bounds are present — the upstream API rejects the combination.

Caveats

  • The consumer ask endpoint is unofficial — Perplexity can change or block it at any time. The API-key path is the supported one.
  • Perplexity exposes no result-count control on the ask endpoint; maxResults is sliced post-hoc (the ctx.web seam enforces the bound regardless).
  • Anonymous mode always works but always gets the free turbo model.
  • useResponsesApi mirrors oh-my-pi's PI_PERPLEXITY_RESPONSES=1 opt-in; it is experimental upstream and off by default.
  • Set PERPLEXITY_AUTH_NO_BORROW=1 to skip desktop-app session borrowing (oh-my-pi's PI_AUTH_NO_BORROW).

Development

npm run typecheck   # tsc --noEmit
npm test            # unit tests (mocked fetch)
npm run build       # tsdown → lib/ + tsc declarations

Credits

  • Login and ask-endpoint logic ported from oh-my-pi (packages/ai/src/registry/oauth/perplexity.ts, packages/coding-agent/src/web/search/providers/perplexity.ts), MIT licensed.
  • Plugin architecture, seam types, and config layout follow deepseek-ai/deepseek-harness, MIT licensed.

License

MIT