/** * Local types mirroring the OpenClaw plugin SDK contracts. We don't import * directly from `openclaw/plugin-sdk` so the package can build standalone in * the secr monorepo (the OpenClaw runtime injects the real SDK at install * time on the user's machine). Keep these in sync with the docs: * * https://docs.openclaw.ai/plugins/hooks * https://docs.openclaw.ai/plugins/building-plugins */ export interface PluginConfig { apiUrl?: string; identityPath?: string; tokenEnvVar?: string; /** Direct token override. Takes precedence over tokenEnvVar. */ token?: string; /** Override IDENTITY.md frontmatter — useful when the file isn't present. */ org?: string; project?: string; environment?: string; materializeOnStartup?: boolean; enforceGateway?: boolean; } export interface BeforeToolCallEvent { toolName: string; params: Record; runId?: string; toolCallId?: string; } export interface PluginContext { agentId?: string; sessionKey?: string; sessionId?: string; runId?: string; jobId?: string; trace?: unknown; pluginConfig?: PluginConfig; } export interface RequireApprovalDecision { title: string; description: string; severity?: "info" | "warning" | "critical"; timeoutMs?: number; timeoutBehavior?: "allow" | "deny"; pluginId?: string; onResolution?: (decision: "allow-once" | "allow-always" | "deny" | "timeout" | "cancelled") => Promise | void; } export interface BeforeToolCallResult { params?: Record; block?: boolean; blockReason?: string; requireApproval?: RequireApprovalDecision; } export interface ToolExecuteResult { content: Array<{ type: "text"; text: string; }>; isError?: boolean; } export interface RegisterToolDef { name: string; description: string; parameters: unknown; execute: (id: string, params: Record) => Promise; } /** * Tool-call hook handler signature. The OpenClaw runtime calls this through * api.on("before_tool_call", handler) — NOT registerHook (which is for the * InternalHookEvent type used by command/session/agent events). */ export type BeforeToolCallHandler = (event: BeforeToolCallEvent, ctx: PluginContext) => Promise | BeforeToolCallResult | void; /** * Fires after a tool call has executed (or failed). result + error + durationMs * are populated by the runtime so plugins can record accurate audit outcomes. */ export interface AfterToolCallEvent { toolName: string; params: Record; runId?: string; toolCallId?: string; result?: unknown; error?: string; durationMs?: number; } export type AfterToolCallHandler = (event: AfterToolCallEvent, ctx: PluginContext) => Promise | void; export interface OpenClawPluginApi { registerTool(def: RegisterToolDef, opts?: { optional?: boolean; }): void; /** * Lifecycle hook registration for typed plugin hooks (before_tool_call, * after_tool_call, llm_input/output, etc). This is the API the runtime's * pi-tools.before_tool_call invocation path uses to discover handlers. */ on(event: "before_tool_call", handler: BeforeToolCallHandler, opts?: { priority?: number; timeoutMs?: number; }): void; on(event: "after_tool_call", handler: AfterToolCallHandler, opts?: { priority?: number; timeoutMs?: number; }): void; on(event: "before_message_write", handler: (event: any, ctx: any) => Promise<{ block?: boolean; message?: any; } | void> | { block?: boolean; message?: any; } | void, opts?: { priority?: number; timeoutMs?: number; }): void; /** Legacy: command/session InternalHookEvent registration. Different event shape. */ registerHook?(events: string | string[], handler: (event: { type: string; action: string; sessionKey: string; context: Record; timestamp: Date; messages: string[]; }) => Promise | void, opts?: { name?: string; }): void; registerService?(def: { name: string; start: () => Promise | void; stop?: () => Promise | void; }): void; registrationMode?: "full" | "discovery" | "setup-only" | "setup-runtime" | "cli-metadata"; } export interface PluginEntryDef { id: string; name: string; description?: string; register: (api: OpenClawPluginApi) => void | Promise; } //# sourceMappingURL=types.d.ts.map