perplex.js 0.2.1 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/client.js +31 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "perplex.js",
3
- "version": "0.2.1",
3
+ "version": "0.2.4",
4
4
  "description": "Minimal Node.js client for the Perplexity API",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
package/src/client.js CHANGED
@@ -7,11 +7,21 @@ import {
7
7
 
8
8
  function defaultHeaders(cookie) {
9
9
  const headers = {
10
- 'accept': 'text/event-stream, text/plain, */*',
10
+ 'accept': 'text/event-stream',
11
+ 'accept-language': 'fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7',
11
12
  'content-type': 'application/json',
12
13
  'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/142.0.0.0 Safari/537.36',
13
14
  'origin': 'https://www.perplexity.ai',
14
- 'referer': 'https://www.perplexity.ai/'
15
+ 'referer': 'https://www.perplexity.ai/',
16
+ 'priority': 'u=1, i',
17
+ 'sec-ch-ua': '"Chromium";v="142", "Google Chrome";v="142", "Not_A Brand";v="99"',
18
+ 'sec-ch-ua-mobile': '?0',
19
+ 'sec-ch-ua-platform': '"Windows"',
20
+ 'sec-fetch-dest': 'empty',
21
+ 'sec-fetch-mode': 'cors',
22
+ 'sec-fetch-site': 'same-origin',
23
+ 'x-perplexity-request-reason': 'perplexity-query-state-provider',
24
+ // x-request-id ?
15
25
  };
16
26
 
17
27
  if (cookie) headers['cookie'] = typeof cookie === 'string' ? cookie : Object.entries(cookie).map(([k, v]) => `${k}=${v}`).join('; ');
@@ -57,7 +67,13 @@ export default class PerplexityClient {
57
67
  // Build the payload for the request
58
68
  _buildPayload(query, opts = {}) {
59
69
  const {
60
- mode = 'auto', model = null, sources = ['web'], attachments = [], language = 'en-US', follow_up = null, incognito = false
70
+ mode = 'auto',
71
+ model = null,
72
+ sources = ['web'],
73
+ attachments = [],
74
+ language = 'en-US',
75
+ follow_up = null,
76
+ incognito = false
61
77
  } = opts;
62
78
 
63
79
  const attachmentsFinal = attachments.concat(follow_up && follow_up.attachments ? follow_up.attachments : []);
@@ -117,14 +133,26 @@ export default class PerplexityClient {
117
133
  }
118
134
 
119
135
  const params = {
136
+ always_search_override: false,
120
137
  attachments: attachmentsFinal,
138
+ browser_agent_allow_once_from_toggle: false,
139
+ client_coordinates: null,
140
+ dsl_query: query,
141
+ force_enable_browser_agent: false,
121
142
  frontend_context_uuid: cryptoRandomUUID(),
122
143
  frontend_uuid: cryptoRandomUUID(),
123
144
  is_incognito: incognito,
145
+ is_nav_suggestions_disabled: false,
146
+ is_related_query: false,
147
+ is_sponsored: false,
124
148
  language,
125
149
  last_backend_uuid: follow_up ? follow_up.backend_uuid : null,
150
+ local_search_enabled: false,
151
+ mentions: [],
126
152
  mode: mode === 'auto' ? 'concise' : 'copilot',
127
153
  model_preference: modelPref,
154
+ override_no_search: false,
155
+ prompt_source: "user",
128
156
  source: 'default',
129
157
  sources,
130
158
  version: this.version