mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 18:58:26 +00:00
feat(plugins): expose llm input/output hook payloads (openclaw#16724) thanks @SecondThread
Verified: - pnpm build - pnpm check - pnpm test:macmini Co-authored-by: SecondThread <18317476+SecondThread@users.noreply.github.com> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
@@ -14,6 +14,8 @@ import type {
|
||||
PluginHookBeforeAgentStartEvent,
|
||||
PluginHookBeforeAgentStartResult,
|
||||
PluginHookBeforeCompactionEvent,
|
||||
PluginHookLlmInputEvent,
|
||||
PluginHookLlmOutputEvent,
|
||||
PluginHookBeforeResetEvent,
|
||||
PluginHookBeforeToolCallEvent,
|
||||
PluginHookBeforeToolCallResult,
|
||||
@@ -41,6 +43,8 @@ export type {
|
||||
PluginHookAgentContext,
|
||||
PluginHookBeforeAgentStartEvent,
|
||||
PluginHookBeforeAgentStartResult,
|
||||
PluginHookLlmInputEvent,
|
||||
PluginHookLlmOutputEvent,
|
||||
PluginHookAgentEndEvent,
|
||||
PluginHookBeforeCompactionEvent,
|
||||
PluginHookBeforeResetEvent,
|
||||
@@ -212,6 +216,24 @@ export function createHookRunner(registry: PluginRegistry, options: HookRunnerOp
|
||||
return runVoidHook("agent_end", event, ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run llm_input hook.
|
||||
* Allows plugins to observe the exact input payload sent to the LLM.
|
||||
* Runs in parallel (fire-and-forget).
|
||||
*/
|
||||
async function runLlmInput(event: PluginHookLlmInputEvent, ctx: PluginHookAgentContext) {
|
||||
return runVoidHook("llm_input", event, ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run llm_output hook.
|
||||
* Allows plugins to observe the exact output payload returned by the LLM.
|
||||
* Runs in parallel (fire-and-forget).
|
||||
*/
|
||||
async function runLlmOutput(event: PluginHookLlmOutputEvent, ctx: PluginHookAgentContext) {
|
||||
return runVoidHook("llm_output", event, ctx);
|
||||
}
|
||||
|
||||
/**
|
||||
* Run before_compaction hook.
|
||||
*/
|
||||
@@ -458,6 +480,8 @@ export function createHookRunner(registry: PluginRegistry, options: HookRunnerOp
|
||||
return {
|
||||
// Agent hooks
|
||||
runBeforeAgentStart,
|
||||
runLlmInput,
|
||||
runLlmOutput,
|
||||
runAgentEnd,
|
||||
runBeforeCompaction,
|
||||
runAfterCompaction,
|
||||
|
||||
Reference in New Issue
Block a user