Skip to content

Commit f5e1fe9

Browse files
committed
refactor: share firecrawl web search metadata
1 parent e9d4929 commit f5e1fe9

3 files changed

Lines changed: 50 additions & 76 deletions

File tree

extensions/firecrawl/src/firecrawl-search-provider.ts

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { readPositiveIntegerParam } from "openclaw/plugin-sdk/param-readers";
2-
import {
3-
createWebSearchProviderContractFields,
4-
type WebSearchProviderPlugin,
5-
} from "openclaw/plugin-sdk/provider-web-search-contract";
6-
7-
const FIRECRAWL_CREDENTIAL_PATH = "plugins.entries.firecrawl.config.webSearch.apiKey";
8-
const FIRECRAWL_FETCH_CREDENTIAL_PATH = "plugins.entries.firecrawl.config.webFetch.apiKey";
2+
import { type WebSearchProviderPlugin } from "openclaw/plugin-sdk/provider-web-search-contract";
3+
import { buildFirecrawlWebSearchProviderBase } from "../web-search-shared.js";
94

105
type FirecrawlClientModule = typeof import("./firecrawl-client.js");
116

@@ -16,20 +11,6 @@ function loadFirecrawlClientModule(): Promise<FirecrawlClientModule> {
1611
return firecrawlClientModulePromise;
1712
}
1813

19-
function getConfiguredFetchCredentialFallback(config?: {
20-
plugins?: { entries?: { firecrawl?: { config?: unknown } } };
21-
}) {
22-
const apiKey = (
23-
config?.plugins?.entries?.firecrawl?.config as { webFetch?: { apiKey?: unknown } } | undefined
24-
)?.webFetch?.apiKey;
25-
return apiKey === undefined
26-
? undefined
27-
: {
28-
path: FIRECRAWL_FETCH_CREDENTIAL_PATH,
29-
value: apiKey,
30-
};
31-
}
32-
3314
const GenericFirecrawlSearchSchema = {
3415
type: "object",
3516
properties: {
@@ -46,24 +27,7 @@ const GenericFirecrawlSearchSchema = {
4627

4728
export function createFirecrawlWebSearchProvider(): WebSearchProviderPlugin {
4829
return {
49-
id: "firecrawl",
50-
label: "Firecrawl Search",
51-
hint: "Structured results with optional result scraping",
52-
onboardingScopes: ["text-inference"],
53-
credentialLabel: "Firecrawl API key",
54-
envVars: ["FIRECRAWL_API_KEY"],
55-
placeholder: "fc-...",
56-
signupUrl: "https://www.firecrawl.dev/",
57-
docsUrl: "https://docs.openclaw.ai/tools/firecrawl",
58-
autoDetectOrder: 60,
59-
credentialPath: FIRECRAWL_CREDENTIAL_PATH,
60-
...createWebSearchProviderContractFields({
61-
credentialPath: FIRECRAWL_CREDENTIAL_PATH,
62-
searchCredential: { type: "scoped", scopeId: "firecrawl" },
63-
configuredCredential: { pluginId: "firecrawl" },
64-
selectionPluginId: "firecrawl",
65-
}),
66-
getConfiguredCredentialFallback: getConfiguredFetchCredentialFallback,
30+
...buildFirecrawlWebSearchProviderBase(),
6731
createTool: (ctx) => ({
6832
description:
6933
"Search the web using Firecrawl. Returns structured results with snippets from Firecrawl Search. Use firecrawl_search for Firecrawl-specific knobs like sources or categories.",
Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,9 @@
1-
import {
2-
createWebSearchProviderContractFields,
3-
type WebSearchProviderPlugin,
4-
} from "openclaw/plugin-sdk/provider-web-search-contract";
1+
import { type WebSearchProviderPlugin } from "openclaw/plugin-sdk/provider-web-search-contract";
2+
import { buildFirecrawlWebSearchProviderBase } from "./web-search-shared.js";
53

64
export function createFirecrawlWebSearchProvider(): WebSearchProviderPlugin {
7-
const credentialPath = "plugins.entries.firecrawl.config.webSearch.apiKey";
8-
const fetchCredentialPath = "plugins.entries.firecrawl.config.webFetch.apiKey";
9-
105
return {
11-
id: "firecrawl",
12-
label: "Firecrawl Search",
13-
hint: "Structured results with optional result scraping",
14-
onboardingScopes: ["text-inference"],
15-
credentialLabel: "Firecrawl API key",
16-
envVars: ["FIRECRAWL_API_KEY"],
17-
placeholder: "fc-...",
18-
signupUrl: "https://www.firecrawl.dev/",
19-
docsUrl: "https://docs.openclaw.ai/tools/firecrawl",
20-
autoDetectOrder: 60,
21-
credentialPath,
22-
...createWebSearchProviderContractFields({
23-
credentialPath,
24-
searchCredential: { type: "scoped", scopeId: "firecrawl" },
25-
configuredCredential: { pluginId: "firecrawl" },
26-
selectionPluginId: "firecrawl",
27-
}),
28-
getConfiguredCredentialFallback: (config) => {
29-
const apiKey = (
30-
config?.plugins?.entries?.firecrawl?.config as
31-
| { webFetch?: { apiKey?: unknown } }
32-
| undefined
33-
)?.webFetch?.apiKey;
34-
return apiKey === undefined
35-
? undefined
36-
: {
37-
path: fetchCredentialPath,
38-
value: apiKey,
39-
};
40-
},
6+
...buildFirecrawlWebSearchProviderBase(),
417
createTool: () => null,
428
};
439
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import {
2+
createWebSearchProviderContractFields,
3+
type WebSearchProviderPlugin,
4+
} from "openclaw/plugin-sdk/provider-web-search-contract";
5+
6+
export const FIRECRAWL_CREDENTIAL_PATH = "plugins.entries.firecrawl.config.webSearch.apiKey";
7+
export const FIRECRAWL_FETCH_CREDENTIAL_PATH = "plugins.entries.firecrawl.config.webFetch.apiKey";
8+
9+
export function getConfiguredFirecrawlFetchCredentialFallback(config?: {
10+
plugins?: { entries?: { firecrawl?: { config?: unknown } } };
11+
}) {
12+
const apiKey = (
13+
config?.plugins?.entries?.firecrawl?.config as { webFetch?: { apiKey?: unknown } } | undefined
14+
)?.webFetch?.apiKey;
15+
return apiKey === undefined
16+
? undefined
17+
: {
18+
path: FIRECRAWL_FETCH_CREDENTIAL_PATH,
19+
value: apiKey,
20+
};
21+
}
22+
23+
export function buildFirecrawlWebSearchProviderBase(): Omit<WebSearchProviderPlugin, "createTool"> {
24+
return {
25+
id: "firecrawl",
26+
label: "Firecrawl Search",
27+
hint: "Structured results with optional result scraping",
28+
onboardingScopes: ["text-inference"],
29+
credentialLabel: "Firecrawl API key",
30+
envVars: ["FIRECRAWL_API_KEY"],
31+
placeholder: "fc-...",
32+
signupUrl: "https://www.firecrawl.dev/",
33+
docsUrl: "https://docs.openclaw.ai/tools/firecrawl",
34+
autoDetectOrder: 60,
35+
credentialPath: FIRECRAWL_CREDENTIAL_PATH,
36+
...createWebSearchProviderContractFields({
37+
credentialPath: FIRECRAWL_CREDENTIAL_PATH,
38+
searchCredential: { type: "scoped", scopeId: "firecrawl" },
39+
configuredCredential: { pluginId: "firecrawl" },
40+
selectionPluginId: "firecrawl",
41+
}),
42+
getConfiguredCredentialFallback: getConfiguredFirecrawlFetchCredentialFallback,
43+
};
44+
}

0 commit comments

Comments
 (0)