refactor: share Buzz inbound kind checks

This commit is contained in:
Shakker
2026-07-31 10:14:56 +01:00
parent 60c81f3f0a
commit 137c2d8d8a
2 changed files with 8 additions and 3 deletions

View File

@@ -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);
}
}

View File

@@ -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