feat: add internal hooks system
This commit is contained in:
@@ -64,6 +64,35 @@ export type HooksGmailConfig = {
|
||||
thinking?: "off" | "minimal" | "low" | "medium" | "high";
|
||||
};
|
||||
|
||||
export type InternalHookHandlerConfig = {
|
||||
/** Event key to listen for (e.g., 'command:new', 'session:start') */
|
||||
event: string;
|
||||
/** Path to handler module (absolute or relative to cwd) */
|
||||
module: string;
|
||||
/** Export name from module (default: 'default') */
|
||||
export?: string;
|
||||
};
|
||||
|
||||
export type HookConfig = {
|
||||
enabled?: boolean;
|
||||
env?: Record<string, string>;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
export type InternalHooksConfig = {
|
||||
/** Enable internal hooks system */
|
||||
enabled?: boolean;
|
||||
/** Legacy: List of internal hook handlers to register (still supported) */
|
||||
handlers?: InternalHookHandlerConfig[];
|
||||
/** Per-hook configuration overrides */
|
||||
entries?: Record<string, HookConfig>;
|
||||
/** Load configuration */
|
||||
load?: {
|
||||
/** Additional hook directories to scan */
|
||||
extraDirs?: string[];
|
||||
};
|
||||
};
|
||||
|
||||
export type HooksConfig = {
|
||||
enabled?: boolean;
|
||||
path?: string;
|
||||
@@ -73,4 +102,6 @@ export type HooksConfig = {
|
||||
transformsDir?: string;
|
||||
mappings?: HookMappingConfig[];
|
||||
gmail?: HooksGmailConfig;
|
||||
/** Internal agent event hooks */
|
||||
internal?: InternalHooksConfig;
|
||||
};
|
||||
|
||||
@@ -41,6 +41,32 @@ export const HookMappingSchema = z
|
||||
})
|
||||
.optional();
|
||||
|
||||
export const InternalHookHandlerSchema = z.object({
|
||||
event: z.string(),
|
||||
module: z.string(),
|
||||
export: z.string().optional(),
|
||||
});
|
||||
|
||||
const HookConfigSchema = z
|
||||
.object({
|
||||
enabled: z.boolean().optional(),
|
||||
env: z.record(z.string(), z.string()).optional(),
|
||||
})
|
||||
.passthrough();
|
||||
|
||||
export const InternalHooksSchema = z
|
||||
.object({
|
||||
enabled: z.boolean().optional(),
|
||||
handlers: z.array(InternalHookHandlerSchema).optional(),
|
||||
entries: z.record(z.string(), HookConfigSchema).optional(),
|
||||
load: z
|
||||
.object({
|
||||
extraDirs: z.array(z.string()).optional(),
|
||||
})
|
||||
.optional(),
|
||||
})
|
||||
.optional();
|
||||
|
||||
export const HooksGmailSchema = z
|
||||
.object({
|
||||
account: z.string().optional(),
|
||||
|
||||
@@ -2,7 +2,7 @@ import { z } from "zod";
|
||||
import { ToolsSchema } from "./zod-schema.agent-runtime.js";
|
||||
import { AgentsSchema, AudioSchema, BindingsSchema, BroadcastSchema } from "./zod-schema.agents.js";
|
||||
import { HexColorSchema, ModelsConfigSchema } from "./zod-schema.core.js";
|
||||
import { HookMappingSchema, HooksGmailSchema } from "./zod-schema.hooks.js";
|
||||
import { HookMappingSchema, HooksGmailSchema, InternalHooksSchema } from "./zod-schema.hooks.js";
|
||||
import { ChannelsSchema } from "./zod-schema.providers.js";
|
||||
import { CommandsSchema, MessagesSchema, SessionSchema } from "./zod-schema.session.js";
|
||||
|
||||
@@ -148,6 +148,7 @@ export const ClawdbotSchema = z
|
||||
transformsDir: z.string().optional(),
|
||||
mappings: z.array(HookMappingSchema).optional(),
|
||||
gmail: HooksGmailSchema,
|
||||
internal: InternalHooksSchema,
|
||||
})
|
||||
.optional(),
|
||||
web: z
|
||||
|
||||
Reference in New Issue
Block a user