mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 01:31:23 +00:00
refactor(channels): dedupe hook and monitor execution paths
This commit is contained in:
@@ -233,6 +233,11 @@ export type HookAgentPayload = {
|
||||
timeoutSeconds?: number;
|
||||
};
|
||||
|
||||
export type HookAgentDispatchPayload = Omit<HookAgentPayload, "sessionKey"> & {
|
||||
sessionKey: string;
|
||||
allowUnsafeExternalContent?: boolean;
|
||||
};
|
||||
|
||||
const listHookChannelValues = () => ["last", ...listChannelPlugins().map((plugin) => plugin.id)];
|
||||
|
||||
export type HookMessageChannel = ChannelId | "last";
|
||||
|
||||
@@ -42,7 +42,7 @@ import {
|
||||
extractHookToken,
|
||||
getHookAgentPolicyError,
|
||||
getHookChannelError,
|
||||
type HookMessageChannel,
|
||||
type HookAgentDispatchPayload,
|
||||
type HooksConfigResolved,
|
||||
isHookAgentAllowed,
|
||||
normalizeAgentPayload,
|
||||
@@ -69,20 +69,7 @@ const HOOK_AUTH_FAILURE_WINDOW_MS = 60_000;
|
||||
|
||||
type HookDispatchers = {
|
||||
dispatchWakeHook: (value: { text: string; mode: "now" | "next-heartbeat" }) => void;
|
||||
dispatchAgentHook: (value: {
|
||||
message: string;
|
||||
name: string;
|
||||
agentId?: string;
|
||||
wakeMode: "now" | "next-heartbeat";
|
||||
sessionKey: string;
|
||||
deliver: boolean;
|
||||
channel: HookMessageChannel;
|
||||
to?: string;
|
||||
model?: string;
|
||||
thinking?: string;
|
||||
timeoutSeconds?: number;
|
||||
allowUnsafeExternalContent?: boolean;
|
||||
}) => string;
|
||||
dispatchAgentHook: (value: HookAgentDispatchPayload) => string;
|
||||
};
|
||||
|
||||
function sendJson(res: ServerResponse, status: number, body: unknown) {
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { CronJob } from "../../cron/types.js";
|
||||
import { requestHeartbeatNow } from "../../infra/heartbeat-wake.js";
|
||||
import { enqueueSystemEvent } from "../../infra/system-events.js";
|
||||
import type { createSubsystemLogger } from "../../logging/subsystem.js";
|
||||
import type { HookMessageChannel, HooksConfigResolved } from "../hooks.js";
|
||||
import type { HookAgentDispatchPayload, HooksConfigResolved } from "../hooks.js";
|
||||
import { createHooksRequestHandler } from "../server-http.js";
|
||||
|
||||
type SubsystemLogger = ReturnType<typeof createSubsystemLogger>;
|
||||
@@ -29,20 +29,7 @@ export function createGatewayHooksRequestHandler(params: {
|
||||
}
|
||||
};
|
||||
|
||||
const dispatchAgentHook = (value: {
|
||||
message: string;
|
||||
name: string;
|
||||
agentId?: string;
|
||||
wakeMode: "now" | "next-heartbeat";
|
||||
sessionKey: string;
|
||||
deliver: boolean;
|
||||
channel: HookMessageChannel;
|
||||
to?: string;
|
||||
model?: string;
|
||||
thinking?: string;
|
||||
timeoutSeconds?: number;
|
||||
allowUnsafeExternalContent?: boolean;
|
||||
}) => {
|
||||
const dispatchAgentHook = (value: HookAgentDispatchPayload) => {
|
||||
const sessionKey = value.sessionKey.trim();
|
||||
const mainSessionKey = resolveMainSessionKeyFromConfig();
|
||||
const jobId = randomUUID();
|
||||
|
||||
Reference in New Issue
Block a user