Skip to content
Open
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
21 changes: 21 additions & 0 deletions src/renderer/features/agents/main/active-chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2024,6 +2024,9 @@ const ChatViewInner = memo(function ChatViewInner({
(state) => state.allSubChats.find((sc) => sc.id === subChatId)?.name || "",
)

// Desktop notifications for agent events
const { notifyAgentNeedsInput } = useDesktopNotifications()

// Mutation for renaming sub-chat
const renameSubChatMutation = api.agents.renameSubChat.useMutation({
onError: (error) => {
Expand Down Expand Up @@ -2628,6 +2631,24 @@ const ChatViewInner = memo(function ChatViewInner({
}
}, [subChatId, lastAssistantMessage, isStreaming, pendingQuestions, setPendingQuestionsMap])

// Track previous pending question toolUseId to detect new questions
const prevPendingQuestionToolUseIdRef = useRef<string | null>(null)

// Notify user when a new AskUserQuestion arrives (when window is not focused)
useEffect(() => {
if (pendingQuestions) {
// Only notify if this is a NEW question (different toolUseId)
if (prevPendingQuestionToolUseIdRef.current !== pendingQuestions.toolUseId) {
prevPendingQuestionToolUseIdRef.current = pendingQuestions.toolUseId
// notifyAgentNeedsInput already checks document.hasFocus() internally
notifyAgentNeedsInput(subChatName || "Agent")
}
} else {
// Clear the ref when there's no pending question
prevPendingQuestionToolUseIdRef.current = null
}
}, [pendingQuestions, subChatName, notifyAgentNeedsInput])

// Helper to clear pending and expired questions for this subChat (used in callbacks)
const clearPendingQuestionCallback = useCallback(() => {
setPendingQuestionsMap((current) => {
Expand Down