@openclaw/parallel-plugin 2026.10.10-beta.5 → 2026.11.5-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/.setup/{parallel-free-web-search-provider-beCN4WUk.mjs → parallel-free-web-search-provider-DnVb3-FA.mjs} +23 -33
- package/dist/.setup/parallel-free-web-search-provider.runtime-CMXl-P9_.mjs +163 -0
- package/dist/.setup/{parallel-search-normalize-CEpdeSGa.mjs → parallel-search-normalize-BrENFe3e.mjs} +45 -58
- package/dist/.setup/{parallel-web-search-provider.runtime-BwODKe5v.mjs → parallel-web-search-provider.runtime-DBqbm_5E.mjs} +23 -30
- package/dist/.source-module-urls/27482ad366c62469825181c2e46191eaffa65a05c60872aec27402a3a0f3f87c.json +1 -1
- package/dist/index.js +2 -3
- package/dist/web-search-contract-api.js +1 -1
- package/dist/web-search-provider.js +1 -1
- package/package.json +4 -4
- package/dist/.setup/parallel-free-web-search-provider.runtime-D3QNHPgE.mjs +0 -190
|
@@ -1,32 +1,6 @@
|
|
|
1
1
|
import { createLazyRuntimeModule } from "openclaw/plugin-sdk/lazy-runtime";
|
|
2
2
|
import { createWebSearchProviderContractFields } from "openclaw/plugin-sdk/provider-web-search-contract";
|
|
3
|
-
|
|
4
|
-
const PARALLEL_FREE_ONBOARDING_SCOPES = ["text-inference"];
|
|
5
|
-
function createParallelFreeWebSearchProviderBase() {
|
|
6
|
-
return {
|
|
7
|
-
id: "parallel-free",
|
|
8
|
-
label: "Parallel Search (Free)",
|
|
9
|
-
hint: "Free web search via Parallel's hosted Search MCP — no API key required",
|
|
10
|
-
configPath: null,
|
|
11
|
-
onboardingScopes: [...PARALLEL_FREE_ONBOARDING_SCOPES],
|
|
12
|
-
requiresCredential: false,
|
|
13
|
-
envVars: [],
|
|
14
|
-
placeholder: "(no key needed)",
|
|
15
|
-
signupUrl: "https://parallel.ai",
|
|
16
|
-
docsUrl: "https://docs.openclaw.ai/tools/parallel-search",
|
|
17
|
-
credentialPath: "",
|
|
18
|
-
...createWebSearchProviderContractFields({
|
|
19
|
-
credentialPath: "",
|
|
20
|
-
searchCredential: {
|
|
21
|
-
type: "scoped",
|
|
22
|
-
scopeId: "parallel-free"
|
|
23
|
-
},
|
|
24
|
-
selectionPluginId: "parallel"
|
|
25
|
-
})
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region extensions/parallel/src/parallel-web-search-provider.ts
|
|
3
|
+
// extensions/parallel/src/parallel-web-search-provider.ts
|
|
30
4
|
const PARALLEL_CREDENTIAL_PATH = "plugins.entries.parallel.config.webSearch.apiKey";
|
|
31
5
|
const PARALLEL_MAX_SEARCH_COUNT = 40;
|
|
32
6
|
const PARALLEL_MAX_SEARCH_QUERIES = 5;
|
|
@@ -34,7 +8,7 @@ const PARALLEL_MAX_SEARCH_QUERY_CHARS = 200;
|
|
|
34
8
|
const PARALLEL_MAX_OBJECTIVE_CHARS = 5e3;
|
|
35
9
|
const PARALLEL_MAX_SESSION_ID_CHARS = 1e3;
|
|
36
10
|
const PARALLEL_MAX_CLIENT_MODEL_CHARS = 100;
|
|
37
|
-
const loadParallelWebSearchRuntime = createLazyRuntimeModule(() => import("./parallel-web-search-provider.runtime-
|
|
11
|
+
const loadParallelWebSearchRuntime = createLazyRuntimeModule(() => import("./parallel-web-search-provider.runtime-DBqbm_5E.mjs"));
|
|
38
12
|
const ParallelSearchSchema = {
|
|
39
13
|
type: "object",
|
|
40
14
|
properties: {
|
|
@@ -106,8 +80,7 @@ function createParallelWebSearchProvider() {
|
|
|
106
80
|
})
|
|
107
81
|
};
|
|
108
82
|
}
|
|
109
|
-
|
|
110
|
-
//#region extensions/parallel/src/parallel-free-web-search-provider.ts
|
|
83
|
+
// extensions/parallel/src/parallel-free-web-search-provider.ts
|
|
111
84
|
const ParallelFreeSearchSchema = {
|
|
112
85
|
...ParallelSearchSchema,
|
|
113
86
|
properties: {
|
|
@@ -118,10 +91,28 @@ const ParallelFreeSearchSchema = {
|
|
|
118
91
|
}
|
|
119
92
|
}
|
|
120
93
|
};
|
|
121
|
-
const loadParallelFreeWebSearchRuntime = createLazyRuntimeModule(() => import("./parallel-free-web-search-provider.runtime-
|
|
94
|
+
const loadParallelFreeWebSearchRuntime = createLazyRuntimeModule(() => import("./parallel-free-web-search-provider.runtime-CMXl-P9_.mjs"));
|
|
122
95
|
function createParallelFreeWebSearchProvider() {
|
|
123
96
|
return {
|
|
124
|
-
|
|
97
|
+
id: "parallel-free",
|
|
98
|
+
label: "Parallel Search (Free)",
|
|
99
|
+
hint: "Free web search via Parallel's hosted Search MCP — no API key required",
|
|
100
|
+
configPath: null,
|
|
101
|
+
onboardingScopes: ["text-inference"],
|
|
102
|
+
requiresCredential: false,
|
|
103
|
+
envVars: [],
|
|
104
|
+
placeholder: "(no key needed)",
|
|
105
|
+
signupUrl: "https://parallel.ai",
|
|
106
|
+
docsUrl: "https://docs.openclaw.ai/tools/parallel-search",
|
|
107
|
+
credentialPath: "",
|
|
108
|
+
...createWebSearchProviderContractFields({
|
|
109
|
+
credentialPath: "",
|
|
110
|
+
searchCredential: {
|
|
111
|
+
type: "scoped",
|
|
112
|
+
scopeId: "parallel-free"
|
|
113
|
+
},
|
|
114
|
+
selectionPluginId: "parallel"
|
|
115
|
+
}),
|
|
125
116
|
createTool: (ctx) => ({
|
|
126
117
|
description: "Search the web using Parallel's free Search MCP (no API key). Returns ranked, LLM-optimized dense excerpts from web sources. Pass an `objective` describing the underlying question along with 2-3 short keyword `search_queries` (Parallel's recommended pairing). For multi-step research, thread the prior result's `sessionId` back in as `session_id` to keep Parallel's context grouped.",
|
|
127
118
|
parameters: ParallelFreeSearchSchema,
|
|
@@ -132,5 +123,4 @@ function createParallelFreeWebSearchProvider() {
|
|
|
132
123
|
})
|
|
133
124
|
};
|
|
134
125
|
}
|
|
135
|
-
//#endregion
|
|
136
126
|
export { createParallelWebSearchProvider as n, createParallelFreeWebSearchProvider as t };
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { t as executeParallelSearchRequest } from "./parallel-search-normalize-BrENFe3e.mjs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { randomUUID } from "node:crypto";
|
|
4
|
+
import { readPluginPackageVersion } from "openclaw/plugin-sdk/extension-shared";
|
|
5
|
+
import { ProviderHttpError, readProviderTextResponse, readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
|
|
6
|
+
import { mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig, withTrustedWebSearchEndpoint } from "openclaw/plugin-sdk/provider-web-search";
|
|
7
|
+
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
8
|
+
import { safeParseJson, truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
9
|
+
// extensions/parallel/src/parallel-free-web-search-provider.runtime.ts
|
|
10
|
+
const PARALLEL_MCP_SEARCH_URL = "https://search.parallel.ai/mcp";
|
|
11
|
+
const MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
12
|
+
const PARALLEL_MCP_ERROR_BODY_LIMIT_BYTES = 8192;
|
|
13
|
+
const require = createRequire(import.meta.url);
|
|
14
|
+
const PLUGIN_VERSION = readPluginPackageVersion({ require });
|
|
15
|
+
const USER_AGENT = `openclaw-parallel/${PLUGIN_VERSION} (${process.platform})`;
|
|
16
|
+
/**
|
|
17
|
+
* Select the first result/error matching requestId from a fully read JSON or SSE body,
|
|
18
|
+
* falling back to the last result/error when no id matches. JSON batches are flattened
|
|
19
|
+
* one level; multiline SSE data fields are joined and malformed events are skipped.
|
|
20
|
+
*/
|
|
21
|
+
function selectMcpEnvelope(text, requestId) {
|
|
22
|
+
let envelope = {};
|
|
23
|
+
const selectMessage = (message) => {
|
|
24
|
+
if (!isRecord(message) || !("result" in message || "error" in message)) return false;
|
|
25
|
+
envelope = message;
|
|
26
|
+
return message.id === requestId;
|
|
27
|
+
};
|
|
28
|
+
const selectPayload = (json) => {
|
|
29
|
+
const payload = safeParseJson(json);
|
|
30
|
+
return Array.isArray(payload) ? payload.some(selectMessage) : selectMessage(payload);
|
|
31
|
+
};
|
|
32
|
+
const body = text.trim();
|
|
33
|
+
if (!body) return envelope;
|
|
34
|
+
if (body.startsWith("{") || body.startsWith("[")) {
|
|
35
|
+
selectPayload(body);
|
|
36
|
+
return envelope;
|
|
37
|
+
}
|
|
38
|
+
let dataLines = [];
|
|
39
|
+
const flush = () => {
|
|
40
|
+
if (dataLines.length === 0) return false;
|
|
41
|
+
const matched = selectPayload(dataLines.join("\n"));
|
|
42
|
+
dataLines = [];
|
|
43
|
+
return matched;
|
|
44
|
+
};
|
|
45
|
+
for (const raw of body.split("\n")) {
|
|
46
|
+
const line = raw.replace(/\r$/, "");
|
|
47
|
+
if (line.startsWith("data:")) dataLines.push(line.slice(5).replace(/^ /, ""));
|
|
48
|
+
else if (line.trim() === "" && flush()) return envelope;
|
|
49
|
+
}
|
|
50
|
+
flush();
|
|
51
|
+
return envelope;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Extract the tool result payload from a `tools/call` envelope.
|
|
55
|
+
*
|
|
56
|
+
* Prefers `structuredContent` (authoritative machine-readable form); otherwise
|
|
57
|
+
* scans text blocks for the first JSON-parseable one. Throws on a JSON-RPC
|
|
58
|
+
* error or a tool-level `isError`.
|
|
59
|
+
*/
|
|
60
|
+
function extractMcpToolPayload(envelope) {
|
|
61
|
+
if ("error" in envelope) throw new Error(`Parallel MCP error: ${truncateUtf16Safe(JSON.stringify(envelope.error), 500)}`);
|
|
62
|
+
const result = isRecord(envelope.result) ? envelope.result : {};
|
|
63
|
+
if (result.isError) throw new Error(`Parallel MCP tool error: ${truncateUtf16Safe(JSON.stringify(result), 500)}`);
|
|
64
|
+
if (isRecord(result.structuredContent)) return result.structuredContent;
|
|
65
|
+
const content = Array.isArray(result.content) ? result.content : [];
|
|
66
|
+
for (const block of content) if (isRecord(block) && block.type === "text" && typeof block.text === "string" && block.text) {
|
|
67
|
+
const parsed = safeParseJson(block.text);
|
|
68
|
+
if (isRecord(parsed)) return parsed;
|
|
69
|
+
}
|
|
70
|
+
throw new Error(`Parallel MCP returned no parseable content: ${truncateUtf16Safe(JSON.stringify(result), 500)}`);
|
|
71
|
+
}
|
|
72
|
+
async function executeParallelFreeWebSearchProviderTool(ctx, args, signal) {
|
|
73
|
+
signal?.throwIfAborted();
|
|
74
|
+
const searchConfig = mergeScopedSearchConfig(ctx.searchConfig, "parallel-free", resolveProviderWebSearchPluginConfig(ctx.config, "parallel-free"));
|
|
75
|
+
return executeParallelSearchRequest({
|
|
76
|
+
provider: "parallel-free",
|
|
77
|
+
endpoint: PARALLEL_MCP_SEARCH_URL,
|
|
78
|
+
args,
|
|
79
|
+
searchConfig,
|
|
80
|
+
search: async (request, timeoutSeconds) => {
|
|
81
|
+
const postMcp = (params) => withTrustedWebSearchEndpoint({
|
|
82
|
+
url: PARALLEL_MCP_SEARCH_URL,
|
|
83
|
+
timeoutSeconds,
|
|
84
|
+
signal,
|
|
85
|
+
init: {
|
|
86
|
+
method: "POST",
|
|
87
|
+
headers: {
|
|
88
|
+
"Content-Type": "application/json",
|
|
89
|
+
"User-Agent": USER_AGENT,
|
|
90
|
+
Accept: "application/json, text/event-stream",
|
|
91
|
+
...params.sessionId ? { "Mcp-Session-Id": params.sessionId } : {},
|
|
92
|
+
...params.protocolVersion ? { "MCP-Protocol-Version": params.protocolVersion } : {}
|
|
93
|
+
},
|
|
94
|
+
body: JSON.stringify(params.body)
|
|
95
|
+
}
|
|
96
|
+
}, async (response) => {
|
|
97
|
+
if (!response.ok) {
|
|
98
|
+
const detail = await readResponseTextLimited(response, PARALLEL_MCP_ERROR_BODY_LIMIT_BYTES);
|
|
99
|
+
throw new ProviderHttpError(`Parallel MCP ${params.body.method} failed (${response.status}): ${detail || response.statusText}`, { status: response.status });
|
|
100
|
+
}
|
|
101
|
+
return {
|
|
102
|
+
text: await readProviderTextResponse(response, "Parallel MCP"),
|
|
103
|
+
sessionIdHeader: response.headers.get("mcp-session-id")
|
|
104
|
+
};
|
|
105
|
+
});
|
|
106
|
+
const sessionId = request.sessionId?.trim() || randomUUID();
|
|
107
|
+
const searchArgs = {
|
|
108
|
+
objective: request.objective ?? request.searchQueries.join(" "),
|
|
109
|
+
search_queries: request.searchQueries,
|
|
110
|
+
session_id: sessionId
|
|
111
|
+
};
|
|
112
|
+
if (request.clientModel) searchArgs.model_name = request.clientModel;
|
|
113
|
+
const initId = randomUUID();
|
|
114
|
+
const init = await postMcp({ body: {
|
|
115
|
+
jsonrpc: "2.0",
|
|
116
|
+
id: initId,
|
|
117
|
+
method: "initialize",
|
|
118
|
+
params: {
|
|
119
|
+
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
120
|
+
capabilities: {},
|
|
121
|
+
clientInfo: {
|
|
122
|
+
name: "openclaw-parallel",
|
|
123
|
+
version: PLUGIN_VERSION
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
} });
|
|
127
|
+
const mcpSessionId = init.sessionIdHeader ?? void 0;
|
|
128
|
+
const initEnvelope = selectMcpEnvelope(init.text, initId);
|
|
129
|
+
const negotiatedVersion = (isRecord(initEnvelope.result) && typeof initEnvelope.result.protocolVersion === "string" ? initEnvelope.result.protocolVersion : void 0) ?? MCP_PROTOCOL_VERSION;
|
|
130
|
+
await postMcp({
|
|
131
|
+
body: {
|
|
132
|
+
jsonrpc: "2.0",
|
|
133
|
+
method: "notifications/initialized"
|
|
134
|
+
},
|
|
135
|
+
sessionId: mcpSessionId,
|
|
136
|
+
protocolVersion: negotiatedVersion
|
|
137
|
+
});
|
|
138
|
+
const callId = randomUUID();
|
|
139
|
+
const payload = extractMcpToolPayload(selectMcpEnvelope((await postMcp({
|
|
140
|
+
body: {
|
|
141
|
+
jsonrpc: "2.0",
|
|
142
|
+
id: callId,
|
|
143
|
+
method: "tools/call",
|
|
144
|
+
params: {
|
|
145
|
+
name: "web_search",
|
|
146
|
+
arguments: searchArgs
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
sessionId: mcpSessionId,
|
|
150
|
+
protocolVersion: negotiatedVersion
|
|
151
|
+
})).text, callId));
|
|
152
|
+
const results = (Array.isArray(payload.results) ? payload.results : []).slice(0, Math.max(request.count, 1));
|
|
153
|
+
return {
|
|
154
|
+
search_id: typeof payload.search_id === "string" ? payload.search_id : void 0,
|
|
155
|
+
session_id: sessionId,
|
|
156
|
+
results,
|
|
157
|
+
warnings: payload.warnings,
|
|
158
|
+
usage: payload.usage
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
export { executeParallelFreeWebSearchProviderTool };
|
|
@@ -1,55 +1,76 @@
|
|
|
1
|
-
import "
|
|
2
|
-
import { DEFAULT_SEARCH_COUNT, buildSearchCacheKey, readCachedSearchPayload, readPositiveIntegerParam, readStringArrayParam, readStringParam, resolveSearchCacheTtlMs, resolveSearchTimeoutSeconds, resolveSiteName, wrapWebContent, writeCachedSearchPayload } from "openclaw/plugin-sdk/provider-web-search";
|
|
1
|
+
import { DEFAULT_SEARCH_COUNT, buildSearchCacheKey, externalContentStamp, readCachedSearchPayload, readPositiveIntegerParam, readStringArrayParam, readStringParam, resolveSearchCacheTtlMs, resolveSearchTimeoutSeconds, resolveSiteName, wrapWebContent, writeCachedSearchPayload } from "openclaw/plugin-sdk/provider-web-search";
|
|
3
2
|
import { asOptionalObjectRecord, filterStringEntries, isRecord, normalizeBoundedOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
4
3
|
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
4
|
+
import { sha256Hex } from "openclaw/plugin-sdk/node-crypto-runtime";
|
|
5
5
|
import { resolveIntegerOption } from "openclaw/plugin-sdk/number-runtime";
|
|
6
|
-
|
|
6
|
+
// extensions/parallel/src/parallel-search-normalize.ts
|
|
7
7
|
const PARALLEL_MAX_SEARCH_COUNT = 40;
|
|
8
8
|
const PARALLEL_MAX_SEARCH_QUERY_CHARS = 200;
|
|
9
9
|
const PARALLEL_MAX_OBJECTIVE_CHARS = 5e3;
|
|
10
10
|
const PARALLEL_MAX_SEARCH_QUERIES = 5;
|
|
11
11
|
const PARALLEL_SESSION_ID_MAX_LENGTH = 1e3;
|
|
12
12
|
const PARALLEL_CLIENT_MODEL_MAX_LENGTH = 100;
|
|
13
|
-
function
|
|
13
|
+
async function executeParallelSearchRequest(params) {
|
|
14
|
+
const { args } = params;
|
|
15
|
+
const configuredCount = params.searchConfig?.maxResults;
|
|
14
16
|
const objective = truncateUtf16Safe(readStringParam(args, "objective") ?? "", PARALLEL_MAX_OBJECTIVE_CHARS) || void 0;
|
|
15
17
|
const cliQuery = truncateUtf16Safe(readStringParam(args, "query") ?? "", PARALLEL_MAX_OBJECTIVE_CHARS) || void 0;
|
|
16
18
|
let searchQueries = normalizeParallelSearchQueries(readStringArrayParam(args, "search_queries"));
|
|
17
19
|
if (searchQueries.length === 0 && cliQuery) searchQueries = normalizeParallelSearchQueries([cliQuery]);
|
|
18
|
-
if (searchQueries.length === 0) return {
|
|
19
|
-
|
|
20
|
+
if (searchQueries.length === 0) return {
|
|
21
|
+
error: "invalid_search_queries",
|
|
22
|
+
message: "search_queries must be a non-empty array of keyword strings (max 5, max 200 chars each). See https://docs.parallel.ai/search/best-practices.",
|
|
23
|
+
docs: "https://docs.openclaw.ai/tools/parallel-search"
|
|
24
|
+
};
|
|
25
|
+
const value = readPositiveIntegerParam(args, "count", {
|
|
26
|
+
max: PARALLEL_MAX_SEARCH_COUNT,
|
|
27
|
+
message: `count must be an integer from 1 to ${PARALLEL_MAX_SEARCH_COUNT}.`
|
|
28
|
+
}) ?? (typeof configuredCount === "number" ? configuredCount : DEFAULT_SEARCH_COUNT);
|
|
29
|
+
const request = {
|
|
20
30
|
objective,
|
|
21
31
|
searchQueries,
|
|
22
|
-
count:
|
|
23
|
-
|
|
32
|
+
count: resolveIntegerOption(value, DEFAULT_SEARCH_COUNT, {
|
|
33
|
+
min: 1,
|
|
34
|
+
max: PARALLEL_MAX_SEARCH_COUNT
|
|
35
|
+
}),
|
|
36
|
+
sessionId: normalizeBoundedOptionalString(readStringParam(args, "session_id"), params.provider === "parallel" ? PARALLEL_SESSION_ID_MAX_LENGTH : 100),
|
|
24
37
|
clientModel: truncateUtf16Safe(readStringParam(args, "client_model") ?? "", PARALLEL_CLIENT_MODEL_MAX_LENGTH) || void 0
|
|
25
38
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
39
|
+
const cacheKey = buildSearchCacheKey([
|
|
40
|
+
params.provider,
|
|
41
|
+
params.apiKey ? sha256Hex(params.apiKey) : void 0,
|
|
42
|
+
JSON.stringify({
|
|
43
|
+
endpoint: params.endpoint,
|
|
44
|
+
...request
|
|
45
|
+
})
|
|
46
|
+
]);
|
|
34
47
|
const cacheTtlMs = resolveSearchCacheTtlMs(params.searchConfig);
|
|
35
48
|
const cached = readCachedSearchPayload(cacheKey, cacheTtlMs);
|
|
36
49
|
if (cached) return cached;
|
|
37
50
|
const start = Date.now();
|
|
38
51
|
const response = await params.search(request, resolveSearchTimeoutSeconds(params.searchConfig));
|
|
39
|
-
|
|
40
|
-
const
|
|
52
|
+
const count = request.count;
|
|
53
|
+
const rawResults = asOptionalObjectRecord(response)?.results;
|
|
54
|
+
const results = (Array.isArray(rawResults) ? rawResults.filter(isRecord) : []).slice(0, count).map((entry) => {
|
|
55
|
+
const title = typeof entry.title === "string" ? entry.title : "";
|
|
56
|
+
const url = typeof entry.url === "string" ? entry.url : "";
|
|
57
|
+
const published = typeof entry.publish_date === "string" && entry.publish_date ? entry.publish_date : void 0;
|
|
58
|
+
const excerpts = filterStringEntries(entry.excerpts).map((e) => wrapWebContent(e, "web_search"));
|
|
59
|
+
const description = excerpts.join("\n\n");
|
|
60
|
+
return Object.assign({
|
|
61
|
+
title: title ? wrapWebContent(title, "web_search") : "",
|
|
62
|
+
url,
|
|
63
|
+
description,
|
|
64
|
+
siteName: resolveSiteName(url) || void 0
|
|
65
|
+
}, published ? { published } : {}, excerpts.length > 0 ? { excerpts } : {});
|
|
66
|
+
});
|
|
41
67
|
const payload = {
|
|
42
68
|
...request.objective ? { objective: request.objective } : {},
|
|
43
69
|
searchQueries: request.searchQueries,
|
|
44
70
|
provider: params.provider,
|
|
45
71
|
count: results.length,
|
|
46
72
|
tookMs: Date.now() - start,
|
|
47
|
-
externalContent:
|
|
48
|
-
untrusted: true,
|
|
49
|
-
source: "web_search",
|
|
50
|
-
provider: params.provider,
|
|
51
|
-
wrapped: true
|
|
52
|
-
},
|
|
73
|
+
externalContent: externalContentStamp(params.provider),
|
|
53
74
|
results
|
|
54
75
|
};
|
|
55
76
|
if (typeof response.search_id === "string") payload.searchId = response.search_id;
|
|
@@ -61,16 +82,6 @@ async function executeParallelSearchRequest(params) {
|
|
|
61
82
|
writeCachedSearchPayload(cacheKey, cachePayload, cacheTtlMs);
|
|
62
83
|
return payload;
|
|
63
84
|
}
|
|
64
|
-
function resolveParallelSearchCount(args, configuredCount) {
|
|
65
|
-
const value = readPositiveIntegerParam(args, "count", {
|
|
66
|
-
max: PARALLEL_MAX_SEARCH_COUNT,
|
|
67
|
-
message: `count must be an integer from 1 to ${PARALLEL_MAX_SEARCH_COUNT}.`
|
|
68
|
-
}) ?? (typeof configuredCount === "number" ? configuredCount : DEFAULT_SEARCH_COUNT);
|
|
69
|
-
return resolveIntegerOption(value, DEFAULT_SEARCH_COUNT, {
|
|
70
|
-
min: 1,
|
|
71
|
-
max: PARALLEL_MAX_SEARCH_COUNT
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
85
|
function normalizeParallelSearchQueries(candidates = []) {
|
|
75
86
|
const seen = /* @__PURE__ */ new Set();
|
|
76
87
|
const out = [];
|
|
@@ -85,28 +96,4 @@ function normalizeParallelSearchQueries(candidates = []) {
|
|
|
85
96
|
}
|
|
86
97
|
return out;
|
|
87
98
|
}
|
|
88
|
-
function invalidSearchQueriesPayload() {
|
|
89
|
-
return {
|
|
90
|
-
error: "invalid_search_queries",
|
|
91
|
-
message: "search_queries must be a non-empty array of keyword strings (max 5, max 200 chars each). See https://docs.parallel.ai/search/best-practices.",
|
|
92
|
-
docs: "https://docs.openclaw.ai/tools/parallel-search"
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
function mapParallelResults(response, count) {
|
|
96
|
-
const rawResults = asOptionalObjectRecord(response)?.results;
|
|
97
|
-
return (Array.isArray(rawResults) ? rawResults.filter(isRecord) : []).slice(0, count).map((entry) => {
|
|
98
|
-
const title = typeof entry.title === "string" ? entry.title : "";
|
|
99
|
-
const url = typeof entry.url === "string" ? entry.url : "";
|
|
100
|
-
const published = typeof entry.publish_date === "string" && entry.publish_date ? entry.publish_date : void 0;
|
|
101
|
-
const excerpts = filterStringEntries(entry.excerpts).map((e) => wrapWebContent(e, "web_search"));
|
|
102
|
-
const description = excerpts.join("\n\n");
|
|
103
|
-
return Object.assign({
|
|
104
|
-
title: title ? wrapWebContent(title, "web_search") : "",
|
|
105
|
-
url,
|
|
106
|
-
description,
|
|
107
|
-
siteName: resolveSiteName(url) || void 0
|
|
108
|
-
}, published ? { published } : {}, excerpts.length > 0 ? { excerpts } : {});
|
|
109
|
-
});
|
|
110
|
-
}
|
|
111
|
-
//#endregion
|
|
112
99
|
export { executeParallelSearchRequest as t };
|
|
@@ -1,21 +1,18 @@
|
|
|
1
|
-
import { t as executeParallelSearchRequest } from "./parallel-search-normalize-
|
|
1
|
+
import { t as executeParallelSearchRequest } from "./parallel-search-normalize-BrENFe3e.mjs";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
|
-
import { mergeScopedSearchConfig, readConfiguredSecretString, readProviderEnvValue, resolveProviderWebSearchPluginConfig, withTrustedWebSearchEndpoint } from "openclaw/plugin-sdk/provider-web-search";
|
|
4
3
|
import { readPluginPackageVersion } from "openclaw/plugin-sdk/extension-shared";
|
|
5
4
|
import { ProviderHttpError, readProviderJsonResponse, readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
|
|
5
|
+
import { mergeScopedSearchConfig, readWebSearchApiKey, resolveProviderWebSearchPluginConfig, withTrustedWebSearchEndpoint } from "openclaw/plugin-sdk/provider-web-search";
|
|
6
6
|
import { asOptionalRecord, normalizeOptionalString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
7
7
|
import { redactToolPayloadText } from "openclaw/plugin-sdk/logging-core";
|
|
8
8
|
import { redactSensitiveText } from "openclaw/plugin-sdk/security-runtime";
|
|
9
|
-
|
|
9
|
+
// extensions/parallel/src/parallel-web-search-provider.runtime.ts
|
|
10
10
|
const PARALLEL_BASE_URL = "https://api.parallel.ai";
|
|
11
11
|
const PARALLEL_SEARCH_PATHNAME = "/v1/search";
|
|
12
12
|
const PARALLEL_ERROR_BODY_LIMIT_BYTES = 8192;
|
|
13
13
|
const PARALLEL_SEARCH_RESPONSE_LIMIT_BYTES = 16777216;
|
|
14
14
|
const require = createRequire(import.meta.url);
|
|
15
15
|
const USER_AGENT = `openclaw-parallel/${readPluginPackageVersion({ require })} (${process.platform})`;
|
|
16
|
-
function resolveParallelApiKey(parallel) {
|
|
17
|
-
return readConfiguredSecretString(parallel?.apiKey, "plugins.entries.parallel.config.webSearch.apiKey") ?? readProviderEnvValue(["PARALLEL_API_KEY"]);
|
|
18
|
-
}
|
|
19
16
|
function invalidBaseUrlPayload() {
|
|
20
17
|
return {
|
|
21
18
|
error: "invalid_base_url",
|
|
@@ -23,44 +20,41 @@ function invalidBaseUrlPayload() {
|
|
|
23
20
|
docs: "https://docs.openclaw.ai/tools/parallel-search"
|
|
24
21
|
};
|
|
25
22
|
}
|
|
26
|
-
function resolveParallelSearchEndpoint(parallel) {
|
|
27
|
-
const configured = normalizeOptionalString(parallel?.baseUrl);
|
|
28
|
-
if (!configured) return { endpoint: `${PARALLEL_BASE_URL}${PARALLEL_SEARCH_PATHNAME}` };
|
|
29
|
-
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(configured) && !/^https?:\/\//i.test(configured)) return invalidBaseUrlPayload();
|
|
30
|
-
const candidate = /^https?:\/\//i.test(configured) ? configured : `https://${configured}`;
|
|
31
|
-
let parsed;
|
|
32
|
-
try {
|
|
33
|
-
parsed = new URL(candidate);
|
|
34
|
-
} catch {
|
|
35
|
-
return invalidBaseUrlPayload();
|
|
36
|
-
}
|
|
37
|
-
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return invalidBaseUrlPayload();
|
|
38
|
-
const pathname = parsed.pathname.replace(/\/+$/, "");
|
|
39
|
-
parsed.pathname = pathname.endsWith(PARALLEL_SEARCH_PATHNAME) ? pathname : `${pathname}${PARALLEL_SEARCH_PATHNAME}`;
|
|
40
|
-
parsed.hash = "";
|
|
41
|
-
return { endpoint: parsed.toString() };
|
|
42
|
-
}
|
|
43
23
|
async function executeParallelWebSearchProviderTool(ctx, args, signal) {
|
|
44
24
|
const searchConfig = mergeScopedSearchConfig(ctx.searchConfig, "parallel", resolveProviderWebSearchPluginConfig(ctx.config, "parallel"));
|
|
45
25
|
const parallelConfig = asOptionalRecord(searchConfig?.parallel);
|
|
46
|
-
const apiKey =
|
|
26
|
+
const apiKey = readWebSearchApiKey(parallelConfig?.apiKey, "plugins.entries.parallel.config.webSearch.apiKey", ["PARALLEL_API_KEY"]);
|
|
47
27
|
if (!apiKey) return {
|
|
48
28
|
error: "missing_parallel_api_key",
|
|
49
29
|
message: "web_search (parallel) needs a Parallel API key. Set PARALLEL_API_KEY in the Gateway environment, or configure plugins.entries.parallel.config.webSearch.apiKey.",
|
|
50
30
|
docs: "https://docs.openclaw.ai/tools/parallel-search"
|
|
51
31
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
32
|
+
let endpoint = `${PARALLEL_BASE_URL}${PARALLEL_SEARCH_PATHNAME}`;
|
|
33
|
+
const configured = normalizeOptionalString(parallelConfig?.baseUrl);
|
|
34
|
+
if (configured) {
|
|
35
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(configured) && !/^https?:\/\//i.test(configured)) return invalidBaseUrlPayload();
|
|
36
|
+
const candidate = /^https?:\/\//i.test(configured) ? configured : `https://${configured}`;
|
|
37
|
+
let parsed;
|
|
38
|
+
try {
|
|
39
|
+
parsed = new URL(candidate);
|
|
40
|
+
} catch {
|
|
41
|
+
return invalidBaseUrlPayload();
|
|
42
|
+
}
|
|
43
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return invalidBaseUrlPayload();
|
|
44
|
+
const pathname = parsed.pathname.replace(/\/+$/, "");
|
|
45
|
+
parsed.pathname = pathname.endsWith(PARALLEL_SEARCH_PATHNAME) ? pathname : `${pathname}${PARALLEL_SEARCH_PATHNAME}`;
|
|
46
|
+
parsed.hash = "";
|
|
47
|
+
endpoint = parsed.toString();
|
|
48
|
+
}
|
|
55
49
|
return executeParallelSearchRequest({
|
|
56
50
|
provider: "parallel",
|
|
57
51
|
endpoint,
|
|
52
|
+
apiKey,
|
|
58
53
|
args,
|
|
59
54
|
searchConfig,
|
|
60
|
-
signal,
|
|
61
55
|
search: async (request, timeoutSeconds) => {
|
|
62
56
|
const body = {
|
|
63
|
-
search_queries:
|
|
57
|
+
search_queries: request.searchQueries,
|
|
64
58
|
advanced_settings: { max_results: request.count }
|
|
65
59
|
};
|
|
66
60
|
if (request.objective) body.objective = request.objective;
|
|
@@ -91,5 +85,4 @@ async function executeParallelWebSearchProviderTool(ctx, args, signal) {
|
|
|
91
85
|
}
|
|
92
86
|
});
|
|
93
87
|
}
|
|
94
|
-
//#endregion
|
|
95
88
|
export { executeParallelWebSearchProviderTool };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"entries":[{"output":"index.js","source":"extensions/parallel/index.ts"},{"output":"web-search-contract-api.js","source":"extensions/parallel/web-search-contract-api.ts"},{"output":"web-search-provider.js","source":"extensions/parallel/web-search-provider.ts"}],"chunks":[{"output":".setup/parallel-free-web-search-provider-
|
|
1
|
+
{"version":3,"entries":[{"output":"index.js","source":"extensions/parallel/index.ts"},{"output":"web-search-contract-api.js","source":"extensions/parallel/web-search-contract-api.ts"},{"output":"web-search-provider.js","source":"extensions/parallel/web-search-provider.ts"}],"chunks":[{"output":".setup/parallel-free-web-search-provider-DnVb3-FA.mjs","sha256":"50ca3c983c915340a1cccf6e3f731502f24cf8dd0bd2e77d369952e08a72349e","facadeSource":null,"sources":["extensions/parallel/src/parallel-free-web-search-provider.ts","extensions/parallel/src/parallel-web-search-provider.ts"]},{"output":".setup/parallel-free-web-search-provider.runtime-CMXl-P9_.mjs","sha256":"c0ed1a05a7c063f690172172da94a07049774d17f8cc293a826ccf1a37c6995d","facadeSource":"extensions/parallel/src/parallel-free-web-search-provider.runtime.ts","sources":["extensions/parallel/src/parallel-free-web-search-provider.runtime.ts"]},{"output":".setup/parallel-search-normalize-BrENFe3e.mjs","sha256":"75804d098e4de2319926560d0f6a8b4661dceddf9169732a617da2a1632a15b9","facadeSource":null,"sources":["extensions/parallel/src/parallel-search-normalize.ts"]},{"output":".setup/parallel-web-search-provider.runtime-DBqbm_5E.mjs","sha256":"272465c1b9afde395f13044e015d5c33e8aea59d7f6ce13457294be8dd9286a8","facadeSource":"extensions/parallel/src/parallel-web-search-provider.runtime.ts","sources":["extensions/parallel/src/parallel-web-search-provider.runtime.ts"]},{"output":"index.js","sha256":"04a8488597e26dc99fe22a9a54536d3d81c71989ba427cedc6a270a523f7ddbc","facadeSource":"extensions/parallel/index.ts","sources":["extensions/parallel/index.ts"]},{"output":"web-search-contract-api.js","sha256":"225e1be3f34f33b1373595112e615f9a2ae3043f9a6d5ad02aec98bb02c5f206","facadeSource":"extensions/parallel/web-search-contract-api.ts","sources":[]},{"output":"web-search-provider.js","sha256":"fb1bf1347039d21b505e32b11392d5d18a57d643080df9ab87caea684c9be5db","facadeSource":"extensions/parallel/web-search-provider.ts","sources":[]}],"unrenderedSources":["extensions/parallel/src/parallel-free-web-search-provider.shared.ts","extensions/parallel/web-search-contract-api.ts","extensions/parallel/web-search-provider.ts"]}
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { n as createParallelWebSearchProvider, t as createParallelFreeWebSearchProvider } from "./.setup/parallel-free-web-search-provider-
|
|
1
|
+
import { n as createParallelWebSearchProvider, t as createParallelFreeWebSearchProvider } from "./.setup/parallel-free-web-search-provider-DnVb3-FA.mjs";
|
|
2
2
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
3
|
-
|
|
3
|
+
// extensions/parallel/index.ts
|
|
4
4
|
var parallel_default = definePluginEntry({
|
|
5
5
|
id: "parallel",
|
|
6
6
|
name: "Parallel Plugin",
|
|
@@ -10,5 +10,4 @@ var parallel_default = definePluginEntry({
|
|
|
10
10
|
api.registerWebSearchProvider(createParallelWebSearchProvider());
|
|
11
11
|
}
|
|
12
12
|
});
|
|
13
|
-
//#endregion
|
|
14
13
|
export { parallel_default as default };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { t as createParallelFreeWebSearchProvider, n as createParallelWebSearchProvider } from "./.setup/parallel-free-web-search-provider-
|
|
1
|
+
export { t as createParallelFreeWebSearchProvider, n as createParallelWebSearchProvider } from "./.setup/parallel-free-web-search-provider-DnVb3-FA.mjs";
|
|
2
2
|
import "./web-search-provider.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as createParallelFreeWebSearchProvider, n as createParallelWebSearchProvider } from "./.setup/parallel-free-web-search-provider-
|
|
1
|
+
export { t as createParallelFreeWebSearchProvider, n as createParallelWebSearchProvider } from "./.setup/parallel-free-web-search-provider-DnVb3-FA.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openclaw/parallel-plugin",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.11.5-beta.1",
|
|
4
4
|
"description": "OpenClaw Parallel web search 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.11.5-beta.1"
|
|
22
22
|
},
|
|
23
23
|
"build": {
|
|
24
|
-
"openclawVersion": "2026.
|
|
24
|
+
"openclawVersion": "2026.11.5-beta.1",
|
|
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.
|
|
43
|
+
"openclaw": ">=2026.11.5-beta.1"
|
|
44
44
|
},
|
|
45
45
|
"peerDependenciesMeta": {
|
|
46
46
|
"openclaw": {
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { t as executeParallelSearchRequest } from "./parallel-search-normalize-CEpdeSGa.mjs";
|
|
2
|
-
import { createRequire } from "node:module";
|
|
3
|
-
import { mergeScopedSearchConfig, resolveProviderWebSearchPluginConfig, withTrustedWebSearchEndpoint } from "openclaw/plugin-sdk/provider-web-search";
|
|
4
|
-
import { randomUUID } from "node:crypto";
|
|
5
|
-
import { readPluginPackageVersion } from "openclaw/plugin-sdk/extension-shared";
|
|
6
|
-
import { ProviderHttpError, readProviderTextResponse, readResponseTextLimited } from "openclaw/plugin-sdk/provider-http";
|
|
7
|
-
import { isRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
8
|
-
import { truncateUtf16Safe } from "openclaw/plugin-sdk/text-utility-runtime";
|
|
9
|
-
//#region extensions/parallel/src/parallel-mcp-search.runtime.ts
|
|
10
|
-
const PARALLEL_MCP_SEARCH_URL = "https://search.parallel.ai/mcp";
|
|
11
|
-
const MCP_PROTOCOL_VERSION = "2025-06-18";
|
|
12
|
-
const MCP_TIMEOUT_SECONDS = 30;
|
|
13
|
-
const PARALLEL_MCP_ERROR_BODY_LIMIT_BYTES = 8192;
|
|
14
|
-
const require = createRequire(import.meta.url);
|
|
15
|
-
const PLUGIN_VERSION = readPluginPackageVersion({ require });
|
|
16
|
-
const USER_AGENT = `openclaw-parallel/${PLUGIN_VERSION} (${process.platform})`;
|
|
17
|
-
/**
|
|
18
|
-
* Select the first result/error matching requestId from a fully read JSON or SSE body,
|
|
19
|
-
* falling back to the last result/error when no id matches. JSON batches are flattened
|
|
20
|
-
* one level; multiline SSE data fields are joined and malformed events are skipped.
|
|
21
|
-
*/
|
|
22
|
-
function selectMcpEnvelope(text, requestId) {
|
|
23
|
-
let envelope = {};
|
|
24
|
-
const selectMessage = (message) => {
|
|
25
|
-
if (!isRecord(message) || !("result" in message || "error" in message)) return false;
|
|
26
|
-
envelope = message;
|
|
27
|
-
return message.id === requestId;
|
|
28
|
-
};
|
|
29
|
-
const selectPayload = (json) => {
|
|
30
|
-
try {
|
|
31
|
-
const payload = JSON.parse(json);
|
|
32
|
-
return Array.isArray(payload) ? payload.some(selectMessage) : selectMessage(payload);
|
|
33
|
-
} catch {
|
|
34
|
-
return false;
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
const body = text.trim();
|
|
38
|
-
if (!body) return envelope;
|
|
39
|
-
if (body.startsWith("{") || body.startsWith("[")) {
|
|
40
|
-
selectPayload(body);
|
|
41
|
-
return envelope;
|
|
42
|
-
}
|
|
43
|
-
let dataLines = [];
|
|
44
|
-
const flush = () => {
|
|
45
|
-
if (dataLines.length === 0) return false;
|
|
46
|
-
const matched = selectPayload(dataLines.join("\n"));
|
|
47
|
-
dataLines = [];
|
|
48
|
-
return matched;
|
|
49
|
-
};
|
|
50
|
-
for (const raw of body.split("\n")) {
|
|
51
|
-
const line = raw.replace(/\r$/, "");
|
|
52
|
-
if (line.startsWith("data:")) dataLines.push(line.slice(5).replace(/^ /, ""));
|
|
53
|
-
else if (line.trim() === "" && flush()) return envelope;
|
|
54
|
-
}
|
|
55
|
-
flush();
|
|
56
|
-
return envelope;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Extract the tool result payload from a `tools/call` envelope.
|
|
60
|
-
*
|
|
61
|
-
* Prefers `structuredContent` (authoritative machine-readable form); otherwise
|
|
62
|
-
* scans text blocks for the first JSON-parseable one. Throws on a JSON-RPC
|
|
63
|
-
* error or a tool-level `isError`.
|
|
64
|
-
*/
|
|
65
|
-
function extractMcpToolPayload(envelope) {
|
|
66
|
-
if ("error" in envelope) throw new Error(`Parallel MCP error: ${truncateUtf16Safe(JSON.stringify(envelope.error), 500)}`);
|
|
67
|
-
const result = isRecord(envelope.result) ? envelope.result : {};
|
|
68
|
-
if (result.isError) throw new Error(`Parallel MCP tool error: ${truncateUtf16Safe(JSON.stringify(result), 500)}`);
|
|
69
|
-
if (isRecord(result.structuredContent)) return result.structuredContent;
|
|
70
|
-
const content = Array.isArray(result.content) ? result.content : [];
|
|
71
|
-
for (const block of content) if (isRecord(block) && block.type === "text" && typeof block.text === "string" && block.text) try {
|
|
72
|
-
const parsed = JSON.parse(block.text);
|
|
73
|
-
if (isRecord(parsed)) return parsed;
|
|
74
|
-
} catch {}
|
|
75
|
-
throw new Error(`Parallel MCP returned no parseable content: ${truncateUtf16Safe(JSON.stringify(result), 500)}`);
|
|
76
|
-
}
|
|
77
|
-
async function postMcp(params) {
|
|
78
|
-
return withTrustedWebSearchEndpoint({
|
|
79
|
-
url: PARALLEL_MCP_SEARCH_URL,
|
|
80
|
-
timeoutSeconds: params.timeoutSeconds,
|
|
81
|
-
signal: params.signal,
|
|
82
|
-
init: {
|
|
83
|
-
method: "POST",
|
|
84
|
-
headers: {
|
|
85
|
-
"Content-Type": "application/json",
|
|
86
|
-
"User-Agent": USER_AGENT,
|
|
87
|
-
Accept: "application/json, text/event-stream",
|
|
88
|
-
...params.sessionId ? { "Mcp-Session-Id": params.sessionId } : {},
|
|
89
|
-
...params.protocolVersion ? { "MCP-Protocol-Version": params.protocolVersion } : {}
|
|
90
|
-
},
|
|
91
|
-
body: JSON.stringify(params.body)
|
|
92
|
-
}
|
|
93
|
-
}, async (response) => {
|
|
94
|
-
if (!response.ok) {
|
|
95
|
-
const detail = await readResponseTextLimited(response, PARALLEL_MCP_ERROR_BODY_LIMIT_BYTES);
|
|
96
|
-
throw new ProviderHttpError(`Parallel MCP ${params.body.method} failed (${response.status}): ${detail || response.statusText}`, { status: response.status });
|
|
97
|
-
}
|
|
98
|
-
return {
|
|
99
|
-
text: await readProviderTextResponse(response, "Parallel MCP"),
|
|
100
|
-
sessionIdHeader: response.headers.get("mcp-session-id")
|
|
101
|
-
};
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
async function runParallelMcpSearch(params) {
|
|
105
|
-
const sessionId = params.sessionId?.trim() || randomUUID();
|
|
106
|
-
const timeoutSeconds = params.timeoutSeconds ?? MCP_TIMEOUT_SECONDS;
|
|
107
|
-
const args = {
|
|
108
|
-
objective: params.objective ?? params.searchQueries.join(" "),
|
|
109
|
-
search_queries: [...params.searchQueries],
|
|
110
|
-
session_id: sessionId
|
|
111
|
-
};
|
|
112
|
-
if (params.modelName) args.model_name = params.modelName;
|
|
113
|
-
const initId = randomUUID();
|
|
114
|
-
const init = await postMcp({
|
|
115
|
-
timeoutSeconds,
|
|
116
|
-
signal: params.signal,
|
|
117
|
-
body: {
|
|
118
|
-
jsonrpc: "2.0",
|
|
119
|
-
id: initId,
|
|
120
|
-
method: "initialize",
|
|
121
|
-
params: {
|
|
122
|
-
protocolVersion: MCP_PROTOCOL_VERSION,
|
|
123
|
-
capabilities: {},
|
|
124
|
-
clientInfo: {
|
|
125
|
-
name: "openclaw-parallel",
|
|
126
|
-
version: PLUGIN_VERSION
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
});
|
|
131
|
-
const mcpSessionId = init.sessionIdHeader ?? void 0;
|
|
132
|
-
const initEnvelope = selectMcpEnvelope(init.text, initId);
|
|
133
|
-
const negotiatedVersion = (isRecord(initEnvelope.result) && typeof initEnvelope.result.protocolVersion === "string" ? initEnvelope.result.protocolVersion : void 0) ?? MCP_PROTOCOL_VERSION;
|
|
134
|
-
await postMcp({
|
|
135
|
-
body: {
|
|
136
|
-
jsonrpc: "2.0",
|
|
137
|
-
method: "notifications/initialized"
|
|
138
|
-
},
|
|
139
|
-
sessionId: mcpSessionId,
|
|
140
|
-
protocolVersion: negotiatedVersion,
|
|
141
|
-
timeoutSeconds,
|
|
142
|
-
signal: params.signal
|
|
143
|
-
});
|
|
144
|
-
const callId = randomUUID();
|
|
145
|
-
const payload = extractMcpToolPayload(selectMcpEnvelope((await postMcp({
|
|
146
|
-
body: {
|
|
147
|
-
jsonrpc: "2.0",
|
|
148
|
-
id: callId,
|
|
149
|
-
method: "tools/call",
|
|
150
|
-
params: {
|
|
151
|
-
name: "web_search",
|
|
152
|
-
arguments: args
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
sessionId: mcpSessionId,
|
|
156
|
-
protocolVersion: negotiatedVersion,
|
|
157
|
-
timeoutSeconds,
|
|
158
|
-
signal: params.signal
|
|
159
|
-
})).text, callId));
|
|
160
|
-
const results = (Array.isArray(payload.results) ? payload.results : []).slice(0, Math.max(params.maxResults, 1));
|
|
161
|
-
return {
|
|
162
|
-
search_id: typeof payload.search_id === "string" ? payload.search_id : void 0,
|
|
163
|
-
session_id: sessionId,
|
|
164
|
-
results,
|
|
165
|
-
warnings: payload.warnings,
|
|
166
|
-
usage: payload.usage
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
//#endregion
|
|
170
|
-
//#region extensions/parallel/src/parallel-free-web-search-provider.runtime.ts
|
|
171
|
-
async function executeParallelFreeWebSearchProviderTool(ctx, args, signal) {
|
|
172
|
-
signal?.throwIfAborted();
|
|
173
|
-
const searchConfig = mergeScopedSearchConfig(ctx.searchConfig, "parallel-free", resolveProviderWebSearchPluginConfig(ctx.config, "parallel-free"));
|
|
174
|
-
return executeParallelSearchRequest({
|
|
175
|
-
provider: "parallel-free",
|
|
176
|
-
endpoint: PARALLEL_MCP_SEARCH_URL,
|
|
177
|
-
args,
|
|
178
|
-
searchConfig,
|
|
179
|
-
signal,
|
|
180
|
-
search: ({ count, clientModel, ...request }, timeoutSeconds) => runParallelMcpSearch({
|
|
181
|
-
...request,
|
|
182
|
-
maxResults: count,
|
|
183
|
-
modelName: clientModel,
|
|
184
|
-
timeoutSeconds,
|
|
185
|
-
signal
|
|
186
|
-
})
|
|
187
|
-
});
|
|
188
|
-
}
|
|
189
|
-
//#endregion
|
|
190
|
-
export { executeParallelFreeWebSearchProviderTool };
|