mirror of https://github.com/openclaw/openclaw.git
159 lines
3.8 KiB
TypeScript
159 lines
3.8 KiB
TypeScript
import type { ChannelDock } from "../channels/dock.js";
|
|
import type { ChannelPlugin } from "../channels/plugins/types.js";
|
|
import { createExtensionHostPluginRegistry } from "../extension-host/plugin-registry.js";
|
|
import type { GatewayRequestHandlers } from "../gateway/server-methods/types.js";
|
|
import type { HookEntry } from "../hooks/types.js";
|
|
import type { PluginRuntime } from "./runtime/types.js";
|
|
import type {
|
|
OpenClawPluginCliRegistrar,
|
|
OpenClawPluginCommandDefinition,
|
|
OpenClawPluginHttpRouteAuth,
|
|
OpenClawPluginHttpRouteMatch,
|
|
OpenClawPluginHttpRouteHandler,
|
|
ProviderPlugin,
|
|
OpenClawPluginService,
|
|
OpenClawPluginToolFactory,
|
|
PluginConfigUiHint,
|
|
PluginDiagnostic,
|
|
PluginLogger,
|
|
PluginOrigin,
|
|
PluginKind,
|
|
PluginHookRegistration as TypedPluginHookRegistration,
|
|
} from "./types.js";
|
|
|
|
export type PluginToolRegistration = {
|
|
pluginId: string;
|
|
factory: OpenClawPluginToolFactory;
|
|
names: string[];
|
|
optional: boolean;
|
|
source: string;
|
|
};
|
|
|
|
export type PluginCliRegistration = {
|
|
pluginId: string;
|
|
register: OpenClawPluginCliRegistrar;
|
|
commands: string[];
|
|
source: string;
|
|
};
|
|
|
|
export type PluginHttpRouteRegistration = {
|
|
pluginId?: string;
|
|
path: string;
|
|
handler: OpenClawPluginHttpRouteHandler;
|
|
auth: OpenClawPluginHttpRouteAuth;
|
|
match: OpenClawPluginHttpRouteMatch;
|
|
source?: string;
|
|
};
|
|
|
|
export type PluginChannelRegistration = {
|
|
pluginId: string;
|
|
plugin: ChannelPlugin;
|
|
dock?: ChannelDock;
|
|
source: string;
|
|
};
|
|
|
|
export type PluginProviderRegistration = {
|
|
pluginId: string;
|
|
provider: ProviderPlugin;
|
|
source: string;
|
|
};
|
|
|
|
export type PluginHookRegistration = {
|
|
pluginId: string;
|
|
entry: HookEntry;
|
|
events: string[];
|
|
source: string;
|
|
};
|
|
|
|
export type PluginServiceRegistration = {
|
|
pluginId: string;
|
|
service: OpenClawPluginService;
|
|
source: string;
|
|
};
|
|
|
|
export type PluginCommandRegistration = {
|
|
pluginId: string;
|
|
command: OpenClawPluginCommandDefinition;
|
|
source: string;
|
|
};
|
|
|
|
export type PluginRecordLifecycleState =
|
|
| "prepared"
|
|
| "imported"
|
|
| "disabled"
|
|
| "validated"
|
|
| "registered"
|
|
| "ready"
|
|
| "error";
|
|
|
|
export type PluginRecord = {
|
|
id: string;
|
|
name: string;
|
|
version?: string;
|
|
description?: string;
|
|
kind?: PluginKind;
|
|
source: string;
|
|
origin: PluginOrigin;
|
|
workspaceDir?: string;
|
|
enabled: boolean;
|
|
status: "loaded" | "disabled" | "error";
|
|
lifecycleState?: PluginRecordLifecycleState;
|
|
error?: string;
|
|
toolNames: string[];
|
|
hookNames: string[];
|
|
channelIds: string[];
|
|
providerIds: string[];
|
|
gatewayMethods: string[];
|
|
cliCommands: string[];
|
|
services: string[];
|
|
commands: string[];
|
|
httpRoutes: number;
|
|
hookCount: number;
|
|
configSchema: boolean;
|
|
configUiHints?: Record<string, PluginConfigUiHint>;
|
|
configJsonSchema?: Record<string, unknown>;
|
|
};
|
|
|
|
export type PluginRegistry = {
|
|
plugins: PluginRecord[];
|
|
tools: PluginToolRegistration[];
|
|
hooks: PluginHookRegistration[];
|
|
typedHooks: TypedPluginHookRegistration[];
|
|
channels: PluginChannelRegistration[];
|
|
providers: PluginProviderRegistration[];
|
|
gatewayHandlers: GatewayRequestHandlers;
|
|
httpRoutes: PluginHttpRouteRegistration[];
|
|
cliRegistrars: PluginCliRegistration[];
|
|
services: PluginServiceRegistration[];
|
|
commands: PluginCommandRegistration[];
|
|
diagnostics: PluginDiagnostic[];
|
|
};
|
|
|
|
export type PluginRegistryParams = {
|
|
logger: PluginLogger;
|
|
coreGatewayHandlers?: GatewayRequestHandlers;
|
|
runtime: PluginRuntime;
|
|
};
|
|
|
|
export function createEmptyPluginRegistry(): PluginRegistry {
|
|
return {
|
|
plugins: [],
|
|
tools: [],
|
|
hooks: [],
|
|
typedHooks: [],
|
|
channels: [],
|
|
providers: [],
|
|
gatewayHandlers: {},
|
|
httpRoutes: [],
|
|
cliRegistrars: [],
|
|
services: [],
|
|
commands: [],
|
|
diagnostics: [],
|
|
};
|
|
}
|
|
|
|
export function createPluginRegistry(registryParams: PluginRegistryParams) {
|
|
const registry = createEmptyPluginRegistry();
|
|
return createExtensionHostPluginRegistry({ registry, registryParams });
|
|
}
|