Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions apps/bullmq/src/jobs/pr-review-notification.test.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions apps/bullmq/src/jobs/pr-review-notification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,17 @@ ${delivery.text}`;
taskId: data.taskId,
route: delivery.route,
text: textWithQuestion,
...(followUp && !delivery.route
? {
action: {
repository: data.repository,
prNumber: data.prNumber,
prUrl: data.prUrl,
question: followUp.question,
followUpPrompt: followUp.prompt,
},
}
: {}),
...(messageTs ? { messageTs } : {}),
});
await finalizePrReviewNotificationRequest(data);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
import { useState, type ComponentType } from 'react';
import { useEffect, useState, type ComponentType } from 'react';
import Image from 'next/image';
import { toast } from 'sonner';
import {
ACP_ENVELOPE_EVENT_TYPES,
getPrReviewNotificationAction,
PR_REVIEW_ACTION_PROCESSING_LEASE_MS,
type AcpRequestUserInputPayload,
type PrReviewNotificationActionStatus,
getProviderRetryNoticeFromMessageData,
getTerminalProviderErrorFromMessageData,
parseLinkedReviewResults,
stripLlmCitationArtifacts,
} from '@roomote/types';

import { cn } from '@/lib/utils';
import { useTRPCClient } from '@/trpc/client';

import {
BasicTooltip,
Button,
ChevronDownIcon,
Loader2,
MediaViewerDialog,
MediaViewerImage,
} from '@/components/system';
Expand Down Expand Up @@ -88,6 +94,138 @@ interface AcpTextMessageProps {
msg: AcpUiMessage;
}

function PrReviewNotificationActions({ msg }: { msg: AcpUiMessage }) {
const action = getPrReviewNotificationAction(
msg.data as Record<string, unknown>,
);
const trpcClient = useTRPCClient();
const [status, setStatus] = useState<PrReviewNotificationActionStatus | null>(
action?.status === 'processing' &&
(action.processingStartedAt ?? 0) <=
Date.now() - PR_REVIEW_ACTION_PROCESSING_LEASE_MS
? 'pending'
: (action?.status ?? null),
);
const [submittingAction, setSubmittingAction] = useState<
'resolve' | 'auto_resolve' | 'dismiss' | null
>(null);

useEffect(() => {
if (action?.status !== 'processing' || !action.processingStartedAt) {
return;
}

const remainingMs =
action.processingStartedAt +
PR_REVIEW_ACTION_PROCESSING_LEASE_MS -
Date.now();

if (remainingMs <= 0) {
setStatus('pending');
return;
}

const timeout = window.setTimeout(() => setStatus('pending'), remainingMs);
return () => window.clearTimeout(timeout);
}, [action?.processingStartedAt, action?.status]);

if (!action || status === null) {
return null;
}

const submit = async (
selectedAction: 'resolve' | 'auto_resolve' | 'dismiss',
) => {
setSubmittingAction(selectedAction);
setStatus('processing');

try {
const result =
await trpcClient.sandboxSession.handlePrReviewNotificationAction.mutate(
{
taskId: action.taskId,
messageId: msg.id,
action: selectedAction,
},
);
setStatus(result.status as PrReviewNotificationActionStatus);

if (
selectedAction === 'auto_resolve' &&
!result.currentFeedbackDispatched
) {
toast.warning(
'Future feedback will be resolved automatically, but this task could not resume for the current feedback.',
);
}
} catch (error) {
setStatus('pending');
toast.error(
error instanceof Error ? error.message : 'Failed to handle feedback.',
);
} finally {
setSubmittingAction(null);
}
};

if (status !== 'pending' && status !== 'processing') {
const resolution = {
resolved: 'Resolution requested.',
auto_resolved:
'Future feedback on this PR will be resolved automatically.',
dismissed: 'Dismissed.',
}[status];

return (
<p className="mt-3 text-sm text-muted-foreground" role="status">
{resolution}
</p>
);
}

const isSubmitting = status === 'processing';

return (
<div
className="mt-3 flex flex-wrap items-center gap-2"
data-testid="pr-review-notification-actions"
>
<Button
size="sm"
disabled={isSubmitting}
onClick={() => void submit('resolve')}
>
{submittingAction === 'resolve' ? (
<Loader2 className="animate-spin" />
) : null}
Resolve these issues
</Button>
<Button
size="sm"
variant="outline"
disabled={isSubmitting}
onClick={() => void submit('auto_resolve')}
>
{submittingAction === 'auto_resolve' ? (
<Loader2 className="animate-spin" />
) : null}
Auto-resolve on this PR
</Button>
<Button
size="sm"
variant="ghost"
disabled={isSubmitting}
onClick={() => void submit('dismiss')}
>
{submittingAction === 'dismiss' ? (
<Loader2 className="animate-spin" />
) : null}
Dismiss
</Button>
</div>
);
}

function getUserTooltipContent(msg: AcpUiMessage): string {
const userName = msg.userName ?? 'User';

Expand Down Expand Up @@ -333,6 +471,9 @@ export function AcpTextMessage({ msg }: AcpTextMessageProps) {
) : (
<MessageResponse>{content}</MessageResponse>
)}
{!isUser && msg.kind === 'text' ? (
<PrReviewNotificationActions msg={msg} />
) : null}
</MessageContent>
</div>
{showPersistentTimestamp && !msg.partial && (
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading