@openclaw/perplexity-plugin 2026.8.1-beta.3 → 2026.8.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-B2_VZX21.js +155 -0
- package/dist/{perplexity-web-search-provider.runtime-CDJXALXh.js → perplexity-web-search-provider.runtime-BVBYV1y4.js} +64 -53
- 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-CSYSs8kt.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-B2_VZX21.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-BVBYV1y4.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-B2_VZX21.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";
|
|
@@ -90,17 +90,21 @@ async function runPerplexitySearchApi(params) {
|
|
|
90
90
|
if (params.searchBeforeDate) body.search_before_date_filter = params.searchBeforeDate;
|
|
91
91
|
if (params.maxTokens !== void 0) body.max_tokens = params.maxTokens;
|
|
92
92
|
if (params.maxTokensPerPage !== void 0) body.max_tokens_per_page = params.maxTokensPerPage;
|
|
93
|
+
const headers = buildPerplexityRequestHeaders(params.apiKey, true);
|
|
93
94
|
return withTrustedWebSearchEndpoint({
|
|
94
95
|
url: PERPLEXITY_SEARCH_ENDPOINT,
|
|
95
96
|
timeoutSeconds: params.timeoutSeconds,
|
|
96
97
|
signal: params.signal,
|
|
97
98
|
init: {
|
|
98
99
|
method: "POST",
|
|
99
|
-
headers
|
|
100
|
+
headers,
|
|
100
101
|
body: JSON.stringify(body)
|
|
101
102
|
}
|
|
102
103
|
}, async (res) => {
|
|
103
|
-
if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search"
|
|
104
|
+
if (!res.ok) return await throwWebSearchApiError(res, "Perplexity Search", {
|
|
105
|
+
headers,
|
|
106
|
+
signal: params.signal
|
|
107
|
+
});
|
|
104
108
|
return ((await readProviderJsonResponse(res, "Perplexity Search")).results ?? []).map((entry) => ({
|
|
105
109
|
title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
|
|
106
110
|
url: entry.url ?? "",
|
|
@@ -120,17 +124,21 @@ async function runPerplexitySearch(params) {
|
|
|
120
124
|
}]
|
|
121
125
|
};
|
|
122
126
|
if (params.freshness) body.search_recency_filter = params.freshness;
|
|
127
|
+
const headers = buildPerplexityRequestHeaders(params.apiKey);
|
|
123
128
|
return withTrustedWebSearchEndpoint({
|
|
124
129
|
url: endpoint,
|
|
125
130
|
timeoutSeconds: params.timeoutSeconds,
|
|
126
131
|
signal: params.signal,
|
|
127
132
|
init: {
|
|
128
133
|
method: "POST",
|
|
129
|
-
headers
|
|
134
|
+
headers,
|
|
130
135
|
body: JSON.stringify(body)
|
|
131
136
|
}
|
|
132
137
|
}, async (res) => {
|
|
133
|
-
if (!res.ok) return await throwWebSearchApiError(res, "Perplexity"
|
|
138
|
+
if (!res.ok) return await throwWebSearchApiError(res, "Perplexity", {
|
|
139
|
+
headers,
|
|
140
|
+
signal: params.signal
|
|
141
|
+
});
|
|
134
142
|
const data = await readProviderJsonResponse(res, "Perplexity");
|
|
135
143
|
const content = data.choices?.[0]?.message?.content;
|
|
136
144
|
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 +179,41 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
171
179
|
});
|
|
172
180
|
const maxTokensPerPage = readPositiveIntegerParam(args, "max_tokens_per_page", { message: "max_tokens_per_page must be a positive integer." });
|
|
173
181
|
if (!structured) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
182
|
+
const unsupportedOptions = [
|
|
183
|
+
[
|
|
184
|
+
country,
|
|
185
|
+
"unsupported_country",
|
|
186
|
+
"country filtering",
|
|
187
|
+
"it"
|
|
188
|
+
],
|
|
189
|
+
[
|
|
190
|
+
language,
|
|
191
|
+
"unsupported_language",
|
|
192
|
+
"language filtering",
|
|
193
|
+
"it"
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
rawDateAfter || rawDateBefore,
|
|
197
|
+
"unsupported_date_filter",
|
|
198
|
+
"date_after/date_before",
|
|
199
|
+
"them"
|
|
200
|
+
],
|
|
201
|
+
[
|
|
202
|
+
domainFilter?.length,
|
|
203
|
+
"unsupported_domain_filter",
|
|
204
|
+
"domain_filter",
|
|
205
|
+
"it"
|
|
206
|
+
],
|
|
207
|
+
[
|
|
208
|
+
maxTokens !== void 0 || maxTokensPerPage !== void 0,
|
|
209
|
+
"unsupported_content_budget",
|
|
210
|
+
"max_tokens and max_tokens_per_page",
|
|
211
|
+
"them"
|
|
212
|
+
]
|
|
213
|
+
];
|
|
214
|
+
for (const [value, error, option, pronoun] of unsupportedOptions) if (value) return {
|
|
215
|
+
error,
|
|
216
|
+
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
217
|
docs: "https://docs.openclaw.ai/tools/web"
|
|
198
218
|
};
|
|
199
219
|
}
|
|
@@ -202,28 +222,18 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
202
222
|
message: "language must be a 2-letter ISO 639-1 code like 'en', 'de', or 'fr'.",
|
|
203
223
|
docs: "https://docs.openclaw.ai/tools/web"
|
|
204
224
|
};
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
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
|
-
};
|
|
225
|
+
const parsedTimeFilters = parseWebSearchTimeFilters({
|
|
226
|
+
rawFreshness,
|
|
227
|
+
rawDateAfter,
|
|
228
|
+
rawDateBefore,
|
|
229
|
+
freshnessProvider: "perplexity",
|
|
230
|
+
invalidFreshnessMessage: "freshness must be day, week, month, or year.",
|
|
231
|
+
invalidDateAfterMessage: "date_after must be YYYY-MM-DD format.",
|
|
232
|
+
invalidDateBeforeMessage: "date_before must be YYYY-MM-DD format.",
|
|
233
|
+
invalidDateRangeMessage: "date_after must be before date_before."
|
|
234
|
+
});
|
|
235
|
+
if ("error" in parsedTimeFilters) return parsedTimeFilters;
|
|
236
|
+
const { dateAfter, dateBefore } = parsedTimeFilters;
|
|
227
237
|
if (domainFilter?.length) {
|
|
228
238
|
const hasDeny = domainFilter.some((entry) => entry.startsWith("-"));
|
|
229
239
|
const hasAllow = domainFilter.some((entry) => !entry.startsWith("-"));
|
|
@@ -254,7 +264,8 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
254
264
|
maxTokens,
|
|
255
265
|
maxTokensPerPage
|
|
256
266
|
]);
|
|
257
|
-
const
|
|
267
|
+
const cacheTtlMs = resolveSearchCacheTtlMs(searchConfig);
|
|
268
|
+
const cached = readCachedSearchPayload(cacheKey, cacheTtlMs);
|
|
258
269
|
if (cached) return cached;
|
|
259
270
|
const start = Date.now();
|
|
260
271
|
const timeoutSeconds = resolveSearchTimeoutSeconds(searchConfig);
|
|
@@ -316,7 +327,7 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
316
327
|
payload.tookMs = Date.now() - start;
|
|
317
328
|
} else payload.tookMs = Date.now() - start;
|
|
318
329
|
signal?.throwIfAborted();
|
|
319
|
-
writeCachedSearchPayload(cacheKey, payload,
|
|
330
|
+
writeCachedSearchPayload(cacheKey, payload, cacheTtlMs);
|
|
320
331
|
return payload;
|
|
321
332
|
}
|
|
322
333
|
const 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-B2_VZX21.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-B2_VZX21.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
|
|
3
|
+
"version": "2026.8.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.8.1
|
|
21
|
+
"pluginApi": ">=2026.8.1"
|
|
22
22
|
},
|
|
23
23
|
"build": {
|
|
24
|
-
"openclawVersion": "2026.8.1
|
|
24
|
+
"openclawVersion": "2026.8.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.8.1
|
|
41
|
+
"openclaw": ">=2026.8.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-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 };
|