mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:58:25 +00:00
refactor: unify message hook mapping and async dispatch
This commit is contained in:
50
src/auto-reply/reply/message-preprocess-hooks.ts
Normal file
50
src/auto-reply/reply/message-preprocess-hooks.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { fireAndForgetHook } from "../../hooks/fire-and-forget.js";
|
||||
import { createInternalHookEvent, triggerInternalHook } from "../../hooks/internal-hooks.js";
|
||||
import {
|
||||
deriveInboundMessageHookContext,
|
||||
toInternalMessagePreprocessedContext,
|
||||
toInternalMessageTranscribedContext,
|
||||
} from "../../hooks/message-hook-mappers.js";
|
||||
import type { FinalizedMsgContext } from "../templating.js";
|
||||
|
||||
export function emitPreAgentMessageHooks(params: {
|
||||
ctx: FinalizedMsgContext;
|
||||
cfg: OpenClawConfig;
|
||||
isFastTestEnv: boolean;
|
||||
}): void {
|
||||
if (params.isFastTestEnv) {
|
||||
return;
|
||||
}
|
||||
const sessionKey = params.ctx.SessionKey?.trim();
|
||||
if (!sessionKey) {
|
||||
return;
|
||||
}
|
||||
|
||||
const canonical = deriveInboundMessageHookContext(params.ctx);
|
||||
if (canonical.transcript) {
|
||||
fireAndForgetHook(
|
||||
triggerInternalHook(
|
||||
createInternalHookEvent(
|
||||
"message",
|
||||
"transcribed",
|
||||
sessionKey,
|
||||
toInternalMessageTranscribedContext(canonical, params.cfg),
|
||||
),
|
||||
),
|
||||
"get-reply: message:transcribed internal hook failed",
|
||||
);
|
||||
}
|
||||
|
||||
fireAndForgetHook(
|
||||
triggerInternalHook(
|
||||
createInternalHookEvent(
|
||||
"message",
|
||||
"preprocessed",
|
||||
sessionKey,
|
||||
toInternalMessagePreprocessedContext(canonical, params.cfg),
|
||||
),
|
||||
),
|
||||
"get-reply: message:preprocessed internal hook failed",
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user