mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-07 18:03:51 +02:00
59 lines
1.7 KiB
TypeScript
59 lines
1.7 KiB
TypeScript
import type { OpenClawConfig } from "openclaw/plugin-sdk/plugin-entry";
|
|
import { definePluginEntry } from "openclaw/plugin-sdk/plugin-entry";
|
|
|
|
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
}
|
|
|
|
function listContainsBrowser(value: unknown): boolean {
|
|
return (
|
|
Array.isArray(value) &&
|
|
value.some((entry) => typeof entry === "string" && entry.trim().toLowerCase() === "browser")
|
|
);
|
|
}
|
|
|
|
function toolPolicyReferencesBrowser(value: unknown): boolean {
|
|
return (
|
|
isRecord(value) && (listContainsBrowser(value.allow) || listContainsBrowser(value.alsoAllow))
|
|
);
|
|
}
|
|
|
|
function hasBrowserToolReference(config: OpenClawConfig): boolean {
|
|
if (toolPolicyReferencesBrowser(config.tools)) {
|
|
return true;
|
|
}
|
|
const agentList = config.agents?.list;
|
|
return Array.isArray(agentList)
|
|
? agentList.some((entry) => isRecord(entry) && toolPolicyReferencesBrowser(entry.tools))
|
|
: false;
|
|
}
|
|
|
|
export default definePluginEntry({
|
|
id: "browser",
|
|
name: "Browser Setup",
|
|
description: "Lightweight Browser setup hooks",
|
|
register(api) {
|
|
api.registerAutoEnableProbe(({ config }) => {
|
|
if (
|
|
config.browser?.enabled === false ||
|
|
config.plugins?.entries?.browser?.enabled === false
|
|
) {
|
|
return null;
|
|
}
|
|
if (Object.prototype.hasOwnProperty.call(config, "browser")) {
|
|
return "browser configured";
|
|
}
|
|
if (
|
|
config.plugins?.entries &&
|
|
Object.prototype.hasOwnProperty.call(config.plugins.entries, "browser")
|
|
) {
|
|
return "browser plugin configured";
|
|
}
|
|
if (hasBrowserToolReference(config)) {
|
|
return "browser tool referenced";
|
|
}
|
|
return null;
|
|
});
|
|
},
|
|
});
|