Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(chat): handle provider channel events for reactions and read receipts

Steven Enamakelfb104b933c65
diff --git a/app/src/services/chatService.ts b/app/src/services/chatService.ts
index 427c44b2b7..5fe1bdc3f9 100644
--- a/app/src/services/chatService.ts
+++ b/app/src/services/chatService.ts
@@ -16,6 +16,7 @@ import {
ChatApprovalDecidedEvent,
ChatApprovalRequestEvent,
ChatCancelledEvent,
+ ChatChannelEventEvent,
ChatDoneEvent,
ChatErrorEvent,
ChatInferenceHeartbeatEvent,
@@ -112,6 +113,7 @@ export function segmentText(event: ChatSegmentEvent): string {
export interface ChatEventListeners {
onInferenceStart?: (event: ChatInferenceStartEvent) => void;
onInferenceHeartbeat?: (event: ChatInferenceHeartbeatEvent) => void;
+ onChannelEvent?: (event: ChatChannelEventEvent) => void;
onIterationStart?: (event: ChatIterationStartEvent) => void;
onToolCall?: (event: ChatToolCallEvent) => void;
onToolResult?: (event: ChatToolResultEvent) => void;
@@ -164,6 +166,7 @@ export function subscribeChatEvents(listeners: ChatEventListeners): () => void {
const EVENTS = {
inferenceStart: 'inference_start',
inferenceHeartbeat: 'inference_heartbeat',
+ channelEvent: 'channel_event',
iterationStart: 'iteration_start',
toolCall: 'tool_call',
toolResult: 'tool_result',
@@ -223,6 +226,15 @@ export function subscribeChatEvents(listeners: ChatEventListeners): () => void {
handlers.push([EVENTS.inferenceHeartbeat, cb]);
}
+ if (listeners.onChannelEvent) {
+ const cb = (payload: unknown) => {
+ const event = payload as ChatChannelEventEvent;
+ listeners.onChannelEvent?.(event);
+ };
+ socket.on(EVENTS.channelEvent, cb);
+ handlers.push([EVENTS.channelEvent, cb]);
+ }
+
if (listeners.onIterationStart) {
const cb = (payload: unknown) => {
const e = payload as ChatIterationStartEvent;
diff --git a/app/src/services/chatWire.ts b/app/src/services/chatWire.ts
index 2b8b8c7f3f..b3db7a3575 100644
--- a/app/src/services/chatWire.ts
+++ b/app/src/services/chatWire.ts
@@ -135,6 +135,8 @@ export function externalTransferProvider(event: ExternalTransferPendingEvent): s
export type ChatTextDeltaEvent = WireEvent<'text_delta', 'delta' | 'round'>;
export type ChatThinkingDeltaEvent = WireEvent<'thinking_delta', 'delta' | 'round'>;
+/** Provider event with an OpenHuman row ID only when ownership is exact. */
+export type ChatChannelEventEvent = WireEvent<'channel_event', 'channel_event'>;
export type ChatToolArgsDeltaEvent = WireEvent<
'tool_args_delta',
'delta' | 'round' | 'tool_call_id' | 'tool_name'
diff --git a/app/src/store/threadSlice.ts b/app/src/store/threadSlice.ts
index 6d7c72ec8a..6db46c4843 100644
--- a/app/src/store/threadSlice.ts
+++ b/app/src/store/threadSlice.ts
@@ -2,7 +2,7 @@ import { createAsyncThunk, createSlice, type PayloadAction } from '@reduxjs/tool
import { extractWorkflowProposalFromMessages } from '../lib/workflows/workflowProposal';
import { threadApi } from '../services/api/threadApi';
-import type { ContentPart } from '../services/chatWire';
+import type { ChatChannelEventEvent, ContentPart } from '../services/chatWire';
import { isThreadNotFoundCoreRpcError } from '../services/coreRpcClient';
import type { Thread, ThreadMessage } from '../types/thread';
import { IS_DEV } from '../utils/config';
@@ -32,6 +32,8 @@ interface ThreadState {
*/
welcomeThreadId: string | null;
messagesByThreadId: Record<string, ThreadMessage[]>;
+ /** Live provider receipts/reactions keyed by exact persisted thread/message IDs. */
+ channelActivityByThreadId: Record<string, Record<string, ChannelActivity>>;
messages: ThreadMessage[];
isLoadingThreads: boolean;
isLoadingMessages: boolean;
@@ -61,6 +63,11 @@ interface ThreadState {
createThreadRequestId: string | null;
}
+interface ChannelActivity {
+ reactions: Array<{ actorId: string; value: string; customEmojiId?: string }>;
+ readReceipts: Array<{ actorId: string; timestamp?: number }>;
+}
+
const initialState: ThreadState = {
threads: [],
selectedThreadId: null,
@@ -68,6 +75,7 @@ const initialState: ThreadState = {
activeThreadIds: {},
welcomeThreadId: null,
messagesByThreadId: {},
+ channelActivityByThreadId: {},
messages: [],
isLoadingThreads: false,
isLoadingMessages: false,
@@ -479,6 +487,60 @@ const threadSlice = createSlice({
name: 'thread',
initialState,
reducers: {
+ applyChannelEvent(state, action: PayloadAction<ChatChannelEventEvent>) {
+ const event = action.payload;
+ const rowId = event.openhuman_message_id;
+ if (!rowId || !event.thread_id) return;
+ const thread = (state.channelActivityByThreadId[event.thread_id] ??= {});
+ const activity = (thread[rowId] ??= { reactions: [], readReceipts: [] });
+ const providerEvent = event.channel_event;
+ if (providerEvent.type === 'reaction_added') {
+ const reaction = {
+ actorId: providerEvent.actor.id,
+ value: providerEvent.reaction.value,
+ ...(providerEvent.reaction.customEmojiId
+ ? { customEmojiId: providerEvent.reaction.customEmojiId }
+ : {}),
+ };
+ if (
+ !activity.reactions.some(
+ item =>
+ item.actorId === reaction.actorId &&
+ item.value === reaction.value &&
+ item.customEmojiId === reaction.customEmojiId
+ )
+ ) {
+ activity.reactions.push(reaction);
+ }
+ } else if (providerEvent.type === 'reaction_removed') {
+ activity.reactions = activity.reactions.filter(
+ item =>
+ item.actorId !== providerEvent.actor.id ||
+ item.value !== providerEvent.reaction.value ||
+ item.customEmojiId !== providerEvent.reaction.customEmojiId
+ );
+ } else if (providerEvent.type === 'read_receipt') {
+ const receipt = {
+ actorId: providerEvent.actor?.id ?? '',
+ ...(providerEvent.timestamp == null ? {} : { timestamp: providerEvent.timestamp }),
+ };
+ const prior = activity.readReceipts.findIndex(item => item.actorId === receipt.actorId);
+ if (prior >= 0) activity.readReceipts[prior] = receipt;
+ else activity.readReceipts.push(receipt);
+ }
+ const updateMessage = (message: ThreadMessage) => {
+ if (message.id !== rowId) return;
+ message.extraMetadata = {
+ ...message.extraMetadata,
+ channelActivity: {
+ reactions: activity.reactions,
+ readReceipts: activity.readReceipts,
+ },
+ };
+ };
+ state.messagesByThreadId[event.thread_id]?.forEach(updateMessage);
+ if (state.selectedThreadId === event.thread_id) state.messages.forEach(updateMessage);
+ },
/**
* Dismiss the "couldn't start a new chat" surface (#5156) — the user has
* seen it and moved on (typed into the composer, navigated away).