@openclaw/perplexity-plugin 0.0.0 → 2026.6.9-beta.1

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/README.md CHANGED
@@ -1,3 +1,12 @@
1
- # @openclaw/perplexity-plugin
1
+ # OpenClaw Perplexity Plugin
2
2
 
3
- Reserved placeholder for the official OpenClaw plugin package. Use a published release version instead.
3
+ Official OpenClaw plugin for Perplexity.
4
+
5
+ Install from OpenClaw:
6
+
7
+ ```bash
8
+ openclaw plugins install @openclaw/perplexity-plugin
9
+ openclaw gateway restart
10
+ ```
11
+
12
+ See <https://docs.openclaw.ai/tools/perplexity-search> for setup and configuration.
package/dist/index.js ADDED
@@ -0,0 +1,13 @@
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-CaQDGcIE.js";
2
+ import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
3
+ //#region extensions/perplexity/index.ts
4
+ var perplexity_default = definePluginEntry({
5
+ id: "perplexity",
6
+ name: "Perplexity Plugin",
7
+ description: "Bundled Perplexity plugin",
8
+ register(api) {
9
+ api.registerWebSearchProvider(createPerplexityWebSearchProvider());
10
+ }
11
+ });
12
+ //#endregion
13
+ export { perplexity_default as default };
@@ -0,0 +1,90 @@
1
+ import { o as resolvePerplexityWebSearchRuntimeMetadata, r as createPerplexityWebSearchProviderBase } from "./perplexity-web-search-provider.shared-idWXa4i8.js";
2
+ import { mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig } from "openclaw/plugin-sdk/provider-web-search-config-contract";
3
+ import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
4
+ //#region extensions/perplexity/src/perplexity-web-search-provider.ts
5
+ let perplexityWebSearchRuntimePromise;
6
+ function loadPerplexityWebSearchRuntime() {
7
+ perplexityWebSearchRuntimePromise ??= import("./perplexity-web-search-provider.runtime-DwJn4ePw.js");
8
+ return perplexityWebSearchRuntimePromise;
9
+ }
10
+ function createPerplexityParameters(transport) {
11
+ const properties = {
12
+ query: {
13
+ type: "string",
14
+ description: "Search query string."
15
+ },
16
+ count: {
17
+ type: "integer",
18
+ description: "Number of results to return (1-10).",
19
+ minimum: 1,
20
+ maximum: 10
21
+ },
22
+ freshness: {
23
+ type: "string",
24
+ description: "Filter by time: 'day' (24h), 'week', 'month', or 'year'."
25
+ }
26
+ };
27
+ if (transport !== "chat_completions") {
28
+ properties.country = {
29
+ type: "string",
30
+ description: "Native Perplexity Search API only. 2-letter country code."
31
+ };
32
+ properties.language = {
33
+ type: "string",
34
+ description: "Native Perplexity Search API only. ISO 639-1 language code."
35
+ };
36
+ properties.date_after = {
37
+ type: "string",
38
+ description: "Native Perplexity Search API only. Only results published after this date (YYYY-MM-DD)."
39
+ };
40
+ properties.date_before = {
41
+ type: "string",
42
+ description: "Native Perplexity Search API only. Only results published before this date (YYYY-MM-DD)."
43
+ };
44
+ properties.domain_filter = {
45
+ type: "array",
46
+ items: { type: "string" },
47
+ description: "Native Perplexity Search API only. Domain filter (max 20)."
48
+ };
49
+ properties.max_tokens = {
50
+ type: "integer",
51
+ description: "Native Perplexity Search API only. Total content budget across all results.",
52
+ minimum: 1,
53
+ maximum: 1e6
54
+ };
55
+ properties.max_tokens_per_page = {
56
+ type: "integer",
57
+ description: "Native Perplexity Search API only. Max tokens extracted per page.",
58
+ minimum: 1
59
+ };
60
+ }
61
+ return {
62
+ type: "object",
63
+ properties,
64
+ required: ["query"]
65
+ };
66
+ }
67
+ function hasPerplexityLegacyOverride(searchConfig) {
68
+ const perplexity = isRecord(searchConfig?.perplexity) ? searchConfig.perplexity : void 0;
69
+ return typeof perplexity?.baseUrl === "string" && perplexity.baseUrl.trim().length > 0 || typeof perplexity?.model === "string" && perplexity.model.trim().length > 0;
70
+ }
71
+ function createPerplexityToolDefinition(searchConfig, runtimeTransport) {
72
+ const schemaTransport = runtimeTransport ?? (hasPerplexityLegacyOverride(searchConfig) ? "chat_completions" : void 0);
73
+ return {
74
+ 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.",
75
+ parameters: createPerplexityParameters(schemaTransport),
76
+ execute: async (args) => {
77
+ const { executePerplexitySearch } = await loadPerplexityWebSearchRuntime();
78
+ return await executePerplexitySearch(args, searchConfig);
79
+ }
80
+ };
81
+ }
82
+ function createPerplexityWebSearchProvider() {
83
+ return {
84
+ ...createPerplexityWebSearchProviderBase(),
85
+ resolveRuntimeMetadata: resolvePerplexityWebSearchRuntimeMetadata,
86
+ createTool: (ctx) => createPerplexityToolDefinition(mergeScopedSearchConfig(ctx.searchConfig, "perplexity", resolveProviderWebSearchPluginConfig(ctx.config, "perplexity")), ctx.runtimeMetadata?.perplexityTransport)
87
+ };
88
+ }
89
+ //#endregion
90
+ export { createPerplexityWebSearchProvider as t };
@@ -0,0 +1,334 @@
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";
2
+ import { normalizeOptionalString, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
3
+ 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
+ //#region extensions/perplexity/src/perplexity-web-search-provider.runtime.ts
5
+ const PERPLEXITY_SEARCH_ENDPOINT = "https://api.perplexity.ai/search";
6
+ const DEFAULT_PERPLEXITY_MODEL = "perplexity/sonar-pro";
7
+ function resolvePerplexityConfig(searchConfig) {
8
+ const perplexity = searchConfig?.perplexity;
9
+ return perplexity && typeof perplexity === "object" && !Array.isArray(perplexity) ? perplexity : {};
10
+ }
11
+ function resolvePerplexityApiKey(perplexity) {
12
+ const fromConfig = readConfiguredSecretString(perplexity?.apiKey, "tools.web.search.perplexity.apiKey");
13
+ if (fromConfig) return {
14
+ apiKey: fromConfig,
15
+ source: "config"
16
+ };
17
+ const fromPerplexityEnv = readProviderEnvValue(["PERPLEXITY_API_KEY"]);
18
+ if (fromPerplexityEnv) return {
19
+ apiKey: fromPerplexityEnv,
20
+ source: "perplexity_env"
21
+ };
22
+ const fromOpenRouterEnv = readProviderEnvValue(["OPENROUTER_API_KEY"]);
23
+ if (fromOpenRouterEnv) return {
24
+ apiKey: fromOpenRouterEnv,
25
+ source: "openrouter_env"
26
+ };
27
+ return {
28
+ apiKey: void 0,
29
+ source: "none"
30
+ };
31
+ }
32
+ function resolvePerplexityBaseUrl(perplexity, authSource = "none", configuredKey) {
33
+ const fromConfig = normalizeOptionalString(perplexity?.baseUrl) ?? "";
34
+ if (fromConfig) return fromConfig;
35
+ if (authSource === "perplexity_env") return PERPLEXITY_DIRECT_BASE_URL;
36
+ if (authSource === "openrouter_env") return DEFAULT_PERPLEXITY_BASE_URL;
37
+ if (authSource === "config") return inferPerplexityBaseUrlFromApiKey(configuredKey) === "openrouter" ? DEFAULT_PERPLEXITY_BASE_URL : PERPLEXITY_DIRECT_BASE_URL;
38
+ return DEFAULT_PERPLEXITY_BASE_URL;
39
+ }
40
+ function resolvePerplexityModel(perplexity) {
41
+ return (normalizeOptionalString(perplexity?.model) ?? "") || DEFAULT_PERPLEXITY_MODEL;
42
+ }
43
+ function resolvePerplexityRequestModel(baseUrl, model) {
44
+ if (!isDirectPerplexityBaseUrl(baseUrl)) return model;
45
+ return model.startsWith("perplexity/") ? model.slice(11) : model;
46
+ }
47
+ function buildPerplexityRequestHeaders(apiKey, acceptJson = false) {
48
+ return {
49
+ "Content-Type": "application/json",
50
+ ...acceptJson ? { Accept: "application/json" } : {},
51
+ Authorization: `Bearer ${apiKey}`,
52
+ "HTTP-Referer": "https://openclaw.ai",
53
+ "X-Title": "OpenClaw Web Search"
54
+ };
55
+ }
56
+ async function readPerplexityJsonResponse(response, label) {
57
+ try {
58
+ return await response.json();
59
+ } catch (cause) {
60
+ throw new Error(`${label}: malformed JSON response`, { cause });
61
+ }
62
+ }
63
+ function resolvePerplexityTransport(perplexity) {
64
+ const auth = resolvePerplexityApiKey(perplexity);
65
+ const baseUrl = resolvePerplexityBaseUrl(perplexity, auth.source, auth.apiKey);
66
+ const model = resolvePerplexityModel(perplexity);
67
+ const hasLegacyOverride = Boolean(normalizeOptionalString(perplexity?.baseUrl) || normalizeOptionalString(perplexity?.model));
68
+ return {
69
+ ...auth,
70
+ baseUrl,
71
+ model,
72
+ transport: hasLegacyOverride || !isDirectPerplexityBaseUrl(baseUrl) ? "chat_completions" : "search_api"
73
+ };
74
+ }
75
+ function extractPerplexityCitations(data) {
76
+ const topLevel = (data.citations ?? []).filter((url) => Boolean(normalizeOptionalString(url)));
77
+ if (topLevel.length > 0) return uniqueStrings(topLevel);
78
+ const citations = [];
79
+ for (const choice of data.choices ?? []) for (const annotation of choice.message?.annotations ?? []) {
80
+ if (annotation.type !== "url_citation") continue;
81
+ const normalizedUrl = normalizeOptionalString(typeof annotation.url_citation?.url === "string" ? annotation.url_citation.url : typeof annotation.url === "string" ? annotation.url : void 0);
82
+ if (normalizedUrl) citations.push(normalizedUrl);
83
+ }
84
+ return uniqueStrings(citations);
85
+ }
86
+ async function runPerplexitySearchApi(params) {
87
+ const body = {
88
+ query: params.query,
89
+ max_results: params.count
90
+ };
91
+ if (params.country) body.country = params.country;
92
+ if (params.searchDomainFilter?.length) body.search_domain_filter = params.searchDomainFilter;
93
+ if (params.searchRecencyFilter) body.search_recency_filter = params.searchRecencyFilter;
94
+ if (params.searchLanguageFilter?.length) body.search_language_filter = params.searchLanguageFilter;
95
+ if (params.searchAfterDate) body.search_after_date = params.searchAfterDate;
96
+ if (params.searchBeforeDate) body.search_before_date = params.searchBeforeDate;
97
+ if (params.maxTokens !== void 0) body.max_tokens = params.maxTokens;
98
+ if (params.maxTokensPerPage !== void 0) body.max_tokens_per_page = params.maxTokensPerPage;
99
+ return withTrustedWebSearchEndpoint({
100
+ url: PERPLEXITY_SEARCH_ENDPOINT,
101
+ timeoutSeconds: params.timeoutSeconds,
102
+ init: {
103
+ method: "POST",
104
+ headers: buildPerplexityRequestHeaders(params.apiKey, true),
105
+ body: JSON.stringify(body)
106
+ }
107
+ }, async (res) => {
108
+ if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search");
109
+ return ((await readPerplexityJsonResponse(res, "Perplexity Search")).results ?? []).map((entry) => ({
110
+ title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
111
+ url: entry.url ?? "",
112
+ description: entry.snippet ? wrapWebContent(entry.snippet, "web_search") : "",
113
+ published: entry.date ?? void 0,
114
+ siteName: resolveSiteName(entry.url) || void 0
115
+ }));
116
+ });
117
+ }
118
+ async function runPerplexitySearch(params) {
119
+ const endpoint = `${params.baseUrl.trim().replace(/\/$/, "")}/chat/completions`;
120
+ const body = {
121
+ model: resolvePerplexityRequestModel(params.baseUrl, params.model),
122
+ messages: [{
123
+ role: "user",
124
+ content: params.query
125
+ }]
126
+ };
127
+ if (params.freshness) body.search_recency_filter = params.freshness;
128
+ return withTrustedWebSearchEndpoint({
129
+ url: endpoint,
130
+ timeoutSeconds: params.timeoutSeconds,
131
+ init: {
132
+ method: "POST",
133
+ headers: buildPerplexityRequestHeaders(params.apiKey),
134
+ body: JSON.stringify(body)
135
+ }
136
+ }, async (res) => {
137
+ if (!res.ok) return await throwWebSearchApiError(res, "Perplexity");
138
+ const data = await readPerplexityJsonResponse(res, "Perplexity");
139
+ return {
140
+ content: data.choices?.[0]?.message?.content ?? "No response",
141
+ citations: extractPerplexityCitations(data)
142
+ };
143
+ });
144
+ }
145
+ async function executePerplexitySearch(args, searchConfig) {
146
+ const runtime = resolvePerplexityTransport(resolvePerplexityConfig(searchConfig));
147
+ if (!runtime.apiKey) return {
148
+ error: "missing_perplexity_api_key",
149
+ message: "web_search (perplexity) needs an API key. Set PERPLEXITY_API_KEY or OPENROUTER_API_KEY in the Gateway environment, or configure tools.web.search.perplexity.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.",
150
+ docs: "https://docs.openclaw.ai/tools/web"
151
+ };
152
+ const query = readStringParam(args, "query", { required: true });
153
+ const count = readPositiveIntegerParam(args, "count", {
154
+ max: MAX_SEARCH_COUNT,
155
+ message: `count must be an integer from 1 to ${MAX_SEARCH_COUNT}.`
156
+ }) ?? searchConfig?.maxResults ?? void 0;
157
+ const rawFreshness = readStringParam(args, "freshness");
158
+ const freshness = rawFreshness ? normalizeFreshness(rawFreshness, "perplexity") : void 0;
159
+ if (rawFreshness && !freshness) return {
160
+ error: "invalid_freshness",
161
+ message: "freshness must be day, week, month, or year.",
162
+ docs: "https://docs.openclaw.ai/tools/web"
163
+ };
164
+ const structured = runtime.transport === "search_api";
165
+ const country = readStringParam(args, "country");
166
+ const language = readStringParam(args, "language");
167
+ const rawDateAfter = readStringParam(args, "date_after");
168
+ const rawDateBefore = readStringParam(args, "date_before");
169
+ const domainFilter = readStringArrayParam(args, "domain_filter");
170
+ const maxTokens = readPositiveIntegerParam(args, "max_tokens", {
171
+ max: 1e6,
172
+ message: "max_tokens must be a positive integer."
173
+ });
174
+ const maxTokensPerPage = readPositiveIntegerParam(args, "max_tokens_per_page", { message: "max_tokens_per_page must be a positive integer." });
175
+ if (!structured) {
176
+ if (country) return {
177
+ error: "unsupported_country",
178
+ 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.",
179
+ docs: "https://docs.openclaw.ai/tools/web"
180
+ };
181
+ if (language) return {
182
+ error: "unsupported_language",
183
+ 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.",
184
+ docs: "https://docs.openclaw.ai/tools/web"
185
+ };
186
+ if (rawDateAfter || rawDateBefore) return {
187
+ error: "unsupported_date_filter",
188
+ 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.",
189
+ docs: "https://docs.openclaw.ai/tools/web"
190
+ };
191
+ if (domainFilter?.length) return {
192
+ error: "unsupported_domain_filter",
193
+ 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.",
194
+ docs: "https://docs.openclaw.ai/tools/web"
195
+ };
196
+ if (maxTokens !== void 0 || maxTokensPerPage !== void 0) return {
197
+ error: "unsupported_content_budget",
198
+ 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.",
199
+ docs: "https://docs.openclaw.ai/tools/web"
200
+ };
201
+ }
202
+ if (language && !/^[a-z]{2}$/iu.test(language)) return {
203
+ error: "invalid_language",
204
+ message: "language must be a 2-letter ISO 639-1 code like 'en', 'de', or 'fr'.",
205
+ docs: "https://docs.openclaw.ai/tools/web"
206
+ };
207
+ if (rawFreshness && (rawDateAfter || rawDateBefore)) return {
208
+ error: "conflicting_time_filters",
209
+ 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.",
210
+ docs: "https://docs.openclaw.ai/tools/web"
211
+ };
212
+ const dateAfter = rawDateAfter ? normalizeToIsoDate(rawDateAfter) : void 0;
213
+ const dateBefore = rawDateBefore ? normalizeToIsoDate(rawDateBefore) : void 0;
214
+ if (rawDateAfter && !dateAfter) return {
215
+ error: "invalid_date",
216
+ message: "date_after must be YYYY-MM-DD format.",
217
+ docs: "https://docs.openclaw.ai/tools/web"
218
+ };
219
+ if (rawDateBefore && !dateBefore) return {
220
+ error: "invalid_date",
221
+ message: "date_before must be YYYY-MM-DD format.",
222
+ docs: "https://docs.openclaw.ai/tools/web"
223
+ };
224
+ if (dateAfter && dateBefore && dateAfter > dateBefore) return {
225
+ error: "invalid_date_range",
226
+ message: "date_after must be before date_before.",
227
+ docs: "https://docs.openclaw.ai/tools/web"
228
+ };
229
+ if (domainFilter?.length) {
230
+ const hasDeny = domainFilter.some((entry) => entry.startsWith("-"));
231
+ const hasAllow = domainFilter.some((entry) => !entry.startsWith("-"));
232
+ if (hasDeny && hasAllow) return {
233
+ error: "invalid_domain_filter",
234
+ message: "domain_filter cannot mix allowlist and denylist entries. Use either all positive entries (allowlist) or all entries prefixed with '-' (denylist).",
235
+ docs: "https://docs.openclaw.ai/tools/web"
236
+ };
237
+ if (domainFilter.length > 20) return {
238
+ error: "invalid_domain_filter",
239
+ message: "domain_filter supports a maximum of 20 domains.",
240
+ docs: "https://docs.openclaw.ai/tools/web"
241
+ };
242
+ }
243
+ const cacheKey = buildSearchCacheKey([
244
+ "perplexity",
245
+ runtime.transport,
246
+ runtime.baseUrl,
247
+ runtime.model,
248
+ query,
249
+ resolveSearchCount(count, DEFAULT_SEARCH_COUNT),
250
+ country,
251
+ language,
252
+ freshness,
253
+ dateAfter,
254
+ dateBefore,
255
+ domainFilter?.join(","),
256
+ maxTokens,
257
+ maxTokensPerPage
258
+ ]);
259
+ const cached = readCachedSearchPayload(cacheKey);
260
+ if (cached) return cached;
261
+ const start = Date.now();
262
+ const timeoutSeconds = resolveSearchTimeoutSeconds(searchConfig);
263
+ const payload = runtime.transport === "chat_completions" ? {
264
+ query,
265
+ provider: "perplexity",
266
+ model: runtime.model,
267
+ tookMs: Date.now() - start,
268
+ externalContent: {
269
+ untrusted: true,
270
+ source: "web_search",
271
+ provider: "perplexity",
272
+ wrapped: true
273
+ },
274
+ ...await (async () => {
275
+ const result = await runPerplexitySearch({
276
+ query,
277
+ apiKey: runtime.apiKey,
278
+ baseUrl: runtime.baseUrl,
279
+ model: runtime.model,
280
+ timeoutSeconds,
281
+ freshness
282
+ });
283
+ return {
284
+ content: wrapWebContent(result.content, "web_search"),
285
+ citations: result.citations
286
+ };
287
+ })()
288
+ } : {
289
+ query,
290
+ provider: "perplexity",
291
+ count: 0,
292
+ tookMs: Date.now() - start,
293
+ externalContent: {
294
+ untrusted: true,
295
+ source: "web_search",
296
+ provider: "perplexity",
297
+ wrapped: true
298
+ },
299
+ results: await runPerplexitySearchApi({
300
+ query,
301
+ apiKey: runtime.apiKey,
302
+ count: resolveSearchCount(count, DEFAULT_SEARCH_COUNT),
303
+ timeoutSeconds,
304
+ country: country ?? void 0,
305
+ searchDomainFilter: domainFilter,
306
+ searchRecencyFilter: freshness,
307
+ searchLanguageFilter: language ? [language] : void 0,
308
+ searchAfterDate: dateAfter ? isoToPerplexityDate(dateAfter) : void 0,
309
+ searchBeforeDate: dateBefore ? isoToPerplexityDate(dateBefore) : void 0,
310
+ maxTokens: maxTokens ?? void 0,
311
+ maxTokensPerPage: maxTokensPerPage ?? void 0
312
+ })
313
+ };
314
+ if (Array.isArray(payload.results)) {
315
+ payload.count = payload.results.length;
316
+ payload.tookMs = Date.now() - start;
317
+ } else payload.tookMs = Date.now() - start;
318
+ writeCachedSearchPayload(cacheKey, payload, resolveSearchCacheTtlMs(searchConfig));
319
+ return payload;
320
+ }
321
+ const testing = {
322
+ inferPerplexityBaseUrlFromApiKey,
323
+ resolvePerplexityBaseUrl,
324
+ resolvePerplexityModel,
325
+ resolvePerplexityTransport,
326
+ isDirectPerplexityBaseUrl,
327
+ resolvePerplexityRequestModel,
328
+ resolvePerplexityApiKey,
329
+ readPerplexityJsonResponse,
330
+ normalizeToIsoDate,
331
+ isoToPerplexityDate
332
+ };
333
+ //#endregion
334
+ export { testing as __testing, testing, executePerplexitySearch };
@@ -0,0 +1,71 @@
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 };
@@ -0,0 +1,11 @@
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
11
+ export { createPerplexityWebSearchProvider };
@@ -0,0 +1,2 @@
1
+ import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-CaQDGcIE.js";
2
+ export { createPerplexityWebSearchProvider };
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "@openclaw/perplexity-plugin",
3
+ "version": "2026.6.9-beta.1",
4
+ "lockfileVersion": 3,
5
+ "requires": true,
6
+ "packages": {
7
+ "": {
8
+ "name": "@openclaw/perplexity-plugin",
9
+ "version": "2026.6.9-beta.1"
10
+ }
11
+ }
12
+ }
@@ -0,0 +1,57 @@
1
+ {
2
+ "id": "perplexity",
3
+ "activation": {
4
+ "onStartup": false
5
+ },
6
+ "setup": {
7
+ "providers": [
8
+ {
9
+ "id": "perplexity",
10
+ "envVars": ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"]
11
+ }
12
+ ]
13
+ },
14
+ "uiHints": {
15
+ "webSearch.apiKey": {
16
+ "label": "Perplexity API Key",
17
+ "help": "Perplexity or OpenRouter API key for web search.",
18
+ "sensitive": true,
19
+ "placeholder": "pplx-..."
20
+ },
21
+ "webSearch.baseUrl": {
22
+ "label": "Perplexity Base URL",
23
+ "help": "Optional Perplexity/OpenRouter chat-completions base URL override."
24
+ },
25
+ "webSearch.model": {
26
+ "label": "Perplexity Model",
27
+ "help": "Optional Sonar/OpenRouter model override."
28
+ }
29
+ },
30
+ "contracts": {
31
+ "webSearchProviders": ["perplexity"]
32
+ },
33
+ "configContracts": {
34
+ "compatibilityRuntimePaths": ["tools.web.search.apiKey"]
35
+ },
36
+ "configSchema": {
37
+ "type": "object",
38
+ "additionalProperties": false,
39
+ "properties": {
40
+ "webSearch": {
41
+ "type": "object",
42
+ "additionalProperties": false,
43
+ "properties": {
44
+ "apiKey": {
45
+ "type": ["string", "object"]
46
+ },
47
+ "baseUrl": {
48
+ "type": "string"
49
+ },
50
+ "model": {
51
+ "type": "string"
52
+ }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ }
package/package.json CHANGED
@@ -1,14 +1,50 @@
1
1
  {
2
2
  "name": "@openclaw/perplexity-plugin",
3
- "version": "0.0.0",
4
- "description": "Reserved package name for an official OpenClaw plugin.",
5
- "license": "MIT",
3
+ "version": "2026.6.9-beta.1",
4
+ "description": "OpenClaw Perplexity plugin.",
6
5
  "repository": {
7
6
  "type": "git",
8
- "url": "git+https://github.com/openclaw/openclaw.git"
7
+ "url": "https://github.com/openclaw/openclaw"
9
8
  },
10
- "publishConfig": {
11
- "access": "public",
12
- "tag": "placeholder"
13
- }
9
+ "type": "module",
10
+ "openclaw": {
11
+ "extensions": [
12
+ "./index.ts"
13
+ ],
14
+ "install": {
15
+ "clawhubSpec": "clawhub:@openclaw/perplexity-plugin",
16
+ "npmSpec": "@openclaw/perplexity-plugin",
17
+ "defaultChoice": "npm",
18
+ "minHostVersion": ">=2026.6.8"
19
+ },
20
+ "compat": {
21
+ "pluginApi": ">=2026.6.9-beta.1"
22
+ },
23
+ "build": {
24
+ "openclawVersion": "2026.6.9-beta.1",
25
+ "bundledDist": false
26
+ },
27
+ "release": {
28
+ "publishToClawHub": true,
29
+ "publishToNpm": true
30
+ },
31
+ "runtimeExtensions": [
32
+ "./dist/index.js"
33
+ ]
34
+ },
35
+ "files": [
36
+ "dist/**",
37
+ "openclaw.plugin.json",
38
+ "npm-shrinkwrap.json",
39
+ "README.md"
40
+ ],
41
+ "peerDependencies": {
42
+ "openclaw": ">=2026.6.9-beta.1"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "openclaw": {
46
+ "optional": true
47
+ }
48
+ },
49
+ "bundledDependencies": []
14
50
  }