Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/hooks/useAgentZeroStatusIndicator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ type AgentZeroStatusState = {
};

/**
* Hook to manage AgentZero status indicator for Concierge chats.
* Subscribes to real-time reasoning updates via Pusher and manages processing state.
* Hook to manage AgentZero status indicator for chats where AgentZero responds.
* This includes both Concierge DM chats and policy #admins rooms (where Concierge handles onboarding).
* @param reportID - The report ID to monitor
* @param isAgentZeroChat - Whether the chat is an AgentZero-enabled chat (Concierge DM or #admins room)
*/
function useAgentZeroStatusIndicator(reportID: string, isConciergeChat: boolean): AgentZeroStatusState {
function useAgentZeroStatusIndicator(reportID: string, isAgentZeroChat: boolean): AgentZeroStatusState {
const [reportNameValuePairs] = useOnyx(`${ONYXKEYS.COLLECTION.REPORT_NAME_VALUE_PAIRS}${reportID}`);
const serverLabel = reportNameValuePairs?.agentZeroProcessingRequestIndicator?.trim() ?? '';

Expand Down Expand Up @@ -52,7 +54,7 @@ function useAgentZeroStatusIndicator(reportID: string, isConciergeChat: boolean)
}, [reportID]);

useEffect(() => {
if (!isConciergeChat) {
if (!isAgentZeroChat) {
return;
}

Expand All @@ -63,7 +65,7 @@ function useAgentZeroStatusIndicator(reportID: string, isConciergeChat: boolean)
return () => {
unsubscribeFromReportReasoningChannel(reportID);
};
}, [isConciergeChat, reportID]);
}, [isAgentZeroChat, reportID]);

useEffect(() => {
const hadServerLabel = !!prevServerLabelRef.current;
Expand Down Expand Up @@ -139,13 +141,13 @@ function useAgentZeroStatusIndicator(reportID: string, isConciergeChat: boolean)
}, [isOffline]);

const kickoffWaitingIndicator = useCallback(() => {
if (!isConciergeChat) {
if (!isAgentZeroChat) {
return;
}
setOptimisticStartTime(Date.now());
}, [isConciergeChat]);
}, [isAgentZeroChat]);

const isProcessing = isConciergeChat && !isOffline && (!!serverLabel || !!optimisticStartTime);
const isProcessing = isAgentZeroChat && !isOffline && (!!serverLabel || !!optimisticStartTime);

return useMemo(
() => ({
Expand Down
3 changes: 2 additions & 1 deletion src/pages/inbox/ReportScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,13 @@ function ReportScreen({route, navigation, isInSidePanel = false}: ReportScreenPr
const newTransactions = useNewTransactions(reportMetadata?.hasOnceLoadedReportActions, reportTransactions);

const isConciergeChat = isConciergeChatReport(report);
const shouldShowConciergeIndicator = isConciergeChat || isAdminRoom(report);
const {
isProcessing: isConciergeProcessing,
reasoningHistory: conciergeReasoningHistory,
statusLabel: conciergeStatusLabel,
kickoffWaitingIndicator,
} = useAgentZeroStatusIndicator(String(report?.reportID ?? CONST.DEFAULT_NUMBER_ID), isConciergeChat);
} = useAgentZeroStatusIndicator(String(report?.reportID ?? CONST.DEFAULT_NUMBER_ID), shouldShowConciergeIndicator);

const {closeSidePanel} = useSidePanelActions();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import {
chatIncludesConcierge,
getParentReport,
getReportRecipientAccountIDs,
isAdminRoom,
isChatRoom,
isConciergeChatReport,
isGroupChat,
Expand Down Expand Up @@ -222,6 +223,7 @@ function ReportActionCompose({
const isBlockedFromConcierge = useMemo(() => includesConcierge && userBlockedFromConcierge, [includesConcierge, userBlockedFromConcierge]);
const isReportArchived = useReportIsArchived(report?.reportID);
const isConciergeChat = useMemo(() => isConciergeChatReport(report), [report]);
const shouldShowConciergeIndicator = isConciergeChat || isAdminRoom(report);

const isTransactionThreadView = useMemo(() => isReportTransactionThread(report), [report]);
const isExpensesReport = useMemo(() => reportTransactions && reportTransactions.length > 1, [reportTransactions]);
Expand Down Expand Up @@ -336,7 +338,7 @@ function ReportActionCompose({
(newComment: string) => {
const newCommentTrimmed = newComment.trim();

if (isConciergeChat && kickoffWaitingIndicator) {
if (shouldShowConciergeIndicator && kickoffWaitingIndicator) {
kickoffWaitingIndicator();
}

Expand Down Expand Up @@ -373,7 +375,7 @@ function ReportActionCompose({
}
},
[
isConciergeChat,
shouldShowConciergeIndicator,
kickoffWaitingIndicator,
transactionThreadReport,
report,
Expand Down
Loading