@openclaw/perplexity-plugin 2026.8.1-beta.2 → 2026.9.1-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/dist/index.js +1 -1
- package/dist/perplexity-web-search-provider-BwUa_uAl.js +155 -0
- package/dist/{perplexity-web-search-provider.runtime-CMXrHVHO.js → perplexity-web-search-provider.runtime-C8Z5RiPA.js} +56 -56
- package/dist/web-search-contract-api.js +2 -10
- package/dist/web-search-provider.js +1 -1
- package/package.json +4 -4
- package/dist/perplexity-web-search-provider-BZTwy6bO.js +0 -88
- package/dist/perplexity-web-search-provider.shared-idWXa4i8.js +0 -71
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-
|
|
1
|
+
import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BwUa_uAl.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-C8Z5RiPA.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
|
|
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";
|
|
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,
|
|
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";
|
|
@@ -54,9 +54,6 @@ function buildPerplexityRequestHeaders(apiKey, acceptJson = false) {
|
|
|
54
54
|
"X-Title": "OpenClaw Web Search"
|
|
55
55
|
};
|
|
56
56
|
}
|
|
57
|
-
async function readPerplexityJsonResponse(response, label) {
|
|
58
|
-
return await readProviderJsonResponse(response, label);
|
|
59
|
-
}
|
|
60
57
|
function resolvePerplexityTransport(perplexity) {
|
|
61
58
|
const auth = resolvePerplexityApiKey(perplexity);
|
|
62
59
|
const baseUrl = resolvePerplexityBaseUrl(perplexity, auth.source, auth.apiKey);
|
|
@@ -104,7 +101,7 @@ async function runPerplexitySearchApi(params) {
|
|
|
104
101
|
}
|
|
105
102
|
}, async (res) => {
|
|
106
103
|
if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search");
|
|
107
|
-
return ((await
|
|
104
|
+
return ((await readProviderJsonResponse(res, "Perplexity Search")).results ?? []).map((entry) => ({
|
|
108
105
|
title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
|
|
109
106
|
url: entry.url ?? "",
|
|
110
107
|
description: entry.snippet ? wrapWebContent(entry.snippet, "web_search") : "",
|
|
@@ -134,9 +131,11 @@ async function runPerplexitySearch(params) {
|
|
|
134
131
|
}
|
|
135
132
|
}, async (res) => {
|
|
136
133
|
if (!res.ok) return await throwWebSearchApiError(res, "Perplexity");
|
|
137
|
-
const data = await
|
|
134
|
+
const data = await readProviderJsonResponse(res, "Perplexity");
|
|
135
|
+
const content = data.choices?.[0]?.message?.content;
|
|
136
|
+
if (typeof content !== "string" || !content.trim()) throw new Error("Perplexity search returned no final answer. Retry the query or choose another search provider.");
|
|
138
137
|
return {
|
|
139
|
-
content
|
|
138
|
+
content,
|
|
140
139
|
citations: extractPerplexityCitations(data)
|
|
141
140
|
};
|
|
142
141
|
});
|
|
@@ -172,29 +171,41 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
172
171
|
});
|
|
173
172
|
const maxTokensPerPage = readPositiveIntegerParam(args, "max_tokens_per_page", { message: "max_tokens_per_page must be a positive integer." });
|
|
174
173
|
if (!structured) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
174
|
+
const unsupportedOptions = [
|
|
175
|
+
[
|
|
176
|
+
country,
|
|
177
|
+
"unsupported_country",
|
|
178
|
+
"country filtering",
|
|
179
|
+
"it"
|
|
180
|
+
],
|
|
181
|
+
[
|
|
182
|
+
language,
|
|
183
|
+
"unsupported_language",
|
|
184
|
+
"language filtering",
|
|
185
|
+
"it"
|
|
186
|
+
],
|
|
187
|
+
[
|
|
188
|
+
rawDateAfter || rawDateBefore,
|
|
189
|
+
"unsupported_date_filter",
|
|
190
|
+
"date_after/date_before",
|
|
191
|
+
"them"
|
|
192
|
+
],
|
|
193
|
+
[
|
|
194
|
+
domainFilter?.length,
|
|
195
|
+
"unsupported_domain_filter",
|
|
196
|
+
"domain_filter",
|
|
197
|
+
"it"
|
|
198
|
+
],
|
|
199
|
+
[
|
|
200
|
+
maxTokens !== void 0 || maxTokensPerPage !== void 0,
|
|
201
|
+
"unsupported_content_budget",
|
|
202
|
+
"max_tokens and max_tokens_per_page",
|
|
203
|
+
"them"
|
|
204
|
+
]
|
|
205
|
+
];
|
|
206
|
+
for (const [value, error, option, pronoun] of unsupportedOptions) if (value) return {
|
|
207
|
+
error,
|
|
208
|
+
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}.`,
|
|
198
209
|
docs: "https://docs.openclaw.ai/tools/web"
|
|
199
210
|
};
|
|
200
211
|
}
|
|
@@ -203,28 +214,18 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
203
214
|
message: "language must be a 2-letter ISO 639-1 code like 'en', 'de', or 'fr'.",
|
|
204
215
|
docs: "https://docs.openclaw.ai/tools/web"
|
|
205
216
|
};
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
};
|
|
218
|
-
if (rawDateBefore && !dateBefore) return {
|
|
219
|
-
error: "invalid_date",
|
|
220
|
-
message: "date_before must be YYYY-MM-DD format.",
|
|
221
|
-
docs: "https://docs.openclaw.ai/tools/web"
|
|
222
|
-
};
|
|
223
|
-
if (dateAfter && dateBefore && dateAfter > dateBefore) return {
|
|
224
|
-
error: "invalid_date_range",
|
|
225
|
-
message: "date_after must be before date_before.",
|
|
226
|
-
docs: "https://docs.openclaw.ai/tools/web"
|
|
227
|
-
};
|
|
217
|
+
const parsedTimeFilters = parseWebSearchTimeFilters({
|
|
218
|
+
rawFreshness,
|
|
219
|
+
rawDateAfter,
|
|
220
|
+
rawDateBefore,
|
|
221
|
+
freshnessProvider: "perplexity",
|
|
222
|
+
invalidFreshnessMessage: "freshness must be day, week, month, or year.",
|
|
223
|
+
invalidDateAfterMessage: "date_after must be YYYY-MM-DD format.",
|
|
224
|
+
invalidDateBeforeMessage: "date_before must be YYYY-MM-DD format.",
|
|
225
|
+
invalidDateRangeMessage: "date_after must be before date_before."
|
|
226
|
+
});
|
|
227
|
+
if ("error" in parsedTimeFilters) return parsedTimeFilters;
|
|
228
|
+
const { dateAfter, dateBefore } = parsedTimeFilters;
|
|
228
229
|
if (domainFilter?.length) {
|
|
229
230
|
const hasDeny = domainFilter.some((entry) => entry.startsWith("-"));
|
|
230
231
|
const hasAllow = domainFilter.some((entry) => !entry.startsWith("-"));
|
|
@@ -245,7 +246,7 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
245
246
|
runtime.baseUrl,
|
|
246
247
|
runtime.model,
|
|
247
248
|
query,
|
|
248
|
-
resolveSearchCount(count, DEFAULT_SEARCH_COUNT),
|
|
249
|
+
structured ? resolveSearchCount(count, DEFAULT_SEARCH_COUNT) : void 0,
|
|
249
250
|
country,
|
|
250
251
|
language,
|
|
251
252
|
freshness,
|
|
@@ -326,8 +327,7 @@ const testing = {
|
|
|
326
327
|
resolvePerplexityModel,
|
|
327
328
|
resolvePerplexityTransport,
|
|
328
329
|
resolvePerplexityRequestModel,
|
|
329
|
-
resolvePerplexityApiKey
|
|
330
|
-
readPerplexityJsonResponse
|
|
330
|
+
resolvePerplexityApiKey
|
|
331
331
|
};
|
|
332
332
|
//#endregion
|
|
333
333
|
export { executePerplexitySearch, testing };
|
|
@@ -1,11 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
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-BwUa_uAl.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-
|
|
1
|
+
import { t as createPerplexityWebSearchProvider } from "./perplexity-web-search-provider-BwUa_uAl.js";
|
|
2
2
|
export { createPerplexityWebSearchProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/perplexity-plugin",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.9.1-beta.1",
|
|
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.
|
|
21
|
+
"pluginApi": ">=2026.9.1-beta.1"
|
|
22
22
|
},
|
|
23
23
|
"build": {
|
|
24
|
-
"openclawVersion": "2026.
|
|
24
|
+
"openclawVersion": "2026.9.1-beta.1",
|
|
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.
|
|
41
|
+
"openclaw": ">=2026.9.1-beta.1"
|
|
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-CMXrHVHO.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 };
|