mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-02 10:21:34 +00:00
refactor: share Buzz inbound kind checks
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
||||
BUZZ_NORMAL_MESSAGE_KIND,
|
||||
BUZZ_TYPING_INDICATOR_KIND,
|
||||
buildBuzzMessageTags,
|
||||
isBuzzInboundMessageKind,
|
||||
parseBuzzMessageEvent,
|
||||
type BuzzInboundMessage,
|
||||
} from "./message-event.js";
|
||||
@@ -383,7 +384,7 @@ async function createBuzzRoomMembershipTracker(params: {
|
||||
return refreshMembershipOnce(channelId);
|
||||
};
|
||||
const handleRoomEvent = (event: Event) => {
|
||||
if (BUZZ_INBOUND_MESSAGE_KINDS.includes(event.kind)) {
|
||||
if (isBuzzInboundMessageKind(event.kind)) {
|
||||
params.onMessageEvent(event, isMember);
|
||||
return;
|
||||
}
|
||||
@@ -480,7 +481,7 @@ async function createBuzzRoomMembershipTracker(params: {
|
||||
// EOSE can be newer than the loaded snapshot and need an in-memory overlay.
|
||||
initialized = true;
|
||||
for (const { event, historical } of bufferedEvents) {
|
||||
if (!historical || BUZZ_INBOUND_MESSAGE_KINDS.includes(event.kind)) {
|
||||
if (!historical || isBuzzInboundMessageKind(event.kind)) {
|
||||
handleRoomEvent(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,10 @@ const BUZZ_DIFF_AGENT_CONTEXT_MAX_CHARS = 4_000;
|
||||
const BUZZ_DIFF_AGENT_CONTEXT_TRUNCATED_SUFFIX = "\n...[Buzz diff truncated for model context]";
|
||||
const BUZZ_INBOUND_MESSAGE_KIND_SET = new Set<number>(BUZZ_INBOUND_MESSAGE_KINDS);
|
||||
|
||||
export function isBuzzInboundMessageKind(kind: number): boolean {
|
||||
return BUZZ_INBOUND_MESSAGE_KIND_SET.has(kind);
|
||||
}
|
||||
|
||||
interface BuzzDiffMetadata {
|
||||
repoUrl: string;
|
||||
commitSha: string;
|
||||
@@ -210,7 +214,7 @@ export function formatBuzzMessageForAgent(message: BuzzInboundMessage): string {
|
||||
|
||||
export function parseBuzzMessageEvent(event: Event): BuzzInboundMessage | null {
|
||||
if (
|
||||
!BUZZ_INBOUND_MESSAGE_KIND_SET.has(event.kind) ||
|
||||
!isBuzzInboundMessageKind(event.kind) ||
|
||||
!event.content.trim() ||
|
||||
Buffer.byteLength(event.content, "utf8") >
|
||||
(event.kind === BUZZ_DIFF_MESSAGE_KIND
|
||||
|
||||
Reference in New Issue
Block a user