mirror of
https://github.com/moltbot/moltbot.git
synced 2026-04-26 16:06:16 +00:00
refactor: move plugin setup and memory capabilities to registries
This commit is contained in:
58
extensions/browser/setup-api.ts
Normal file
58
extensions/browser/setup-api.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
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;
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user