@openclaw/perplexity-plugin 2026.11.3 → 2026.11.5-beta.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/.setup/{perplexity-web-search-provider-BP_SdCt9.mjs → perplexity-web-search-provider-RWOL37q-.mjs} +80 -99
- package/dist/.setup/{perplexity-web-search-provider.runtime-BKoiuxCz.mjs → perplexity-web-search-provider.runtime-Cz7e5C5L.mjs} +68 -102
- package/dist/.source-module-urls/55bce1209cd2907433d52e5a8d50a504c35f1f14230847335c4ef1c3a9fce6f5.json +1 -0
- package/dist/index.js +1 -1
- package/dist/web-search-contract-api.js +1 -2
- package/dist/web-search-provider.js +1 -2
- package/package.json +4 -4
|
@@ -1,35 +1,10 @@
|
|
|
1
1
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
2
|
-
import { createWebSearchProviderContractFields, mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig } from "openclaw/plugin-sdk/provider-web-search-config-contract";
|
|
2
|
+
import { WEB_SEARCH_QUERY_COUNT_PROPERTIES, createWebSearchProviderContractFields, mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig } from "openclaw/plugin-sdk/provider-web-search-config-contract";
|
|
3
3
|
import { asNonArrayRecord, normalizeLowercaseStringOrEmpty, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
4
|
//#region extensions/perplexity/src/perplexity-web-search-provider.shared.ts
|
|
5
5
|
const DEFAULT_PERPLEXITY_BASE_URL = "https://openrouter.ai/api/v1";
|
|
6
6
|
const PERPLEXITY_DIRECT_BASE_URL = "https://api.perplexity.ai";
|
|
7
7
|
const DEFAULT_PERPLEXITY_MODEL = "perplexity/sonar-pro";
|
|
8
|
-
const PERPLEXITY_CREDENTIAL_PATH = "plugins.entries.perplexity.config.webSearch.apiKey";
|
|
9
|
-
const PERPLEXITY_ONBOARDING_SCOPES = ["text-inference"];
|
|
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
8
|
function resolvePerplexityWebSearchRuntimeMetadata(ctx) {
|
|
34
9
|
const credential = ctx.resolvedCredential;
|
|
35
10
|
const source = credential?.source === "env" ? credential.fallbackEnvVar === "PERPLEXITY_API_KEY" ? "perplexity_env" : "openrouter_env" : (credential?.source === "config" || credential?.source === "secretRef") && credential.value ? "config" : "none";
|
|
@@ -51,7 +26,6 @@ function resolvePerplexityRuntime(perplexity, auth) {
|
|
|
51
26
|
const baseUrl = normalizeOptionalString(perplexity?.baseUrl) || (auth.source === "perplexity_env" || auth.source === "config" && !normalizeLowercaseStringOrEmpty(auth.apiKey).startsWith("sk-or-") ? PERPLEXITY_DIRECT_BASE_URL : DEFAULT_PERPLEXITY_BASE_URL);
|
|
52
27
|
return {
|
|
53
28
|
apiKey: auth.apiKey,
|
|
54
|
-
source: auth.source,
|
|
55
29
|
baseUrl,
|
|
56
30
|
model: normalizeOptionalString(perplexity?.model) || DEFAULT_PERPLEXITY_MODEL,
|
|
57
31
|
transport: hasPerplexityLegacyOverride(perplexity) || !isDirectPerplexityBaseUrl(baseUrl) ? "chat_completions" : "search_api"
|
|
@@ -59,81 +33,88 @@ function resolvePerplexityRuntime(perplexity, auth) {
|
|
|
59
33
|
}
|
|
60
34
|
//#endregion
|
|
61
35
|
//#region extensions/perplexity/src/perplexity-web-search-provider.ts
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
const properties = {
|
|
65
|
-
query: {
|
|
66
|
-
type: "string",
|
|
67
|
-
description: "Search query string."
|
|
68
|
-
},
|
|
69
|
-
count: {
|
|
70
|
-
type: "integer",
|
|
71
|
-
description: "Number of results to return (1-10).",
|
|
72
|
-
minimum: 1,
|
|
73
|
-
maximum: 10
|
|
74
|
-
},
|
|
75
|
-
freshness: {
|
|
76
|
-
type: "string",
|
|
77
|
-
description: "Filter by time: 'day' (24h), 'week', 'month', or 'year'."
|
|
78
|
-
}
|
|
79
|
-
};
|
|
80
|
-
if (transport !== "chat_completions") {
|
|
81
|
-
properties.country = {
|
|
82
|
-
type: "string",
|
|
83
|
-
description: "Native Perplexity Search API only. 2-letter country code."
|
|
84
|
-
};
|
|
85
|
-
properties.language = {
|
|
86
|
-
type: "string",
|
|
87
|
-
description: "Native Perplexity Search API only. ISO 639-1 language code."
|
|
88
|
-
};
|
|
89
|
-
properties.date_after = {
|
|
90
|
-
type: "string",
|
|
91
|
-
description: "Native Perplexity Search API only. Only results published after this date (YYYY-MM-DD)."
|
|
92
|
-
};
|
|
93
|
-
properties.date_before = {
|
|
94
|
-
type: "string",
|
|
95
|
-
description: "Native Perplexity Search API only. Only results published before this date (YYYY-MM-DD)."
|
|
96
|
-
};
|
|
97
|
-
properties.domain_filter = {
|
|
98
|
-
type: "array",
|
|
99
|
-
items: { type: "string" },
|
|
100
|
-
description: "Native Perplexity Search API only. Domain filter (max 20)."
|
|
101
|
-
};
|
|
102
|
-
properties.max_tokens = {
|
|
103
|
-
type: "integer",
|
|
104
|
-
description: "Native Perplexity Search API only. Total content budget across all results.",
|
|
105
|
-
minimum: 1,
|
|
106
|
-
maximum: 1e6
|
|
107
|
-
};
|
|
108
|
-
properties.max_tokens_per_page = {
|
|
109
|
-
type: "integer",
|
|
110
|
-
description: "Native Perplexity Search API only. Max tokens extracted per page.",
|
|
111
|
-
minimum: 1
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
return {
|
|
115
|
-
type: "object",
|
|
116
|
-
properties,
|
|
117
|
-
required: ["query"]
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
function createPerplexityToolDefinition(searchConfig, runtimeTransport) {
|
|
121
|
-
const schemaTransport = runtimeTransport ?? (hasPerplexityLegacyOverride(resolvePerplexityConfig(searchConfig)) ? "chat_completions" : void 0);
|
|
122
|
-
return {
|
|
123
|
-
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.",
|
|
124
|
-
parameters: createPerplexityParameters(schemaTransport),
|
|
125
|
-
execute: async (args, context) => {
|
|
126
|
-
context?.signal?.throwIfAborted();
|
|
127
|
-
const { executePerplexitySearch } = await loadPerplexityWebSearchRuntime();
|
|
128
|
-
return await executePerplexitySearch(args, searchConfig, context?.signal);
|
|
129
|
-
}
|
|
130
|
-
};
|
|
131
|
-
}
|
|
36
|
+
const PERPLEXITY_CREDENTIAL_PATH = "plugins.entries.perplexity.config.webSearch.apiKey";
|
|
37
|
+
const loadPerplexityWebSearchRuntime = createLazyRuntimeModule(() => import("./perplexity-web-search-provider.runtime-Cz7e5C5L.mjs"));
|
|
132
38
|
function createPerplexityWebSearchProvider() {
|
|
133
39
|
return {
|
|
134
|
-
|
|
40
|
+
id: "perplexity",
|
|
41
|
+
label: "Perplexity Search",
|
|
42
|
+
hint: "Requires Perplexity API key or OpenRouter API key · structured results",
|
|
43
|
+
onboardingScopes: ["text-inference"],
|
|
44
|
+
credentialLabel: "Perplexity API key",
|
|
45
|
+
envVars: ["PERPLEXITY_API_KEY", "OPENROUTER_API_KEY"],
|
|
46
|
+
placeholder: "pplx-...",
|
|
47
|
+
signupUrl: "https://www.perplexity.ai/settings/api",
|
|
48
|
+
docsUrl: "https://docs.openclaw.ai/perplexity",
|
|
49
|
+
autoDetectOrder: 50,
|
|
50
|
+
credentialPath: PERPLEXITY_CREDENTIAL_PATH,
|
|
51
|
+
...createWebSearchProviderContractFields({
|
|
52
|
+
credentialPath: PERPLEXITY_CREDENTIAL_PATH,
|
|
53
|
+
searchCredential: {
|
|
54
|
+
type: "scoped",
|
|
55
|
+
scopeId: "perplexity"
|
|
56
|
+
},
|
|
57
|
+
configuredCredential: { pluginId: "perplexity" }
|
|
58
|
+
}),
|
|
135
59
|
resolveRuntimeMetadata: resolvePerplexityWebSearchRuntimeMetadata,
|
|
136
|
-
createTool: (ctx) =>
|
|
60
|
+
createTool: (ctx) => {
|
|
61
|
+
const searchConfig = mergeScopedSearchConfig(ctx.searchConfig, "perplexity", resolveProviderWebSearchPluginConfig(ctx.config, "perplexity"));
|
|
62
|
+
const schemaTransport = ctx.runtimeMetadata?.perplexityTransport ?? (hasPerplexityLegacyOverride(resolvePerplexityConfig(searchConfig)) ? "chat_completions" : void 0);
|
|
63
|
+
const properties = {
|
|
64
|
+
...WEB_SEARCH_QUERY_COUNT_PROPERTIES,
|
|
65
|
+
freshness: {
|
|
66
|
+
type: "string",
|
|
67
|
+
description: "Filter by time: 'day' (24h), 'week', 'month', or 'year'."
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
if (schemaTransport !== "chat_completions") {
|
|
71
|
+
properties.country = {
|
|
72
|
+
type: "string",
|
|
73
|
+
description: "Native Perplexity Search API only. 2-letter country code."
|
|
74
|
+
};
|
|
75
|
+
properties.language = {
|
|
76
|
+
type: "string",
|
|
77
|
+
description: "Native Perplexity Search API only. ISO 639-1 language code."
|
|
78
|
+
};
|
|
79
|
+
properties.date_after = {
|
|
80
|
+
type: "string",
|
|
81
|
+
description: "Native Perplexity Search API only. Only results published after this date (YYYY-MM-DD)."
|
|
82
|
+
};
|
|
83
|
+
properties.date_before = {
|
|
84
|
+
type: "string",
|
|
85
|
+
description: "Native Perplexity Search API only. Only results published before this date (YYYY-MM-DD)."
|
|
86
|
+
};
|
|
87
|
+
properties.domain_filter = {
|
|
88
|
+
type: "array",
|
|
89
|
+
items: { type: "string" },
|
|
90
|
+
description: "Native Perplexity Search API only. Domain filter (max 20)."
|
|
91
|
+
};
|
|
92
|
+
properties.max_tokens = {
|
|
93
|
+
type: "integer",
|
|
94
|
+
description: "Native Perplexity Search API only. Total content budget across all results.",
|
|
95
|
+
minimum: 1,
|
|
96
|
+
maximum: 1e6
|
|
97
|
+
};
|
|
98
|
+
properties.max_tokens_per_page = {
|
|
99
|
+
type: "integer",
|
|
100
|
+
description: "Native Perplexity Search API only. Max tokens extracted per page.",
|
|
101
|
+
minimum: 1
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
return {
|
|
105
|
+
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.",
|
|
106
|
+
parameters: {
|
|
107
|
+
type: "object",
|
|
108
|
+
properties,
|
|
109
|
+
required: ["query"]
|
|
110
|
+
},
|
|
111
|
+
execute: async (args, context) => {
|
|
112
|
+
context?.signal?.throwIfAborted();
|
|
113
|
+
const { executePerplexitySearch } = await loadPerplexityWebSearchRuntime();
|
|
114
|
+
return await executePerplexitySearch(args, searchConfig, context?.signal);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
}
|
|
137
118
|
};
|
|
138
119
|
}
|
|
139
120
|
//#endregion
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
import { i as resolvePerplexityRuntime, n as isDirectPerplexityBaseUrl, r as resolvePerplexityConfig } from "./perplexity-web-search-provider-
|
|
1
|
+
import { i as resolvePerplexityRuntime, n as isDirectPerplexityBaseUrl, r as resolvePerplexityConfig } from "./perplexity-web-search-provider-RWOL37q-.mjs";
|
|
2
2
|
import { normalizeOptionalString, uniqueStrings } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
3
|
+
import { sha256Hex } from "openclaw/plugin-sdk/node-crypto-runtime";
|
|
3
4
|
import { readProviderJsonResponse, resolveProviderRequestHeaders } from "openclaw/plugin-sdk/provider-http";
|
|
4
|
-
import {
|
|
5
|
+
import { omitNullRequestHeaders } from "openclaw/plugin-sdk/provider-request-headers";
|
|
6
|
+
import { DEFAULT_SEARCH_COUNT, buildSearchCacheKey, externalContentStamp, isoToPerplexityDate, normalizeFreshness, parseWebSearchTimeFilters, readCachedSearchPayload, readConfiguredSecretString, readPositiveIntegerParam, readProviderEnvValue, readStringArrayParam, readStringParam, readWebSearchQueryAndCount, resolveSearchCacheTtlMs, resolveSearchCount, resolveSearchTimeoutSeconds, resolveSiteName, throwWebSearchApiError, withTrustedWebSearchEndpoint, wrapWebContent, writeCachedSearchPayload } from "openclaw/plugin-sdk/provider-web-search";
|
|
5
7
|
//#region extensions/perplexity/src/perplexity-web-search-provider.runtime.ts
|
|
6
8
|
const PERPLEXITY_SEARCH_ENDPOINT = "https://api.perplexity.ai/search";
|
|
7
9
|
function resolvePerplexityApiKey(perplexity) {
|
|
@@ -29,20 +31,6 @@ function resolvePerplexityRequestModel(baseUrl, model) {
|
|
|
29
31
|
if (!isDirectPerplexityBaseUrl(baseUrl)) return model;
|
|
30
32
|
return model.startsWith("perplexity/") ? model.slice(11) : model;
|
|
31
33
|
}
|
|
32
|
-
function buildPerplexityRequestHeaders(params) {
|
|
33
|
-
const defaultHeaders = {
|
|
34
|
-
"Content-Type": "application/json",
|
|
35
|
-
...params.acceptJson ? { Accept: "application/json" } : {},
|
|
36
|
-
Authorization: `Bearer ${params.apiKey}`
|
|
37
|
-
};
|
|
38
|
-
return resolveProviderRequestHeaders({
|
|
39
|
-
provider: "perplexity",
|
|
40
|
-
baseUrl: params.baseUrl && !isDirectPerplexityBaseUrl(params.baseUrl) ? params.baseUrl : void 0,
|
|
41
|
-
capability: "other",
|
|
42
|
-
transport: "http",
|
|
43
|
-
defaultHeaders
|
|
44
|
-
}) ?? defaultHeaders;
|
|
45
|
-
}
|
|
46
34
|
function extractPerplexityCitations(data) {
|
|
47
35
|
const topLevel = (data.citations ?? []).filter((url) => Boolean(normalizeOptionalString(url)));
|
|
48
36
|
if (topLevel.length > 0) return uniqueStrings(topLevel);
|
|
@@ -55,63 +43,6 @@ function extractPerplexityCitations(data) {
|
|
|
55
43
|
}
|
|
56
44
|
return uniqueStrings(citations);
|
|
57
45
|
}
|
|
58
|
-
async function runPerplexitySearch(params) {
|
|
59
|
-
const structured = params.transport === "search_api";
|
|
60
|
-
const label = structured ? "Perplexity Search" : "Perplexity";
|
|
61
|
-
const endpoint = structured ? PERPLEXITY_SEARCH_ENDPOINT : `${params.baseUrl.trim().replace(/\/$/, "")}/chat/completions`;
|
|
62
|
-
const body = structured ? {
|
|
63
|
-
query: params.query,
|
|
64
|
-
max_results: params.count,
|
|
65
|
-
...params.country ? { country: params.country } : {},
|
|
66
|
-
...params.searchDomainFilter?.length ? { search_domain_filter: params.searchDomainFilter } : {},
|
|
67
|
-
...params.searchRecencyFilter ? { search_recency_filter: params.searchRecencyFilter } : {},
|
|
68
|
-
...params.searchLanguageFilter?.length ? { search_language_filter: params.searchLanguageFilter } : {},
|
|
69
|
-
...params.searchAfterDate ? { search_after_date_filter: params.searchAfterDate } : {},
|
|
70
|
-
...params.searchBeforeDate ? { search_before_date_filter: params.searchBeforeDate } : {},
|
|
71
|
-
...params.maxTokens !== void 0 ? { max_tokens: params.maxTokens } : {},
|
|
72
|
-
...params.maxTokensPerPage !== void 0 ? { max_tokens_per_page: params.maxTokensPerPage } : {}
|
|
73
|
-
} : {
|
|
74
|
-
model: resolvePerplexityRequestModel(params.baseUrl, params.model),
|
|
75
|
-
messages: [{
|
|
76
|
-
role: "user",
|
|
77
|
-
content: params.query
|
|
78
|
-
}],
|
|
79
|
-
...params.freshness ? { search_recency_filter: params.freshness } : {}
|
|
80
|
-
};
|
|
81
|
-
const headers = buildPerplexityRequestHeaders({
|
|
82
|
-
apiKey: params.apiKey,
|
|
83
|
-
...structured ? { acceptJson: true } : { baseUrl: params.baseUrl }
|
|
84
|
-
});
|
|
85
|
-
return withTrustedWebSearchEndpoint({
|
|
86
|
-
url: endpoint,
|
|
87
|
-
timeoutSeconds: params.timeoutSeconds,
|
|
88
|
-
signal: params.signal,
|
|
89
|
-
init: {
|
|
90
|
-
method: "POST",
|
|
91
|
-
headers,
|
|
92
|
-
body: JSON.stringify(body)
|
|
93
|
-
}
|
|
94
|
-
}, async (res) => {
|
|
95
|
-
if (!res.ok) return await throwWebSearchApiError(res, label, {
|
|
96
|
-
headers,
|
|
97
|
-
signal: params.signal
|
|
98
|
-
});
|
|
99
|
-
if (structured) return ((await readProviderJsonResponse(res, label)).results ?? []).slice(0, params.count).map((entry) => ({
|
|
100
|
-
title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
|
|
101
|
-
url: entry.url ?? "",
|
|
102
|
-
description: entry.snippet ? wrapWebContent(entry.snippet, "web_search") : "",
|
|
103
|
-
published: entry.date ?? void 0,
|
|
104
|
-
siteName: resolveSiteName(entry.url) || void 0
|
|
105
|
-
}));
|
|
106
|
-
const data = await readProviderJsonResponse(res, label);
|
|
107
|
-
const content = data.choices?.[0]?.message?.content;
|
|
108
|
-
if (typeof content !== "string" || !content.trim()) throw new Error("Perplexity search returned no final answer. Retry the query or choose another search provider.");
|
|
109
|
-
return {
|
|
110
|
-
content,
|
|
111
|
-
citations: extractPerplexityCitations(data)
|
|
112
|
-
};
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
46
|
async function executePerplexitySearch(args, searchConfig, signal) {
|
|
116
47
|
const perplexityConfig = resolvePerplexityConfig(searchConfig);
|
|
117
48
|
const runtime = resolvePerplexityRuntime(perplexityConfig, resolvePerplexityApiKey(perplexityConfig));
|
|
@@ -120,11 +51,7 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
120
51
|
message: "web_search (perplexity) needs an API key. Set PERPLEXITY_API_KEY or OPENROUTER_API_KEY in the Gateway environment, or configure plugins.entries.perplexity.config.webSearch.apiKey. If you do not want to configure a search API key, use web_fetch for a specific URL or the browser tool for interactive pages.",
|
|
121
52
|
docs: "https://docs.openclaw.ai/tools/web"
|
|
122
53
|
};
|
|
123
|
-
const query =
|
|
124
|
-
const count = readPositiveIntegerParam(args, "count", {
|
|
125
|
-
max: MAX_SEARCH_COUNT,
|
|
126
|
-
message: `count must be an integer from 1 to ${MAX_SEARCH_COUNT}.`
|
|
127
|
-
}) ?? searchConfig?.maxResults ?? void 0;
|
|
54
|
+
const { query, count } = readWebSearchQueryAndCount(args, searchConfig);
|
|
128
55
|
const rawFreshness = readStringParam(args, "freshness");
|
|
129
56
|
const freshness = rawFreshness ? normalizeFreshness(rawFreshness, "perplexity") : void 0;
|
|
130
57
|
if (rawFreshness && !freshness) return {
|
|
@@ -215,6 +142,7 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
215
142
|
}
|
|
216
143
|
const cacheKey = buildSearchCacheKey([
|
|
217
144
|
"perplexity",
|
|
145
|
+
sha256Hex(runtime.apiKey),
|
|
218
146
|
runtime.transport,
|
|
219
147
|
runtime.baseUrl,
|
|
220
148
|
runtime.model,
|
|
@@ -234,28 +162,71 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
234
162
|
if (cached) return cached;
|
|
235
163
|
const start = Date.now();
|
|
236
164
|
const timeoutSeconds = resolveSearchTimeoutSeconds(searchConfig);
|
|
237
|
-
const
|
|
165
|
+
const searchCount = structured ? resolveSearchCount(count, DEFAULT_SEARCH_COUNT) : 0;
|
|
166
|
+
const searchLanguageFilter = language ? [language] : void 0;
|
|
167
|
+
const searchAfterDate = structured && dateAfter ? isoToPerplexityDate(dateAfter) : void 0;
|
|
168
|
+
const searchBeforeDate = structured && dateBefore ? isoToPerplexityDate(dateBefore) : void 0;
|
|
169
|
+
const label = structured ? "Perplexity Search" : "Perplexity";
|
|
170
|
+
const endpoint = structured ? PERPLEXITY_SEARCH_ENDPOINT : `${runtime.baseUrl.trim().replace(/\/$/, "")}/chat/completions`;
|
|
171
|
+
const body = structured ? {
|
|
238
172
|
query,
|
|
239
|
-
|
|
173
|
+
max_results: searchCount,
|
|
174
|
+
...country ? { country } : {},
|
|
175
|
+
...domainFilter?.length ? { search_domain_filter: domainFilter } : {},
|
|
176
|
+
...freshness ? { search_recency_filter: freshness } : {},
|
|
177
|
+
...searchLanguageFilter?.length ? { search_language_filter: searchLanguageFilter } : {},
|
|
178
|
+
...searchAfterDate ? { search_after_date_filter: searchAfterDate } : {},
|
|
179
|
+
...searchBeforeDate ? { search_before_date_filter: searchBeforeDate } : {},
|
|
180
|
+
...maxTokens !== void 0 ? { max_tokens: maxTokens } : {},
|
|
181
|
+
...maxTokensPerPage !== void 0 ? { max_tokens_per_page: maxTokensPerPage } : {}
|
|
182
|
+
} : {
|
|
183
|
+
model: resolvePerplexityRequestModel(runtime.baseUrl, runtime.model),
|
|
184
|
+
messages: [{
|
|
185
|
+
role: "user",
|
|
186
|
+
content: query
|
|
187
|
+
}],
|
|
188
|
+
...freshness ? { search_recency_filter: freshness } : {}
|
|
189
|
+
};
|
|
190
|
+
const defaultHeaders = {
|
|
191
|
+
"Content-Type": "application/json",
|
|
192
|
+
...structured ? { Accept: "application/json" } : {},
|
|
193
|
+
Authorization: `Bearer ${runtime.apiKey}`
|
|
194
|
+
};
|
|
195
|
+
const headers = omitNullRequestHeaders(resolveProviderRequestHeaders({
|
|
196
|
+
provider: "perplexity",
|
|
197
|
+
baseUrl: !structured && !isDirectPerplexityBaseUrl(runtime.baseUrl) ? runtime.baseUrl : void 0,
|
|
198
|
+
capability: "other",
|
|
199
|
+
transport: "http",
|
|
200
|
+
defaultHeaders
|
|
201
|
+
})) ?? defaultHeaders;
|
|
202
|
+
const result = await withTrustedWebSearchEndpoint({
|
|
203
|
+
url: endpoint,
|
|
240
204
|
timeoutSeconds,
|
|
241
205
|
signal,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
freshness
|
|
247
|
-
} : {
|
|
248
|
-
transport: runtime.transport,
|
|
249
|
-
count: resolveSearchCount(count, DEFAULT_SEARCH_COUNT),
|
|
250
|
-
country: country ?? void 0,
|
|
251
|
-
searchDomainFilter: domainFilter,
|
|
252
|
-
searchRecencyFilter: freshness,
|
|
253
|
-
searchLanguageFilter: language ? [language] : void 0,
|
|
254
|
-
searchAfterDate: dateAfter ? isoToPerplexityDate(dateAfter) : void 0,
|
|
255
|
-
searchBeforeDate: dateBefore ? isoToPerplexityDate(dateBefore) : void 0,
|
|
256
|
-
maxTokens: maxTokens ?? void 0,
|
|
257
|
-
maxTokensPerPage: maxTokensPerPage ?? void 0
|
|
206
|
+
init: {
|
|
207
|
+
method: "POST",
|
|
208
|
+
headers,
|
|
209
|
+
body: JSON.stringify(body)
|
|
258
210
|
}
|
|
211
|
+
}, async (res) => {
|
|
212
|
+
if (!res.ok) return await throwWebSearchApiError(res, label, {
|
|
213
|
+
headers,
|
|
214
|
+
signal
|
|
215
|
+
});
|
|
216
|
+
if (structured) return ((await readProviderJsonResponse(res, label)).results ?? []).slice(0, searchCount).map((entry) => ({
|
|
217
|
+
title: entry.title ? wrapWebContent(entry.title, "web_search") : "",
|
|
218
|
+
url: entry.url ?? "",
|
|
219
|
+
description: entry.snippet ? wrapWebContent(entry.snippet, "web_search") : "",
|
|
220
|
+
published: entry.date ?? void 0,
|
|
221
|
+
siteName: resolveSiteName(entry.url) || void 0
|
|
222
|
+
}));
|
|
223
|
+
const data = await readProviderJsonResponse(res, label);
|
|
224
|
+
const content = data.choices?.[0]?.message?.content;
|
|
225
|
+
if (typeof content !== "string" || !content.trim()) throw new Error("Perplexity search returned no final answer. Retry the query or choose another search provider.");
|
|
226
|
+
return {
|
|
227
|
+
content,
|
|
228
|
+
citations: extractPerplexityCitations(data)
|
|
229
|
+
};
|
|
259
230
|
});
|
|
260
231
|
const resultFields = Array.isArray(result) ? { results: result } : {
|
|
261
232
|
content: wrapWebContent(result.content, "web_search"),
|
|
@@ -266,12 +237,7 @@ async function executePerplexitySearch(args, searchConfig, signal) {
|
|
|
266
237
|
provider: "perplexity",
|
|
267
238
|
...Array.isArray(result) ? { count: result.length } : { model: runtime.model },
|
|
268
239
|
tookMs: Date.now() - start,
|
|
269
|
-
externalContent:
|
|
270
|
-
untrusted: true,
|
|
271
|
-
source: "web_search",
|
|
272
|
-
provider: "perplexity",
|
|
273
|
-
wrapped: true
|
|
274
|
-
},
|
|
240
|
+
externalContent: externalContentStamp("perplexity"),
|
|
275
241
|
...resultFields
|
|
276
242
|
};
|
|
277
243
|
signal?.throwIfAborted();
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"entries":[{"output":"index.js","source":"extensions/perplexity/index.ts"},{"output":"web-search-contract-api.js","source":"extensions/perplexity/web-search-contract-api.ts"},{"output":"web-search-provider.js","source":"extensions/perplexity/web-search-provider.ts"}],"chunks":[{"output":".setup/perplexity-web-search-provider-RWOL37q-.mjs","sha256":"2b5c111ff20d7acb33cbf9172efc2eb17a7675712a8a6b8dc04105421fd6eb84","facadeSource":null,"sources":["extensions/perplexity/src/perplexity-web-search-provider.shared.ts","extensions/perplexity/src/perplexity-web-search-provider.ts"]},{"output":".setup/perplexity-web-search-provider.runtime-Cz7e5C5L.mjs","sha256":"c571831c9165113b74db6d62d3ae7be9a6012167a2d5a0c99759c9b3511c855b","facadeSource":"extensions/perplexity/src/perplexity-web-search-provider.runtime.ts","sources":["extensions/perplexity/src/perplexity-web-search-provider.runtime.ts"]},{"output":"index.js","sha256":"dbd5983ae6e9657bdb0ca5861fb966edaa635a1e890144b03a17a5a761cc57bf","facadeSource":"extensions/perplexity/index.ts","sources":["extensions/perplexity/index.ts"]},{"output":"web-search-contract-api.js","sha256":"bc0b4f14a00f3af3c642c6bc35a55041d69dabe9a065945589d9bc356de80553","facadeSource":"extensions/perplexity/web-search-contract-api.ts","sources":[]},{"output":"web-search-provider.js","sha256":"05d98bdb8cc7a542d081283b7f6e01b647de64c5a68133ae6c4b6cb3c1501672","facadeSource":"extensions/perplexity/web-search-provider.ts","sources":[]}],"unrenderedSources":["extensions/perplexity/web-search-contract-api.ts","extensions/perplexity/web-search-provider.ts"]}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createPerplexityWebSearchProvider } from "./.setup/perplexity-web-search-provider-
|
|
1
|
+
import { t as createPerplexityWebSearchProvider } from "./.setup/perplexity-web-search-provider-RWOL37q-.mjs";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
3
|
//#region extensions/perplexity/index.ts
|
|
4
4
|
var perplexity_default = definePluginEntry({
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
export { t as createPerplexityWebSearchProvider } from "./.setup/perplexity-web-search-provider-RWOL37q-.mjs";
|
|
2
2
|
import "./web-search-provider.js";
|
|
3
|
-
export { createPerplexityWebSearchProvider };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export { createPerplexityWebSearchProvider };
|
|
1
|
+
export { t as createPerplexityWebSearchProvider } from "./.setup/perplexity-web-search-provider-RWOL37q-.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/perplexity-plugin",
|
|
3
|
-
"version": "2026.11.
|
|
3
|
+
"version": "2026.11.5-beta.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.11.
|
|
21
|
+
"pluginApi": ">=2026.11.5-beta.2"
|
|
22
22
|
},
|
|
23
23
|
"build": {
|
|
24
|
-
"openclawVersion": "2026.11.
|
|
24
|
+
"openclawVersion": "2026.11.5-beta.2",
|
|
25
25
|
"bundledDist": false
|
|
26
26
|
},
|
|
27
27
|
"release": {
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"assets/activity.svg"
|
|
41
41
|
],
|
|
42
42
|
"peerDependencies": {
|
|
43
|
-
"openclaw": ">=2026.11.
|
|
43
|
+
"openclaw": ">=2026.11.5-beta.2"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|
|
46
46
|
"openclaw": {
|