mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 20:50:22 +00:00
perf(plugin-sdk): add web fetch contract artifacts
This commit is contained in:
65
extensions/firecrawl/web-fetch-contract-api.ts
Normal file
65
extensions/firecrawl/web-fetch-contract-api.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import {
|
||||
enablePluginInConfig,
|
||||
type WebFetchProviderPlugin,
|
||||
} from "openclaw/plugin-sdk/provider-web-fetch-contract";
|
||||
|
||||
function ensureRecord(target: Record<string, unknown>, key: string): Record<string, unknown> {
|
||||
const current = target[key];
|
||||
if (current && typeof current === "object" && !Array.isArray(current)) {
|
||||
return current as Record<string, unknown>;
|
||||
}
|
||||
const next: Record<string, unknown> = {};
|
||||
target[key] = next;
|
||||
return next;
|
||||
}
|
||||
|
||||
export function createFirecrawlWebFetchProvider(): WebFetchProviderPlugin {
|
||||
return {
|
||||
id: "firecrawl",
|
||||
label: "Firecrawl",
|
||||
hint: "Fetch pages with Firecrawl for JS-heavy or bot-protected sites.",
|
||||
envVars: ["FIRECRAWL_API_KEY"],
|
||||
placeholder: "fc-...",
|
||||
signupUrl: "https://www.firecrawl.dev/",
|
||||
docsUrl: "https://docs.firecrawl.dev",
|
||||
autoDetectOrder: 50,
|
||||
credentialPath: "plugins.entries.firecrawl.config.webFetch.apiKey",
|
||||
inactiveSecretPaths: [
|
||||
"plugins.entries.firecrawl.config.webFetch.apiKey",
|
||||
"tools.web.fetch.firecrawl.apiKey",
|
||||
],
|
||||
getCredentialValue: (fetchConfig) => {
|
||||
if (!fetchConfig || typeof fetchConfig !== "object") {
|
||||
return undefined;
|
||||
}
|
||||
const legacy = fetchConfig.firecrawl;
|
||||
if (!legacy || typeof legacy !== "object" || Array.isArray(legacy)) {
|
||||
return undefined;
|
||||
}
|
||||
if ((legacy as { enabled?: boolean }).enabled === false) {
|
||||
return undefined;
|
||||
}
|
||||
return (legacy as { apiKey?: unknown }).apiKey;
|
||||
},
|
||||
setCredentialValue: (fetchConfigTarget, value) => {
|
||||
const firecrawl = ensureRecord(fetchConfigTarget, "firecrawl");
|
||||
firecrawl.apiKey = value;
|
||||
},
|
||||
getConfiguredCredentialValue: (config) =>
|
||||
(
|
||||
config?.plugins?.entries?.firecrawl?.config as
|
||||
| { webFetch?: { apiKey?: unknown } }
|
||||
| undefined
|
||||
)?.webFetch?.apiKey,
|
||||
setConfiguredCredentialValue: (configTarget, value) => {
|
||||
const plugins = ensureRecord(configTarget as Record<string, unknown>, "plugins");
|
||||
const entries = ensureRecord(plugins, "entries");
|
||||
const firecrawlEntry = ensureRecord(entries, "firecrawl");
|
||||
const pluginConfig = ensureRecord(firecrawlEntry, "config");
|
||||
const webFetch = ensureRecord(pluginConfig, "webFetch");
|
||||
webFetch.apiKey = value;
|
||||
},
|
||||
applySelectionConfig: (config) => enablePluginInConfig(config, "firecrawl").config,
|
||||
createTool: () => null,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user