Skip to content

Commit 161efdf

Browse files
author
Test
committed
🤖 fix: narrow mux message type guard for mobile
Change-Id: I89207a670656a722fbcfed3cdf4057db195c85b3 Signed-off-by: Test <test@example.com>
1 parent afaf80f commit 161efdf

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

mobile/src/messages/normalizeChatEvent.ts

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -279,32 +279,35 @@ export function createChatEventExpander(): ChatEventExpander {
279279
return payload.flatMap((item) => expandSingle(item));
280280
}
281281

282-
if (isObject(payload) && isMuxMessage(payload as WorkspaceChatMessage)) {
283-
const muxMessage = payload as MuxMessage;
284-
const historySequence = muxMessage.metadata?.historySequence;
285-
286-
if (typeof historySequence !== "number" || !Number.isFinite(historySequence)) {
287-
console.warn(`${DEBUG_TAG} Dropping mux message without historySequence`, {
288-
id: muxMessage.id,
289-
role: muxMessage.role,
290-
metadata: muxMessage.metadata,
291-
});
292-
return [];
293-
}
282+
if (isObject(payload)) {
283+
const candidate = payload as WorkspaceChatMessage;
284+
if (isMuxMessage(candidate)) {
285+
const muxMessage: MuxMessage = candidate;
286+
const historySequence = muxMessage.metadata?.historySequence;
287+
288+
if (typeof historySequence !== "number" || !Number.isFinite(historySequence)) {
289+
console.warn(`${DEBUG_TAG} Dropping mux message without historySequence`, {
290+
id: muxMessage.id,
291+
role: muxMessage.role,
292+
metadata: muxMessage.metadata,
293+
});
294+
return [];
295+
}
294296

295-
processor.handleEvent(muxMessage as WorkspaceChatMessage);
296-
const displayed = transformMuxToDisplayed(muxMessage);
297+
processor.handleEvent(muxMessage as WorkspaceChatMessage);
298+
const displayed = transformMuxToDisplayed(muxMessage);
297299

298-
if (displayed.length === 0) {
299-
debugLog("Mux message yielded no displayable entries", {
300-
id: muxMessage.id,
301-
role: muxMessage.role,
302-
historySequence,
303-
});
304-
return [];
305-
}
300+
if (displayed.length === 0) {
301+
debugLog("Mux message yielded no displayable entries", {
302+
id: muxMessage.id,
303+
role: muxMessage.role,
304+
historySequence,
305+
});
306+
return [];
307+
}
306308

307-
return displayed;
309+
return displayed;
310+
}
308311
}
309312
if (typeof payload === "string" || typeof payload === "number") {
310313
// Skip primitive values - they're not valid events

0 commit comments

Comments
 (0)