feat: streamline group dispatch reminders

This commit is contained in:
kris
2026-04-04 03:00:34 +08:00
parent 425d8992ef
commit 5ebb37cbfc
13 changed files with 485 additions and 37 deletions

View File

@@ -18,6 +18,8 @@ import { getMasterAgentChatMenuItems } from "@/lib/master-agent-chat-menu";
import {
extractApprovedTargetProjectIds,
summarizeDispatchPlan,
summarizeDispatchPlanCompact,
summarizeDispatchPlanLightTitle,
} from "@/lib/dispatch-plan-ui";
import type {
Device,
@@ -1036,11 +1038,13 @@ export function ChatComposer({
initialPendingDispatchPlan,
initialRejectedDispatchPlan,
dispatchPlanRecoveryHint,
initialLightDispatchReminderEnabled = false,
}: {
projectId: string;
initialPendingDispatchPlan?: PendingDispatchPlanState | null;
initialRejectedDispatchPlan?: PendingDispatchPlanState | null;
dispatchPlanRecoveryHint?: string | null;
initialLightDispatchReminderEnabled?: boolean;
}) {
const router = useRouter();
const [value, setValue] = useState("");
@@ -1052,6 +1056,9 @@ export function ChatComposer({
const [localRejectedDispatchPlan, setLocalRejectedDispatchPlan] =
useState<PendingDispatchPlanState | null>(null);
const [dismissedPendingPlanId, setDismissedPendingPlanId] = useState<string | null>(null);
const [lightDispatchReminderEnabled, setLightDispatchReminderEnabled] = useState(
initialLightDispatchReminderEnabled,
);
const pendingDispatchPlan =
localPendingDispatchPlan ??
(initialPendingDispatchPlan && initialPendingDispatchPlan.planId !== dismissedPendingPlanId
@@ -1060,7 +1067,7 @@ export function ChatComposer({
const rejectedDispatchPlan =
pendingDispatchPlan ? null : localRejectedDispatchPlan ?? initialRejectedDispatchPlan ?? null;
async function confirmDispatchPlan() {
async function confirmDispatchPlan(rememberLightReminder = false) {
if (!pendingDispatchPlan) return;
setLoading(true);
const response = await fetch(
@@ -1070,12 +1077,16 @@ export function ChatComposer({
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
approvedTargetProjectIds: extractApprovedTargetProjectIds(pendingDispatchPlan),
rememberLightReminder,
}),
},
);
const result = (await response.json()) as {
ok: boolean;
executions?: Array<unknown>;
collaborationGate?: {
lightDispatchReminderEnabled?: boolean;
};
message?: string;
};
setLoading(false);
@@ -1085,11 +1096,18 @@ export function ChatComposer({
return;
}
const executionCount = result.executions?.length ?? extractApprovedTargetProjectIds(pendingDispatchPlan).length;
setLightDispatchReminderEnabled(
result.collaborationGate?.lightDispatchReminderEnabled ?? lightDispatchReminderEnabled,
);
setLocalPendingDispatchPlan(null);
setLocalRejectedDispatchPlan(null);
setDismissedPendingPlanId(pendingDispatchPlan.planId);
setMessageTone("success");
setMessage(`已确认下发到 ${executionCount} 个线程。`);
setMessage(
rememberLightReminder
? `已确认下发到 ${executionCount} 个线程,并记住这个群使用轻提醒。`
: `已确认下发到 ${executionCount} 个线程。`,
);
router.refresh();
}
@@ -1112,6 +1130,7 @@ export function ChatComposer({
} | null;
collaborationGate?: {
requiresMasterAgentApproval?: boolean;
lightDispatchReminderEnabled?: boolean;
};
message?: string;
};
@@ -1132,6 +1151,9 @@ export function ChatComposer({
: null,
);
setDismissedPendingPlanId(null);
setLightDispatchReminderEnabled(
result.collaborationGate?.lightDispatchReminderEnabled ?? lightDispatchReminderEnabled,
);
setMessageTone("success");
setMessage(
result.collaborationGate?.requiresMasterAgentApproval
@@ -1199,6 +1221,7 @@ export function ChatComposer({
} | null;
collaborationGate?: {
requiresMasterAgentApproval?: boolean;
lightDispatchReminderEnabled?: boolean;
};
messageText?: string;
};
@@ -1222,6 +1245,9 @@ export function ChatComposer({
});
setLocalRejectedDispatchPlan(null);
setDismissedPendingPlanId(null);
setLightDispatchReminderEnabled(
result.collaborationGate?.lightDispatchReminderEnabled ?? lightDispatchReminderEnabled,
);
setMessage(
result.collaborationGate?.requiresMasterAgentApproval
? "消息已发送,等待你批准主 Agent 下发。"
@@ -1305,17 +1331,32 @@ export function ChatComposer({
) : null}
{pendingDispatchPlan ? (
<div className="mt-3 rounded-2xl border border-[#E5E5EA] bg-[#F7F8FA] px-4 py-4 text-[12px] leading-6 text-[#57606A]">
<div className="text-[14px] font-semibold text-[#111111]"> Agent </div>
<div className="mt-2 whitespace-pre-line">{summarizeDispatchPlan(pendingDispatchPlan)}</div>
<div className="text-[14px] font-semibold text-[#111111]">
{lightDispatchReminderEnabled ? summarizeDispatchPlanLightTitle(pendingDispatchPlan) : "主 Agent 推荐下发"}
</div>
<div className="mt-2 whitespace-pre-line">{summarizeDispatchPlanCompact(pendingDispatchPlan)}</div>
<div className="mt-2 text-[12px] text-[#8C8C8C]">
{lightDispatchReminderEnabled ? "轻提醒已开启" : "当前仍会显式提醒你确认"}
</div>
<div className="mt-3 flex flex-wrap gap-2">
<button
type="button"
disabled={loading}
onClick={() => void confirmDispatchPlan()}
onClick={() => void confirmDispatchPlan(false)}
className="rounded-full bg-[#07C160] px-4 py-2 text-[13px] font-semibold text-white disabled:bg-[#B7E6C9]"
>
{lightDispatchReminderEnabled ? "继续下发" : "确认一下"}
</button>
{!lightDispatchReminderEnabled ? (
<button
type="button"
disabled={loading}
onClick={() => void confirmDispatchPlan(true)}
className="rounded-full border border-[#D9D9D9] px-4 py-2 text-[13px] font-semibold text-[#57606A]"
>
</button>
) : null}
<button
type="button"
disabled={loading}