@openclaw/perplexity-plugin 2026.8.1-beta.3 → 2026.8.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-CSYSs8kt.js";
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BCKqky14.js";
2
2
  import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
3
  //#region extensions/perplexity/index.ts
4
4
  var perplexity_default = definePluginEntry({
@@ -0,0 +1,155 @@
1
+ import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
2
+ import { createWebSearchProviderContractFields, mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig } from "openclaw/plugin-sdk/provider-web-search-config-contract";
3
+ import { isRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
4
+ //#region extensions/perplexity/src/perplexity-web-search-provider.shared.ts
5
+ const DEFAULT_PERPLEXITY_BASE_URL = "https://openrouter.ai/api/v1";
6
+ const PERPLEXITY_DIRECT_BASE_URL = "https://api.perplexity.ai";
7
+ const PERPLEXITY_CREDENTIAL_PATH = "plugins.entries.perplexity.config.webSearch.apiKey";
8
+ const PERPLEXITY_ONBOARDING_SCOPES = ["text-inference"];
9
+ const PERPLEXITY_KEY_PREFIXES = ["pplx-"];
10
+ const OPENROUTER_KEY_PREFIXES = ["sk-or-"];
11
+ function createPerplexityWebSearchProviderBase() {
12
+ return {
13
+ id: "perplexity",
14
+ label: "Perplexity Search",
15
+ hint: "Requires Perplexity API key or OpenRouter API key · structured results",
16
+ onboardingScopes: [...PERPLEXITY_ONBOARDING_SCOPES],
17
+ credentialLabel: "Perplexity API key",
18
+ envVars: ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"],
19
+ placeholder: "pplx-...",
20
+ signupUrl: "https://www.perplexity.ai/settings/api",
21
+ docsUrl: "https://docs.openclaw.ai/perplexity",
22
+ autoDetectOrder: 50,
23
+ credentialPath: PERPLEXITY_CREDENTIAL_PATH,
24
+ ...createWebSearchProviderContractFields({
25
+ credentialPath: PERPLEXITY_CREDENTIAL_PATH,
26
+ searchCredential: {
27
+ type: "scoped",
28
+ scopeId: "perplexity"
29
+ },
30
+ configuredCredential: { pluginId: "perplexity" }
31
+ })
32
+ };
33
+ }
34
+ 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
+ }) };
41
+ }
42
+ function inferPerplexityBaseUrlFromApiKey(apiKey) {
43
+ if (!apiKey) return;
44
+ const normalized = normalizeLowercaseStringOrEmpty(apiKey);
45
+ if (PERPLEXITY_KEY_PREFIXES.some((prefix) => normalized.startsWith(prefix))) return "direct";
46
+ if (OPENROUTER_KEY_PREFIXES.some((prefix) => normalized.startsWith(prefix))) return "openrouter";
47
+ }
48
+ function isDirectPerplexityBaseUrl(baseUrl) {
49
+ try {
50
+ return normalizeLowercaseStringOrEmpty(new URL(baseUrl.trim()).hostname) === "api.perplexity.ai";
51
+ } catch {
52
+ return false;
53
+ }
54
+ }
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";
70
+ }
71
+ //#endregion
72
+ //#region extensions/perplexity/src/perplexity-web-search-provider.ts
73
+ const loadPerplexityWebSearchRuntime = createLazyRuntimeModule(() => import("./perplexity-web-search-provider.runtime-Cex5MH8x.js"));
74
+ function createPerplexityParameters(transport) {
75
+ const properties = {
76
+ query: {
77
+ type: "string",
78
+ description: "Search query string."
79
+ },
80
+ count: {
81
+ type: "integer",
82
+ description: "Number of results to return (1-10).",
83
+ minimum: 1,
84
+ maximum: 10
85
+ },
86
+ freshness: {
87
+ type: "string",
88
+ description: "Filter by time: 'day' (24h), 'week', 'month', or 'year'."
89
+ }
90
+ };
91
+ if (transport !== "chat_completions") {
92
+ properties.country = {
93
+ type: "string",
94
+ description: "Native Perplexity Search API only. 2-letter country code."
95
+ };
96
+ properties.language = {
97
+ type: "string",
98
+ description: "Native Perplexity Search API only. ISO 639-1 language code."
99
+ };
100
+ properties.date_after = {
101
+ type: "string",
102
+ description: "Native Perplexity Search API only. Only results published after this date (YYYY-MM-DD)."
103
+ };
104
+ properties.date_before = {
105
+ type: "string",
106
+ description: "Native Perplexity Search API only. Only results published before this date (YYYY-MM-DD)."
107
+ };
108
+ properties.domain_filter = {
109
+ type: "array",
110
+ items: { type: "string" },
111
+ description: "Native Perplexity Search API only. Domain filter (max 20)."
112
+ };
113
+ properties.max_tokens = {
114
+ type: "integer",
115
+ description: "Native Perplexity Search API only. Total content budget across all results.",
116
+ minimum: 1,
117
+ maximum: 1e6
118
+ };
119
+ properties.max_tokens_per_page = {
120
+ type: "integer",
121
+ description: "Native Perplexity Search API only. Max tokens extracted per page.",
122
+ minimum: 1
123
+ };
124
+ }
125
+ return {
126
+ type: "object",
127
+ properties,
128
+ required: ["query"]
129
+ };
130
+ }
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
+ function createPerplexityToolDefinition(searchConfig, runtimeTransport) {
136
+ const schemaTransport = runtimeTransport ?? (hasPerplexityLegacyOverride(searchConfig) ? "chat_completions" : void 0);
137
+ return {
138
+ 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
+ parameters: createPerplexityParameters(schemaTransport),
140
+ execute: async (args, context) => {
141
+ context?.signal?.throwIfAborted();
142
+ const { executePerplexitySearch } = await loadPerplexityWebSearchRuntime();
143
+ return await executePerplexitySearch(args, searchConfig, context?.signal);
144
+ }
145
+ };
146
+ }
147
+ function createPerplexityWebSearchProvider() {
148
+ return {
149
+ ...createPerplexityWebSearchProviderBase(),
150
+ resolveRuntimeMetadata: resolvePerplexityWebSearchRuntimeMetadata,
151
+ createTool: (ctx) => createPerplexityToolDefinition(mergeScopedSearchConfig(ctx.searchConfig, "perplexity", resolveProviderWebSearchPluginConfig(ctx.config, "perplexity")), ctx.runtimeMetadata?.perplexityTransport)
152
+ };
153
+ }
154
+ //#endregion
155
+ export { isDirectPerplexityBaseUrl as a, inferPerplexityBaseUrlFromApiKey as i, DEFAULT_PERPLEXITY_BASE_URL as n, PERPLEXITY_DIRECT_BASE_URL as r, createPerplexityWebSearchProvider as t };
@@ -1,7 +1,7 @@
1
- import { a as isDirectPerplexityBaseUrl, i as inferPerplexityBaseUrlFromApiKey, n as PERPLEXITY_DIRECT_BASE_URL, t as DEFAULT_PERPLEXITY_BASE_URL } from "./perplexity-web-search-provider.shared-idWXa4i8.js";
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-BCKqky14.js";
2
2
  import { normalizeOptionalString, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
3
3
  import { readProviderJsonResponse } from "openclaw/plugin-sdk/provider-http";
4
- import { DEFAULT_SEARCH_COUNT, MAX_SEARCH_COUNT, buildSearchCacheKey, isoToPerplexityDate, normalizeFreshness, normalizeToIsoDate, readCachedSearchPayload, readConfiguredSecretString, readPositiveIntegerParam, readProviderEnvValue, readStringArrayParam, readStringParam, resolveSearchCacheTtlMs, resolveSearchCount, resolveSearchTimeoutSeconds, resolveSiteName, throwWebSearchApiError, withTrustedWebSearchEndpoint, wrapWebContent, writeCachedSearchPayload } from "openclaw/plugin-sdk/provider-web-search";
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
7
  const DEFAULT_PERPLEXITY_MODEL = "perplexity/sonar-pro";
@@ -72,7 +72,8 @@ function extractPerplexityCitations(data) {
72
72
  const citations = [];
73
73
  for (const choice of data.choices ?? []) for (const annotation of choice.message?.annotations ?? []) {
74
74
  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);
75
+ const url = typeof annotation.url_citation?.url === "string" ? annotation.url_citation.url : typeof annotation.url === "string" ? annotation.url : void 0;
76
+ const normalizedUrl = normalizeOptionalString(url);
76
77
  if (normalizedUrl) citations.push(normalizedUrl);
77
78
  }
78
79
  return uniqueStrings(citations);
@@ -90,17 +91,21 @@ async function runPerplexitySearchApi(params) {
90
91
  if (params.searchBeforeDate) body.search_before_date_filter = params.searchBeforeDate;
91
92
  if (params.maxTokens !== void 0) body.max_tokens = params.maxTokens;
92
93
  if (params.maxTokensPerPage !== void 0) body.max_tokens_per_page = params.maxTokensPerPage;
94
+ const headers = buildPerplexityRequestHeaders(params.apiKey, true);
93
95
  return withTrustedWebSearchEndpoint({
94
96
  url: PERPLEXITY_SEARCH_ENDPOINT,
95
97
  timeoutSeconds: params.timeoutSeconds,
96
98
  signal: params.signal,
97
99
  init: {
98
100
  method: "POST",
99
- headers: buildPerplexityRequestHeaders(params.apiKey, true),
101
+ headers,
100
102
  body: JSON.stringify(body)
101
103
  }
102
104
  }, async (res) => {
103
- if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search");
105
+ if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search", {
106
+ headers,
107
+ signal: params.signal
108
+ });
104
109
  return ((await readProviderJsonResponse(res, "Perplexity Search")).results ?? []).map((entry) => ({
105
110
  title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
106
111
  url: entry.url ?? "",
@@ -120,17 +125,21 @@ async function runPerplexitySearch(params) {
120
125
  }]
121
126
  };
122
127
  if (params.freshness) body.search_recency_filter = params.freshness;
128
+ const headers = buildPerplexityRequestHeaders(params.apiKey);
123
129
  return withTrustedWebSearchEndpoint({
124
130
  url: endpoint,
125
131
  timeoutSeconds: params.timeoutSeconds,
126
132
  signal: params.signal,
127
133
  init: {
128
134
  method: "POST",
129
- headers: buildPerplexityRequestHeaders(params.apiKey),
135
+ headers,
130
136
  body: JSON.stringify(body)
131
137
  }
132
138
  }, async (res) => {
133
- if (!res.ok) return await throwWebSearchApiError(res, "Perplexity");
139
+ if (!res.ok) return await throwWebSearchApiError(res, "Perplexity", {
140
+ headers,
141
+ signal: params.signal
142
+ });
134
143
  const data = await readProviderJsonResponse(res, "Perplexity");
135
144
  const content = data.choices?.[0]?.message?.content;
136
145
  if (typeof content !== "string" || !content.trim()) throw new Error("Perplexity search returned no final answer. Retry the query or choose another search provider.");
@@ -171,29 +180,41 @@ async function executePerplexitySearch(args, searchConfig, signal) {
171
180
  });
172
181
  const maxTokensPerPage = readPositiveIntegerParam(args, "max_tokens_per_page", { message: "max_tokens_per_page must be a positive integer." });
173
182
  if (!structured) {
174
- if (country) return {
175
- error: "unsupported_country",
176
- message: "country filtering is only supported by the native Perplexity Search API path. Remove Perplexity baseUrl/model overrides or use a direct PERPLEXITY_API_KEY to enable it.",
177
- docs: "https://docs.openclaw.ai/tools/web"
178
- };
179
- if (language) return {
180
- error: "unsupported_language",
181
- message: "language filtering is only supported by the native Perplexity Search API path. Remove Perplexity baseUrl/model overrides or use a direct PERPLEXITY_API_KEY to enable it.",
182
- docs: "https://docs.openclaw.ai/tools/web"
183
- };
184
- if (rawDateAfter || rawDateBefore) return {
185
- error: "unsupported_date_filter",
186
- message: "date_after/date_before are only supported by the native Perplexity Search API path. Remove Perplexity baseUrl/model overrides or use a direct PERPLEXITY_API_KEY to enable them.",
187
- docs: "https://docs.openclaw.ai/tools/web"
188
- };
189
- if (domainFilter?.length) return {
190
- error: "unsupported_domain_filter",
191
- message: "domain_filter is only supported by the native Perplexity Search API path. Remove Perplexity baseUrl/model overrides or use a direct PERPLEXITY_API_KEY to enable it.",
192
- docs: "https://docs.openclaw.ai/tools/web"
193
- };
194
- if (maxTokens !== void 0 || maxTokensPerPage !== void 0) return {
195
- error: "unsupported_content_budget",
196
- message: "max_tokens and max_tokens_per_page are only supported by the native Perplexity Search API path. Remove Perplexity baseUrl/model overrides or use a direct PERPLEXITY_API_KEY to enable them.",
183
+ const unsupportedOptions = [
184
+ [
185
+ country,
186
+ "unsupported_country",
187
+ "country filtering",
188
+ "it"
189
+ ],
190
+ [
191
+ language,
192
+ "unsupported_language",
193
+ "language filtering",
194
+ "it"
195
+ ],
196
+ [
197
+ rawDateAfter || rawDateBefore,
198
+ "unsupported_date_filter",
199
+ "date_after/date_before",
200
+ "them"
201
+ ],
202
+ [
203
+ domainFilter?.length,
204
+ "unsupported_domain_filter",
205
+ "domain_filter",
206
+ "it"
207
+ ],
208
+ [
209
+ maxTokens !== void 0 || maxTokensPerPage !== void 0,
210
+ "unsupported_content_budget",
211
+ "max_tokens and max_tokens_per_page",
212
+ "them"
213
+ ]
214
+ ];
215
+ for (const [value, error, option, pronoun] of unsupportedOptions) if (value) return {
216
+ error,
217
+ message: `${option} ${pronoun === "them" ? "are" : "is"} only supported by the native Perplexity Search API path. Remove Perplexity baseUrl/model overrides or use a direct PERPLEXITY_API_KEY to enable ${pronoun}.`,
197
218
  docs: "https://docs.openclaw.ai/tools/web"
198
219
  };
199
220
  }
@@ -202,28 +223,18 @@ async function executePerplexitySearch(args, searchConfig, signal) {
202
223
  message: "language must be a 2-letter ISO 639-1 code like 'en', 'de', or 'fr'.",
203
224
  docs: "https://docs.openclaw.ai/tools/web"
204
225
  };
205
- if (rawFreshness && (rawDateAfter || rawDateBefore)) return {
206
- error: "conflicting_time_filters",
207
- message: "freshness and date_after/date_before cannot be used together. Use either freshness (day/week/month/year) or a date range (date_after/date_before), not both.",
208
- docs: "https://docs.openclaw.ai/tools/web"
209
- };
210
- const dateAfter = rawDateAfter ? normalizeToIsoDate(rawDateAfter) : void 0;
211
- const dateBefore = rawDateBefore ? normalizeToIsoDate(rawDateBefore) : void 0;
212
- if (rawDateAfter && !dateAfter) return {
213
- error: "invalid_date",
214
- message: "date_after must be YYYY-MM-DD format.",
215
- docs: "https://docs.openclaw.ai/tools/web"
216
- };
217
- if (rawDateBefore && !dateBefore) return {
218
- error: "invalid_date",
219
- message: "date_before must be YYYY-MM-DD format.",
220
- docs: "https://docs.openclaw.ai/tools/web"
221
- };
222
- if (dateAfter && dateBefore && dateAfter > dateBefore) return {
223
- error: "invalid_date_range",
224
- message: "date_after must be before date_before.",
225
- docs: "https://docs.openclaw.ai/tools/web"
226
- };
226
+ const parsedTimeFilters = parseWebSearchTimeFilters({
227
+ rawFreshness,
228
+ rawDateAfter,
229
+ rawDateBefore,
230
+ freshnessProvider: "perplexity",
231
+ invalidFreshnessMessage: "freshness must be day, week, month, or year.",
232
+ invalidDateAfterMessage: "date_after must be YYYY-MM-DD format.",
233
+ invalidDateBeforeMessage: "date_before must be YYYY-MM-DD format.",
234
+ invalidDateRangeMessage: "date_after must be before date_before."
235
+ });
236
+ if ("error" in parsedTimeFilters) return parsedTimeFilters;
237
+ const { dateAfter, dateBefore } = parsedTimeFilters;
227
238
  if (domainFilter?.length) {
228
239
  const hasDeny = domainFilter.some((entry) => entry.startsWith("-"));
229
240
  const hasAllow = domainFilter.some((entry) => !entry.startsWith("-"));
@@ -254,7 +265,8 @@ async function executePerplexitySearch(args, searchConfig, signal) {
254
265
  maxTokens,
255
266
  maxTokensPerPage
256
267
  ]);
257
- const cached = readCachedSearchPayload(cacheKey);
268
+ const cacheTtlMs = resolveSearchCacheTtlMs(searchConfig);
269
+ const cached = readCachedSearchPayload(cacheKey, cacheTtlMs);
258
270
  if (cached) return cached;
259
271
  const start = Date.now();
260
272
  const timeoutSeconds = resolveSearchTimeoutSeconds(searchConfig);
@@ -316,7 +328,7 @@ async function executePerplexitySearch(args, searchConfig, signal) {
316
328
  payload.tookMs = Date.now() - start;
317
329
  } else payload.tookMs = Date.now() - start;
318
330
  signal?.throwIfAborted();
319
- writeCachedSearchPayload(cacheKey, payload, resolveSearchCacheTtlMs(searchConfig));
331
+ writeCachedSearchPayload(cacheKey, payload, cacheTtlMs);
320
332
  return payload;
321
333
  }
322
334
  const testing = {
@@ -1,11 +1,3 @@
1
- import { o as resolvePerplexityWebSearchRuntimeMetadata, r as createPerplexityWebSearchProviderBase } from "./perplexity-web-search-provider.shared-idWXa4i8.js";
2
- //#region extensions/perplexity/web-search-contract-api.ts
3
- function createPerplexityWebSearchProvider() {
4
- return {
5
- ...createPerplexityWebSearchProviderBase(),
6
- resolveRuntimeMetadata: resolvePerplexityWebSearchRuntimeMetadata,
7
- createTool: () => null
8
- };
9
- }
10
- //#endregion
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BCKqky14.js";
2
+ import "./web-search-provider.js";
11
3
  export { createPerplexityWebSearchProvider };
@@ -1,2 +1,2 @@
1
- import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-CSYSs8kt.js";
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BCKqky14.js";
2
2
  export { createPerplexityWebSearchProvider };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openclaw/perplexity-plugin",
3
- "version": "2026.8.1-beta.3",
3
+ "version": "2026.8.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.8.1-beta.3"
21
+ "pluginApi": ">=2026.8.2"
22
22
  },
23
23
  "build": {
24
- "openclawVersion": "2026.8.1-beta.3",
24
+ "openclawVersion": "2026.8.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.8.1-beta.3"
41
+ "openclaw": ">=2026.8.2"
42
42
  },
43
43
  "peerDependenciesMeta": {
44
44
  "openclaw": {
@@ -1,88 +0,0 @@
1
- import { o as resolvePerplexityWebSearchRuntimeMetadata, r as createPerplexityWebSearchProviderBase } from "./perplexity-web-search-provider.shared-idWXa4i8.js";
2
- import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
3
- import { mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig } from "openclaw/plugin-sdk/provider-web-search-config-contract";
4
- import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
5
- //#region extensions/perplexity/src/perplexity-web-search-provider.ts
6
- const loadPerplexityWebSearchRuntime = createLazyRuntimeModule(() => import("./perplexity-web-search-provider.runtime-CDJXALXh.js"));
7
- function createPerplexityParameters(transport) {
8
- const properties = {
9
- query: {
10
- type: "string",
11
- description: "Search query string."
12
- },
13
- count: {
14
- type: "integer",
15
- description: "Number of results to return (1-10).",
16
- minimum: 1,
17
- maximum: 10
18
- },
19
- freshness: {
20
- type: "string",
21
- description: "Filter by time: 'day' (24h), 'week', 'month', or 'year'."
22
- }
23
- };
24
- if (transport !== "chat_completions") {
25
- properties.country = {
26
- type: "string",
27
- description: "Native Perplexity Search API only. 2-letter country code."
28
- };
29
- properties.language = {
30
- type: "string",
31
- description: "Native Perplexity Search API only. ISO 639-1 language code."
32
- };
33
- properties.date_after = {
34
- type: "string",
35
- description: "Native Perplexity Search API only. Only results published after this date (YYYY-MM-DD)."
36
- };
37
- properties.date_before = {
38
- type: "string",
39
- description: "Native Perplexity Search API only. Only results published before this date (YYYY-MM-DD)."
40
- };
41
- properties.domain_filter = {
42
- type: "array",
43
- items: { type: "string" },
44
- description: "Native Perplexity Search API only. Domain filter (max 20)."
45
- };
46
- properties.max_tokens = {
47
- type: "integer",
48
- description: "Native Perplexity Search API only. Total content budget across all results.",
49
- minimum: 1,
50
- maximum: 1e6
51
- };
52
- properties.max_tokens_per_page = {
53
- type: "integer",
54
- description: "Native Perplexity Search API only. Max tokens extracted per page.",
55
- minimum: 1
56
- };
57
- }
58
- return {
59
- type: "object",
60
- properties,
61
- required: ["query"]
62
- };
63
- }
64
- function hasPerplexityLegacyOverride(searchConfig) {
65
- const perplexity = isRecord(searchConfig?.perplexity) ? searchConfig.perplexity : void 0;
66
- return typeof perplexity?.baseUrl === "string" && perplexity.baseUrl.trim().length > 0 || typeof perplexity?.model === "string" && perplexity.model.trim().length > 0;
67
- }
68
- function createPerplexityToolDefinition(searchConfig, runtimeTransport) {
69
- const schemaTransport = runtimeTransport ?? (hasPerplexityLegacyOverride(searchConfig) ? "chat_completions" : void 0);
70
- return {
71
- 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.",
72
- parameters: createPerplexityParameters(schemaTransport),
73
- execute: async (args, context) => {
74
- context?.signal?.throwIfAborted();
75
- const { executePerplexitySearch } = await loadPerplexityWebSearchRuntime();
76
- return await executePerplexitySearch(args, searchConfig, context?.signal);
77
- }
78
- };
79
- }
80
- function createPerplexityWebSearchProvider() {
81
- return {
82
- ...createPerplexityWebSearchProviderBase(),
83
- resolveRuntimeMetadata: resolvePerplexityWebSearchRuntimeMetadata,
84
- createTool: (ctx) => createPerplexityToolDefinition(mergeScopedSearchConfig(ctx.searchConfig, "perplexity", resolveProviderWebSearchPluginConfig(ctx.config, "perplexity")), ctx.runtimeMetadata?.perplexityTransport)
85
- };
86
- }
87
- //#endregion
88
- export { createPerplexityWebSearchProvider as t };
@@ -1,71 +0,0 @@
1
- import { createWebSearchProviderContractFields, mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig } from "openclaw/plugin-sdk/provider-web-search-config-contract";
2
- import { normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
3
- //#region extensions/perplexity/src/perplexity-web-search-provider.shared.ts
4
- const DEFAULT_PERPLEXITY_BASE_URL = "https://openrouter.ai/api/v1";
5
- const PERPLEXITY_DIRECT_BASE_URL = "https://api.perplexity.ai";
6
- const PERPLEXITY_CREDENTIAL_PATH = "plugins.entries.perplexity.config.webSearch.apiKey";
7
- const PERPLEXITY_ONBOARDING_SCOPES = ["text-inference"];
8
- const PERPLEXITY_KEY_PREFIXES = ["pplx-"];
9
- const OPENROUTER_KEY_PREFIXES = ["sk-or-"];
10
- function createPerplexityWebSearchProviderBase() {
11
- return {
12
- id: "perplexity",
13
- label: "Perplexity Search",
14
- hint: "Requires Perplexity API key or OpenRouter API key · structured results",
15
- onboardingScopes: [...PERPLEXITY_ONBOARDING_SCOPES],
16
- credentialLabel: "Perplexity API key",
17
- envVars: ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"],
18
- placeholder: "pplx-...",
19
- signupUrl: "https://www.perplexity.ai/settings/api",
20
- docsUrl: "https://docs.openclaw.ai/perplexity",
21
- autoDetectOrder: 50,
22
- credentialPath: PERPLEXITY_CREDENTIAL_PATH,
23
- ...createWebSearchProviderContractFields({
24
- credentialPath: PERPLEXITY_CREDENTIAL_PATH,
25
- searchCredential: {
26
- type: "scoped",
27
- scopeId: "perplexity"
28
- },
29
- configuredCredential: { pluginId: "perplexity" }
30
- })
31
- };
32
- }
33
- function resolvePerplexityWebSearchRuntimeMetadata(ctx) {
34
- return { perplexityTransport: resolvePerplexityRuntimeTransport({
35
- searchConfig: mergeScopedSearchConfig(ctx.searchConfig, "perplexity", resolveProviderWebSearchPluginConfig(ctx.config, "perplexity")),
36
- resolvedKey: ctx.resolvedCredential?.value,
37
- keySource: ctx.resolvedCredential?.source ?? "missing",
38
- fallbackEnvVar: ctx.resolvedCredential?.fallbackEnvVar
39
- }) };
40
- }
41
- function inferPerplexityBaseUrlFromApiKey(apiKey) {
42
- if (!apiKey) return;
43
- const normalized = normalizeLowercaseStringOrEmpty(apiKey);
44
- if (PERPLEXITY_KEY_PREFIXES.some((prefix) => normalized.startsWith(prefix))) return "direct";
45
- if (OPENROUTER_KEY_PREFIXES.some((prefix) => normalized.startsWith(prefix))) return "openrouter";
46
- }
47
- function isDirectPerplexityBaseUrl(baseUrl) {
48
- try {
49
- return normalizeLowercaseStringOrEmpty(new URL(baseUrl.trim()).hostname) === "api.perplexity.ai";
50
- } catch {
51
- return false;
52
- }
53
- }
54
- function resolvePerplexityRuntimeTransport(params) {
55
- const perplexity = params.searchConfig?.perplexity;
56
- const scoped = perplexity && typeof perplexity === "object" && !Array.isArray(perplexity) ? perplexity : void 0;
57
- const configuredBaseUrl = normalizeOptionalString(scoped?.baseUrl) ?? "";
58
- const configuredModel = normalizeOptionalString(scoped?.model) ?? "";
59
- const baseUrl = (() => {
60
- if (configuredBaseUrl) return configuredBaseUrl;
61
- if (params.keySource === "env") {
62
- if (params.fallbackEnvVar === "PERPLEXITY_API_KEY") return PERPLEXITY_DIRECT_BASE_URL;
63
- if (params.fallbackEnvVar === "OPENROUTER_API_KEY") return DEFAULT_PERPLEXITY_BASE_URL;
64
- }
65
- if ((params.keySource === "config" || params.keySource === "secretRef") && params.resolvedKey) return inferPerplexityBaseUrlFromApiKey(params.resolvedKey) === "openrouter" ? DEFAULT_PERPLEXITY_BASE_URL : PERPLEXITY_DIRECT_BASE_URL;
66
- return DEFAULT_PERPLEXITY_BASE_URL;
67
- })();
68
- return configuredBaseUrl || configuredModel || !isDirectPerplexityBaseUrl(baseUrl) ? "chat_completions" : "search_api";
69
- }
70
- //#endregion
71
- export { isDirectPerplexityBaseUrl as a, inferPerplexityBaseUrlFromApiKey as i, PERPLEXITY_DIRECT_BASE_URL as n, resolvePerplexityWebSearchRuntimeMetadata as o, createPerplexityWebSearchProviderBase as r, DEFAULT_PERPLEXITY_BASE_URL as t };