mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 07:10:42 +00:00
* Align silent reply prompt guidance * Pass explicit silent reply conversation types * Handle dm alias in direct prompt guidance * Respect policy session type for routed replies * Preserve routed silent reply policy type * Propagate silent reply dispatcher chat type * Align prompt silent reply target policy * Avoid direct silent fallback prompt token * Use inbound key for prompt silent policy * Rewrite direct silent replies in dispatcher
121 lines
4.3 KiB
TypeScript
121 lines
4.3 KiB
TypeScript
import { normalizeChatType } from "../channels/chat-type.js";
|
|
import type { OpenClawConfig } from "../config/types.openclaw.js";
|
|
import type { SilentReplyConversationType } from "../shared/silent-reply-policy.js";
|
|
import { withReplyDispatcher } from "./dispatch-dispatcher.js";
|
|
import { dispatchReplyFromConfig } from "./reply/dispatch-from-config.js";
|
|
import type { DispatchFromConfigResult } from "./reply/dispatch-from-config.types.js";
|
|
import type { GetReplyFromConfig } from "./reply/get-reply.types.js";
|
|
import { finalizeInboundContext } from "./reply/inbound-context.js";
|
|
import {
|
|
createReplyDispatcher,
|
|
createReplyDispatcherWithTyping,
|
|
type ReplyDispatcherOptions,
|
|
type ReplyDispatcherWithTypingOptions,
|
|
} from "./reply/reply-dispatcher.js";
|
|
import type { ReplyDispatcher } from "./reply/reply-dispatcher.types.js";
|
|
import type { FinalizedMsgContext, MsgContext } from "./templating.js";
|
|
import type { GetReplyOptions } from "./types.js";
|
|
|
|
function resolveDispatcherSilentReplyContext(
|
|
ctx: MsgContext | FinalizedMsgContext,
|
|
cfg: OpenClawConfig,
|
|
) {
|
|
const finalized = finalizeInboundContext(ctx);
|
|
const policySessionKey =
|
|
finalized.CommandSource === "native"
|
|
? (finalized.CommandTargetSessionKey ?? finalized.SessionKey)
|
|
: finalized.SessionKey;
|
|
const chatType = normalizeChatType(finalized.ChatType);
|
|
const conversationType: SilentReplyConversationType | undefined =
|
|
finalized.CommandSource === "native" &&
|
|
finalized.CommandTargetSessionKey &&
|
|
finalized.CommandTargetSessionKey !== finalized.SessionKey
|
|
? undefined
|
|
: chatType === "direct"
|
|
? "direct"
|
|
: chatType === "group" || chatType === "channel"
|
|
? "group"
|
|
: undefined;
|
|
return {
|
|
cfg,
|
|
sessionKey: policySessionKey,
|
|
surface: finalized.Surface ?? finalized.Provider,
|
|
conversationType,
|
|
};
|
|
}
|
|
|
|
export type DispatchInboundResult = DispatchFromConfigResult;
|
|
export { withReplyDispatcher } from "./dispatch-dispatcher.js";
|
|
|
|
export async function dispatchInboundMessage(params: {
|
|
ctx: MsgContext | FinalizedMsgContext;
|
|
cfg: OpenClawConfig;
|
|
dispatcher: ReplyDispatcher;
|
|
replyOptions?: Omit<GetReplyOptions, "onBlockReply">;
|
|
replyResolver?: GetReplyFromConfig;
|
|
}): Promise<DispatchInboundResult> {
|
|
const finalized = finalizeInboundContext(params.ctx);
|
|
return await withReplyDispatcher({
|
|
dispatcher: params.dispatcher,
|
|
run: () =>
|
|
dispatchReplyFromConfig({
|
|
ctx: finalized,
|
|
cfg: params.cfg,
|
|
dispatcher: params.dispatcher,
|
|
replyOptions: params.replyOptions,
|
|
replyResolver: params.replyResolver,
|
|
}),
|
|
});
|
|
}
|
|
|
|
export async function dispatchInboundMessageWithBufferedDispatcher(params: {
|
|
ctx: MsgContext | FinalizedMsgContext;
|
|
cfg: OpenClawConfig;
|
|
dispatcherOptions: ReplyDispatcherWithTypingOptions;
|
|
replyOptions?: Omit<GetReplyOptions, "onBlockReply">;
|
|
replyResolver?: GetReplyFromConfig;
|
|
}): Promise<DispatchInboundResult> {
|
|
const silentReplyContext = resolveDispatcherSilentReplyContext(params.ctx, params.cfg);
|
|
const { dispatcher, replyOptions, markDispatchIdle, markRunComplete } =
|
|
createReplyDispatcherWithTyping({
|
|
...params.dispatcherOptions,
|
|
silentReplyContext: params.dispatcherOptions.silentReplyContext ?? silentReplyContext,
|
|
});
|
|
try {
|
|
return await dispatchInboundMessage({
|
|
ctx: params.ctx,
|
|
cfg: params.cfg,
|
|
dispatcher,
|
|
replyResolver: params.replyResolver,
|
|
replyOptions: {
|
|
...params.replyOptions,
|
|
...replyOptions,
|
|
},
|
|
});
|
|
} finally {
|
|
markRunComplete();
|
|
markDispatchIdle();
|
|
}
|
|
}
|
|
|
|
export async function dispatchInboundMessageWithDispatcher(params: {
|
|
ctx: MsgContext | FinalizedMsgContext;
|
|
cfg: OpenClawConfig;
|
|
dispatcherOptions: ReplyDispatcherOptions;
|
|
replyOptions?: Omit<GetReplyOptions, "onBlockReply">;
|
|
replyResolver?: GetReplyFromConfig;
|
|
}): Promise<DispatchInboundResult> {
|
|
const silentReplyContext = resolveDispatcherSilentReplyContext(params.ctx, params.cfg);
|
|
const dispatcher = createReplyDispatcher({
|
|
...params.dispatcherOptions,
|
|
silentReplyContext: params.dispatcherOptions.silentReplyContext ?? silentReplyContext,
|
|
});
|
|
return await dispatchInboundMessage({
|
|
ctx: params.ctx,
|
|
cfg: params.cfg,
|
|
dispatcher,
|
|
replyResolver: params.replyResolver,
|
|
replyOptions: params.replyOptions,
|
|
});
|
|
}
|