@openclaw/perplexity-plugin 2026.9.1-beta.1 → 2026.9.2

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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BwUa_uAl.js";
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-APW6MQ72.js";
2
2
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
3
  //#region extensions/perplexity/index.ts
4
4
  var perplexity_default = definePluginEntry({
@@ -4,6 +4,7 @@ import { isRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalString } fr
4
4
  //#region extensions/perplexity/src/perplexity-web-search-provider.shared.ts
5
5
  const DEFAULT_PERPLEXITY_BASE_URL = "https://openrouter.ai/api/v1";
6
6
  const PERPLEXITY_DIRECT_BASE_URL = "https://api.perplexity.ai";
7
+ const DEFAULT_PERPLEXITY_MODEL = "perplexity/sonar-pro";
7
8
  const PERPLEXITY_CREDENTIAL_PATH = "plugins.entries.perplexity.config.webSearch.apiKey";
8
9
  const PERPLEXITY_ONBOARDING_SCOPES = ["text-inference"];
9
10
  const PERPLEXITY_KEY_PREFIXES = ["pplx-"];
@@ -32,12 +33,12 @@ function createPerplexityWebSearchProviderBase() {
32
33
  };
33
34
  }
34
35
  function resolvePerplexityWebSearchRuntimeMetadata(ctx) {
35
- return { perplexityTransport: resolvePerplexityRuntimeTransport({
36
- searchConfig: mergeScopedSearchConfig(ctx.searchConfig, "perplexity", resolveProviderWebSearchPluginConfig(ctx.config, "perplexity")),
37
- resolvedKey: ctx.resolvedCredential?.value,
38
- keySource: ctx.resolvedCredential?.source ?? "missing",
39
- fallbackEnvVar: ctx.resolvedCredential?.fallbackEnvVar
40
- }) };
36
+ const credential = ctx.resolvedCredential;
37
+ const source = credential?.source === "env" ? credential.fallbackEnvVar === "PERPLEXITY_API_KEY" ? "perplexity_env" : "openrouter_env" : (credential?.source === "config" || credential?.source === "secretRef") && credential.value ? "config" : "none";
38
+ return { perplexityTransport: resolvePerplexityRuntime(resolvePerplexityConfig(mergeScopedSearchConfig(ctx.searchConfig, "perplexity", resolveProviderWebSearchPluginConfig(ctx.config, "perplexity"))), {
39
+ apiKey: credential?.value,
40
+ source
41
+ }).transport };
41
42
  }
42
43
  function inferPerplexityBaseUrlFromApiKey(apiKey) {
43
44
  if (!apiKey) return;
@@ -52,25 +53,26 @@ function isDirectPerplexityBaseUrl(baseUrl) {
52
53
  return false;
53
54
  }
54
55
  }
55
- function resolvePerplexityRuntimeTransport(params) {
56
- const perplexity = params.searchConfig?.perplexity;
57
- const scoped = perplexity && typeof perplexity === "object" && !Array.isArray(perplexity) ? perplexity : void 0;
58
- const configuredBaseUrl = normalizeOptionalString(scoped?.baseUrl) ?? "";
59
- const configuredModel = normalizeOptionalString(scoped?.model) ?? "";
60
- const baseUrl = (() => {
61
- if (configuredBaseUrl) return configuredBaseUrl;
62
- if (params.keySource === "env") {
63
- if (params.fallbackEnvVar === "PERPLEXITY_API_KEY") return PERPLEXITY_DIRECT_BASE_URL;
64
- if (params.fallbackEnvVar === "OPENROUTER_API_KEY") return DEFAULT_PERPLEXITY_BASE_URL;
65
- }
66
- if ((params.keySource === "config" || params.keySource === "secretRef") && params.resolvedKey) return inferPerplexityBaseUrlFromApiKey(params.resolvedKey) === "openrouter" ? DEFAULT_PERPLEXITY_BASE_URL : PERPLEXITY_DIRECT_BASE_URL;
67
- return DEFAULT_PERPLEXITY_BASE_URL;
68
- })();
69
- return configuredBaseUrl || configuredModel || !isDirectPerplexityBaseUrl(baseUrl) ? "chat_completions" : "search_api";
56
+ function resolvePerplexityConfig(searchConfig) {
57
+ const perplexity = searchConfig?.perplexity;
58
+ return isRecord(perplexity) ? perplexity : {};
59
+ }
60
+ function hasPerplexityLegacyOverride(perplexity) {
61
+ return Boolean(normalizeOptionalString(perplexity?.baseUrl) || normalizeOptionalString(perplexity?.model));
62
+ }
63
+ function resolvePerplexityRuntime(perplexity, auth) {
64
+ const baseUrl = normalizeOptionalString(perplexity?.baseUrl) || (auth.source === "perplexity_env" || auth.source === "config" && inferPerplexityBaseUrlFromApiKey(auth.apiKey) !== "openrouter" ? PERPLEXITY_DIRECT_BASE_URL : DEFAULT_PERPLEXITY_BASE_URL);
65
+ return {
66
+ apiKey: auth.apiKey,
67
+ source: auth.source,
68
+ baseUrl,
69
+ model: normalizeOptionalString(perplexity?.model) || DEFAULT_PERPLEXITY_MODEL,
70
+ transport: hasPerplexityLegacyOverride(perplexity) || !isDirectPerplexityBaseUrl(baseUrl) ? "chat_completions" : "search_api"
71
+ };
70
72
  }
71
73
  //#endregion
72
74
  //#region extensions/perplexity/src/perplexity-web-search-provider.ts
73
- const loadPerplexityWebSearchRuntime = createLazyRuntimeModule(() => import("./perplexity-web-search-provider.runtime-C8Z5RiPA.js"));
75
+ const loadPerplexityWebSearchRuntime = createLazyRuntimeModule(() => import("./perplexity-web-search-provider.runtime-CYQXm2j8.js"));
74
76
  function createPerplexityParameters(transport) {
75
77
  const properties = {
76
78
  query: {
@@ -128,12 +130,8 @@ function createPerplexityParameters(transport) {
128
130
  required: ["query"]
129
131
  };
130
132
  }
131
- function hasPerplexityLegacyOverride(searchConfig) {
132
- const perplexity = isRecord(searchConfig?.perplexity) ? searchConfig.perplexity : void 0;
133
- return typeof perplexity?.baseUrl === "string" && perplexity.baseUrl.trim().length > 0 || typeof perplexity?.model === "string" && perplexity.model.trim().length > 0;
134
- }
135
133
  function createPerplexityToolDefinition(searchConfig, runtimeTransport) {
136
- const schemaTransport = runtimeTransport ?? (hasPerplexityLegacyOverride(searchConfig) ? "chat_completions" : void 0);
134
+ const schemaTransport = runtimeTransport ?? (hasPerplexityLegacyOverride(resolvePerplexityConfig(searchConfig)) ? "chat_completions" : void 0);
137
135
  return {
138
136
  description: schemaTransport === "chat_completions" ? "Search the web using Perplexity Sonar via Perplexity/OpenRouter chat completions. Returns AI-synthesized answers with citations from web-grounded search." : "Search the web using Perplexity. Runtime routing decides between native Search API and Sonar chat-completions compatibility. Structured filters are available on the native Search API path.",
139
137
  parameters: createPerplexityParameters(schemaTransport),
@@ -152,4 +150,4 @@ function createPerplexityWebSearchProvider() {
152
150
  };
153
151
  }
154
152
  //#endregion
155
- export { isDirectPerplexityBaseUrl as a, inferPerplexityBaseUrlFromApiKey as i, DEFAULT_PERPLEXITY_BASE_URL as n, PERPLEXITY_DIRECT_BASE_URL as r, createPerplexityWebSearchProvider as t };
153
+ export { resolvePerplexityRuntime as i, isDirectPerplexityBaseUrl as n, resolvePerplexityConfig as r, createPerplexityWebSearchProvider as t };
@@ -1,14 +1,9 @@
1
- import { a as isDirectPerplexityBaseUrl, i as inferPerplexityBaseUrlFromApiKey, n as DEFAULT_PERPLEXITY_BASE_URL, r as PERPLEXITY_DIRECT_BASE_URL } from "./perplexity-web-search-provider-BwUa_uAl.js";
1
+ import { i as resolvePerplexityRuntime, n as isDirectPerplexityBaseUrl, r as resolvePerplexityConfig } from "./perplexity-web-search-provider-APW6MQ72.js";
2
2
  import { normalizeOptionalString, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
4
4
  import { DEFAULT_SEARCH_COUNT, MAX_SEARCH_COUNT, buildSearchCacheKey, isoToPerplexityDate, normalizeFreshness, parseWebSearchTimeFilters, readCachedSearchPayload, readConfiguredSecretString, readPositiveIntegerParam, readProviderEnvValue, readStringArrayParam, readStringParam, resolveSearchCacheTtlMs, resolveSearchCount, resolveSearchTimeoutSeconds, resolveSiteName, throwWebSearchApiError, withTrustedWebSearchEndpoint, wrapWebContent, writeCachedSearchPayload } from "openclaw/plugin-sdk/provider-web-search";
5
5
  //#region extensions/perplexity/src/perplexity-web-search-provider.runtime.ts
6
6
  const PERPLEXITY_SEARCH_ENDPOINT = "https://api.perplexity.ai/search";
7
- const DEFAULT_PERPLEXITY_MODEL = "perplexity/sonar-pro";
8
- function resolvePerplexityConfig(searchConfig) {
9
- const perplexity = searchConfig?.perplexity;
10
- return perplexity && typeof perplexity === "object" && !Array.isArray(perplexity) ? perplexity : {};
11
- }
12
7
  function resolvePerplexityApiKey(perplexity) {
13
8
  const fromConfig = readConfiguredSecretString(perplexity?.apiKey, "plugins.entries.perplexity.config.webSearch.apiKey");
14
9
  if (fromConfig) return {
@@ -30,17 +25,6 @@ function resolvePerplexityApiKey(perplexity) {
30
25
  source: "none"
31
26
  };
32
27
  }
33
- function resolvePerplexityBaseUrl(perplexity, authSource = "none", configuredKey) {
34
- const fromConfig = normalizeOptionalString(perplexity?.baseUrl) ?? "";
35
- if (fromConfig) return fromConfig;
36
- if (authSource === "perplexity_env") return PERPLEXITY_DIRECT_BASE_URL;
37
- if (authSource === "openrouter_env") return DEFAULT_PERPLEXITY_BASE_URL;
38
- if (authSource === "config") return inferPerplexityBaseUrlFromApiKey(configuredKey) === "openrouter" ? DEFAULT_PERPLEXITY_BASE_URL : PERPLEXITY_DIRECT_BASE_URL;
39
- return DEFAULT_PERPLEXITY_BASE_URL;
40
- }
41
- function resolvePerplexityModel(perplexity) {
42
- return (normalizeOptionalString(perplexity?.model) ?? "") || DEFAULT_PERPLEXITY_MODEL;
43
- }
44
28
  function resolvePerplexityRequestModel(baseUrl, model) {
45
29
  if (!isDirectPerplexityBaseUrl(baseUrl)) return model;
46
30
  return model.startsWith("perplexity/") ? model.slice(11) : model;
@@ -54,25 +38,14 @@ function buildPerplexityRequestHeaders(apiKey, acceptJson = false) {
54
38
  "X-Title": "OpenClaw Web Search"
55
39
  };
56
40
  }
57
- function resolvePerplexityTransport(perplexity) {
58
- const auth = resolvePerplexityApiKey(perplexity);
59
- const baseUrl = resolvePerplexityBaseUrl(perplexity, auth.source, auth.apiKey);
60
- const model = resolvePerplexityModel(perplexity);
61
- const hasLegacyOverride = Boolean(normalizeOptionalString(perplexity?.baseUrl) || normalizeOptionalString(perplexity?.model));
62
- return {
63
- ...auth,
64
- baseUrl,
65
- model,
66
- transport: hasLegacyOverride || !isDirectPerplexityBaseUrl(baseUrl) ? "chat_completions" : "search_api"
67
- };
68
- }
69
41
  function extractPerplexityCitations(data) {
70
42
  const topLevel = (data.citations ?? []).filter((url) => Boolean(normalizeOptionalString(url)));
71
43
  if (topLevel.length > 0) return uniqueStrings(topLevel);
72
44
  const citations = [];
73
45
  for (const choice of data.choices ?? []) for (const annotation of choice.message?.annotations ?? []) {
74
46
  if (annotation.type !== "url_citation") continue;
75
- const normalizedUrl = normalizeOptionalString(typeof annotation.url_citation?.url === "string" ? annotation.url_citation.url : typeof annotation.url === "string" ? annotation.url : void 0);
47
+ const url = typeof annotation.url_citation?.url === "string" ? annotation.url_citation.url : typeof annotation.url === "string" ? annotation.url : void 0;
48
+ const normalizedUrl = normalizeOptionalString(url);
76
49
  if (normalizedUrl) citations.push(normalizedUrl);
77
50
  }
78
51
  return uniqueStrings(citations);
@@ -90,17 +63,21 @@ async function runPerplexitySearchApi(params) {
90
63
  if (params.searchBeforeDate) body.search_before_date_filter = params.searchBeforeDate;
91
64
  if (params.maxTokens !== void 0) body.max_tokens = params.maxTokens;
92
65
  if (params.maxTokensPerPage !== void 0) body.max_tokens_per_page = params.maxTokensPerPage;
66
+ const headers = buildPerplexityRequestHeaders(params.apiKey, true);
93
67
  return withTrustedWebSearchEndpoint({
94
68
  url: PERPLEXITY_SEARCH_ENDPOINT,
95
69
  timeoutSeconds: params.timeoutSeconds,
96
70
  signal: params.signal,
97
71
  init: {
98
72
  method: "POST",
99
- headers: buildPerplexityRequestHeaders(params.apiKey, true),
73
+ headers,
100
74
  body: JSON.stringify(body)
101
75
  }
102
76
  }, async (res) => {
103
- if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search");
77
+ if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search", {
78
+ headers,
79
+ signal: params.signal
80
+ });
104
81
  return ((await readProviderJsonResponse(res, "Perplexity Search")).results ?? []).map((entry) => ({
105
82
  title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
106
83
  url: entry.url ?? "",
@@ -120,17 +97,21 @@ async function runPerplexitySearch(params) {
120
97
  }]
121
98
  };
122
99
  if (params.freshness) body.search_recency_filter = params.freshness;
100
+ const headers = buildPerplexityRequestHeaders(params.apiKey);
123
101
  return withTrustedWebSearchEndpoint({
124
102
  url: endpoint,
125
103
  timeoutSeconds: params.timeoutSeconds,
126
104
  signal: params.signal,
127
105
  init: {
128
106
  method: "POST",
129
- headers: buildPerplexityRequestHeaders(params.apiKey),
107
+ headers,
130
108
  body: JSON.stringify(body)
131
109
  }
132
110
  }, async (res) => {
133
- if (!res.ok) return await throwWebSearchApiError(res, "Perplexity");
111
+ if (!res.ok) return await throwWebSearchApiError(res, "Perplexity", {
112
+ headers,
113
+ signal: params.signal
114
+ });
134
115
  const data = await readProviderJsonResponse(res, "Perplexity");
135
116
  const content = data.choices?.[0]?.message?.content;
136
117
  if (typeof content !== "string" || !content.trim()) throw new Error("Perplexity search returned no final answer. Retry the query or choose another search provider.");
@@ -141,7 +122,8 @@ async function runPerplexitySearch(params) {
141
122
  });
142
123
  }
143
124
  async function executePerplexitySearch(args, searchConfig, signal) {
144
- const runtime = resolvePerplexityTransport(resolvePerplexityConfig(searchConfig));
125
+ const perplexityConfig = resolvePerplexityConfig(searchConfig);
126
+ const runtime = resolvePerplexityRuntime(perplexityConfig, resolvePerplexityApiKey(perplexityConfig));
145
127
  if (!runtime.apiKey) return {
146
128
  error: "missing_perplexity_api_key",
147
129
  message: "web_search (perplexity) needs an API key. Set PERPLEXITY_API_KEY or OPENROUTER_API_KEY in the Gateway environment, or configure plugins.entries.perplexity.config.webSearch.apiKey. If you do not want to configure a search API key, use web_fetch for a specific URL or the browser tool for interactive pages.",
@@ -256,7 +238,8 @@ async function executePerplexitySearch(args, searchConfig, signal) {
256
238
  maxTokens,
257
239
  maxTokensPerPage
258
240
  ]);
259
- const cached = readCachedSearchPayload(cacheKey);
241
+ const cacheTtlMs = resolveSearchCacheTtlMs(searchConfig);
242
+ const cached = readCachedSearchPayload(cacheKey, cacheTtlMs);
260
243
  if (cached) return cached;
261
244
  const start = Date.now();
262
245
  const timeoutSeconds = resolveSearchTimeoutSeconds(searchConfig);
@@ -318,14 +301,10 @@ async function executePerplexitySearch(args, searchConfig, signal) {
318
301
  payload.tookMs = Date.now() - start;
319
302
  } else payload.tookMs = Date.now() - start;
320
303
  signal?.throwIfAborted();
321
- writeCachedSearchPayload(cacheKey, payload, resolveSearchCacheTtlMs(searchConfig));
304
+ writeCachedSearchPayload(cacheKey, payload, cacheTtlMs);
322
305
  return payload;
323
306
  }
324
307
  const testing = {
325
- inferPerplexityBaseUrlFromApiKey,
326
- resolvePerplexityBaseUrl,
327
- resolvePerplexityModel,
328
- resolvePerplexityTransport,
329
308
  resolvePerplexityRequestModel,
330
309
  resolvePerplexityApiKey
331
310
  };
@@ -1,3 +1,3 @@
1
- import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BwUa_uAl.js";
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-APW6MQ72.js";
2
2
  import "./web-search-provider.js";
3
3
  export { createPerplexityWebSearchProvider };
@@ -1,2 +1,2 @@
1
- import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BwUa_uAl.js";
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-APW6MQ72.js";
2
2
  export { createPerplexityWebSearchProvider };
@@ -1,6 +1,5 @@
1
1
  {
2
2
  "id": "perplexity",
3
- "icon": "https://cdn.simpleicons.org/perplexity",
4
3
  "activation": {
5
4
  "onStartup": false
6
5
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/perplexity-plugin",
3
- "version": "2026.9.1-beta.1",
3
+ "version": "2026.9.2",
4
4
  "description": "OpenClaw Perplexity plugin.",
5
5
  "repository": {
6
6
  "type": "git",
@@ -18,10 +18,10 @@
18
18
  "minHostVersion": ">=2026.6.8"
19
19
  },
20
20
  "compat": {
21
- "pluginApi": ">=2026.9.1-beta.1"
21
+ "pluginApi": ">=2026.9.2"
22
22
  },
23
23
  "build": {
24
- "openclawVersion": "2026.9.1-beta.1",
24
+ "openclawVersion": "2026.9.2",
25
25
  "bundledDist": false
26
26
  },
27
27
  "release": {
@@ -38,7 +38,7 @@
38
38
  "README.md"
39
39
  ],
40
40
  "peerDependencies": {
41
- "openclaw": ">=2026.9.1-beta.1"
41
+ "openclaw": ">=2026.9.2"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "openclaw": {