代码提交
This commit is contained in:
1 parent
47217e9158
commit
9d863f63e5
33 files changed
+2878
-163
No files matched your search
@@ -56,6 +56,7 @@ import { useModels } from "@/core/models/hooks";
|
||||
import { getAvatar, Man1Avatar, RobotAvatar } from "@/roundtable-planning/components/Avatars";
|
||||
import { RecommendAgentsDialog } from "@/roundtable-planning/components/RecommendAgentsDialog";
|
||||
import { BusinessChainListDialog } from "@/roundtable-planning/components/BusinessChainListDialog";
|
||||
import { DispatchChainJobModal } from "@/roundtable-planning/components/DispatchChainJobModal";
|
||||
import { Step1Panel } from "@/roundtable-planning/components/Step1Panel";
|
||||
import { Step2Panel } from "@/roundtable-planning/components/Step2Panel";
|
||||
import { Step3Panel } from "@/roundtable-planning/components/Step3Panel";
|
||||
@@ -74,6 +75,7 @@ import {
|
||||
type SelectedAgent,
|
||||
} from "@/roundtable-planning/lib/roundtable-constants";
|
||||
import type { SeatSelectionResult } from "@/roundtable-planning/lib/business-chain";
|
||||
import { getJobByDraft, startJob } from "@/roundtable-planning/api/roundtable-jobs";
|
||||
|
||||
export default function RoundtablePlanningPage() {
|
||||
const { theme } = useTheme();
|
||||
@@ -88,6 +90,8 @@ export default function RoundtablePlanningPage() {
|
||||
const [isRecommendDialogOpen, setIsRecommendDialogOpen] = useState<boolean>(false);
|
||||
// 「业务链条」按钮 → 打开链条列表弹窗(弹窗里再决定进配置页 / 切到某条链条)。
|
||||
const [isChainListOpen, setIsChainListOpen] = useState<boolean>(false);
|
||||
// 历史下拉点击「进行中」任务 → 打开派活链路流程图弹窗(订阅该作业 SSE)。
|
||||
const [chainModalJobId, setChainModalJobId] = useState<string | null>(null);
|
||||
const [selectedModel, setSelectedModel] = useState<string>("");
|
||||
// Step 2 编排模式:recommend = 总控自由派活;chain = 总控按业务链条顺序派活。
|
||||
// 由推荐弹窗确认时的 SeatSelectionResult.mode 决定(见 handleConfirmAgents)。
|
||||
@@ -321,7 +325,11 @@ export default function RoundtablePlanningPage() {
|
||||
[step2, triggerToast],
|
||||
);
|
||||
|
||||
const handleStartNewTask = useCallback(() => {
|
||||
// 把页面重置回「第一步全新任务」——新建任务 + 后台挂起后都复用。
|
||||
// 注意:只清前端状态,不删后端已建的草稿 / 已挂起的后台作业(它们继续在后台跑,
|
||||
// 在历史记录里可见)。
|
||||
const resetToStep1 = useCallback(() => {
|
||||
step2.stopOrchestration();
|
||||
step2.resetStep2State();
|
||||
setOrchestrationMode("recommend");
|
||||
setChainMeta(null);
|
||||
@@ -333,8 +341,61 @@ export default function RoundtablePlanningPage() {
|
||||
// 同步触发 Step 1 init,而不是依赖 useEffect —— 已经在 Step 1 时
|
||||
// currentStep 不变,useEffect 不会 re-fire。
|
||||
step1.runStep1Init();
|
||||
}, [drafts, step1, step2]);
|
||||
|
||||
const handleStartNewTask = useCallback(() => {
|
||||
resetToStep1();
|
||||
triggerToast("✨ 已开始新任务,请在第一步与任务理解智能体澄清需求");
|
||||
}, [drafts, step1, step2, triggerToast]);
|
||||
}, [resetToStep1, triggerToast]);
|
||||
|
||||
// 「后台挂起」:把当前研讨交给后端自动跑到 Step3 结果绘制完成;模型沿用第二步选择。
|
||||
// 挂起后页面像「新建任务」一样重置回第一步(后台作业继续在历史记录里跑)。
|
||||
const handleBackgroundSuspend = useCallback(async () => {
|
||||
const agents = step2.selectedAgents.map((a) => ({ agentId: a.agent_id, name: a.name }));
|
||||
if (agents.length === 0) {
|
||||
triggerToast("⚠️ 请先选择研讨席位再后台挂起");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// 确保后端存在对应草稿(作业按 draftId 关联,历史下拉据此显示「进行中」)。
|
||||
const draftId = await drafts.ensureDraft(2);
|
||||
// 防重复:该草稿已有在跑作业就不再新建(避免重复作业 / 前后端双跑)。
|
||||
const existing = draftId ? await getJobByDraft(draftId).catch(() => null) : null;
|
||||
const alreadyRunning =
|
||||
existing &&
|
||||
(existing.status === "running" ||
|
||||
existing.status === "awaiting_input" ||
|
||||
existing.status === "queued");
|
||||
if (!alreadyRunning) {
|
||||
await startJob({
|
||||
draftId: draftId ?? undefined,
|
||||
intent: buildInitialIntent(),
|
||||
agents,
|
||||
model: selectedModel || undefined, // 模型沿用第二步选择
|
||||
orchestrationMode,
|
||||
chain: chainMeta,
|
||||
threadIds: step2.threadIds ?? undefined,
|
||||
coordinatorName: step2.coordinatorName ?? undefined,
|
||||
});
|
||||
}
|
||||
} catch (err) {
|
||||
triggerToast(`❌ 后台挂起失败:${(err as Error).message}`);
|
||||
return;
|
||||
}
|
||||
// 重置回第一步(同新建任务);后台作业在历史记录里继续跑、可点开看进度。
|
||||
resetToStep1();
|
||||
triggerToast("🚀 已转入后台,任务会自动跑到结果绘制完成;可在「历史记录」查看进度");
|
||||
void drafts.refresh();
|
||||
}, [
|
||||
step2,
|
||||
drafts,
|
||||
selectedModel,
|
||||
orchestrationMode,
|
||||
chainMeta,
|
||||
buildInitialIntent,
|
||||
resetToStep1,
|
||||
triggerToast,
|
||||
]);
|
||||
|
||||
// 本地 demo handler:继续追问 / 跳过此项 —— 不发请求,只本地 push 一条气泡。
|
||||
const handleSkipQuestion = useCallback(() => {
|
||||
@@ -390,6 +451,26 @@ export default function RoundtablePlanningPage() {
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* 派活链路流程图弹窗(订阅进行中作业的真实 SSE 进度) */}
|
||||
<DispatchChainJobModal
|
||||
jobId={chainModalJobId}
|
||||
open={chainModalJobId !== null}
|
||||
onOpenChange={(o) => {
|
||||
if (!o) setChainModalJobId(null);
|
||||
}}
|
||||
onView={(job) => {
|
||||
// 「查看」:进入该任务。done → 加载草稿(含 step3)落到 Step3 看报告;
|
||||
// 进行中 / 待澄清 → 进去后置暂停态,避免前后端「双跑」同一批 thread。
|
||||
setChainModalJobId(null);
|
||||
if (!job.draftId) return;
|
||||
if (job.status === "running" || job.status === "awaiting_input") {
|
||||
step2.setIsRoundTableRunning(false);
|
||||
step2.stopOrchestration();
|
||||
}
|
||||
drafts.handleLoadDraft(job.draftId);
|
||||
}}
|
||||
/>
|
||||
|
||||
{showToast && (
|
||||
<div className="fixed top-4 left-1/2 transform -translate-x-1/2 z-50 bg-primary text-white text-xs px-4 py-2.5 rounded-xl shadow-lg border border-primary/40 font-medium flex items-center gap-2 animate-bounce">
|
||||
<Sparkles className="h-4 w-4 shrink-0" />
|
||||
@@ -483,6 +564,11 @@ export default function RoundtablePlanningPage() {
|
||||
renameDraftValue={drafts.renameDraftValue}
|
||||
setRenameDraftValue={drafts.setRenameDraftValue}
|
||||
onLoad={drafts.handleLoadDraft}
|
||||
onOpen={() => void drafts.refresh()}
|
||||
onOpenJob={(jobId) => {
|
||||
drafts.setIsHistoryOpen(false);
|
||||
setChainModalJobId(jobId);
|
||||
}}
|
||||
onDelete={drafts.handleDeleteDraft}
|
||||
onStartRename={drafts.handleStartRename}
|
||||
onCommitRename={drafts.handleCommitRename}
|
||||
@@ -593,6 +679,7 @@ export default function RoundtablePlanningPage() {
|
||||
"🎉 多角色智能体博弈共识达成,最终交付全套路线成果文档及方案图!",
|
||||
);
|
||||
}}
|
||||
onBackgroundSuspend={handleBackgroundSuspend}
|
||||
onTriggerToast={triggerToast}
|
||||
/>
|
||||
)}
|
||||
@@ -616,6 +703,8 @@ export default function RoundtablePlanningPage() {
|
||||
setStep3SavedTick((t) => t + 1);
|
||||
}}
|
||||
onReset={handleStartNewTask}
|
||||
openArtifactPreview={step2.openArtifactPreview}
|
||||
seatStubMessages={step2.seatStubMessages}
|
||||
/>
|
||||
)}
|
||||
</section>
|
||||
@@ -762,6 +851,10 @@ interface HistoryDropdownProps {
|
||||
renameDraftValue: string;
|
||||
setRenameDraftValue: React.Dispatch<React.SetStateAction<string>>;
|
||||
onLoad: (id: string) => void;
|
||||
/** 下拉展开时回调(刷新列表拿最新作业状态)。 */
|
||||
onOpen?: () => void;
|
||||
/** 点击「进行中 / 待澄清」的任务 → 打开派活链路流程图弹窗。 */
|
||||
onOpenJob: (jobId: string) => void;
|
||||
onDelete: (id: string) => void;
|
||||
onStartRename: (d: ReturnType<typeof useDraftPersistence>["drafts"][number]) => void;
|
||||
onCommitRename: (id: string) => void;
|
||||
@@ -779,6 +872,8 @@ function HistoryDropdown(props: HistoryDropdownProps) {
|
||||
renameDraftValue,
|
||||
setRenameDraftValue,
|
||||
onLoad,
|
||||
onOpen,
|
||||
onOpenJob,
|
||||
onDelete,
|
||||
onStartRename,
|
||||
onCommitRename,
|
||||
@@ -790,7 +885,13 @@ function HistoryDropdown(props: HistoryDropdownProps) {
|
||||
<button
|
||||
id="history-dropdown-btn"
|
||||
type="button"
|
||||
onClick={() => setIsOpen((open) => !open)}
|
||||
onClick={() =>
|
||||
setIsOpen((open) => {
|
||||
const next = !open;
|
||||
if (next) onOpen?.();
|
||||
return next;
|
||||
})
|
||||
}
|
||||
className="bg-white hover:bg-slate-50 border border-[#e2e8f0] text-[#334155] text-xs font-bold px-3 py-2 rounded-xl flex items-center gap-1.5 transition dark:border-border dark:bg-secondary dark:text-foreground dark:hover:bg-accent"
|
||||
>
|
||||
<History className="w-3.5 h-3.5 text-slate-500" />
|
||||
@@ -815,6 +916,11 @@ function HistoryDropdown(props: HistoryDropdownProps) {
|
||||
{drafts.map((d) => {
|
||||
const isCurrent = d.id === currentDraftId;
|
||||
const isRenaming = d.id === renamingDraftId;
|
||||
// 「进行中 / 待澄清」且有 jobId → 点击打开流程图弹窗,而非加载草稿。
|
||||
const isActiveJob =
|
||||
(d.status === "running" || d.status === "awaiting_input") && !!d.jobId;
|
||||
const openOrLoad = () =>
|
||||
isActiveJob && d.jobId ? onOpenJob(d.jobId) : onLoad(d.id);
|
||||
return (
|
||||
<li key={d.id} className={`px-3 py-2.5 ${isCurrent ? "bg-emerald-50/40" : ""}`}>
|
||||
<div className="flex items-start gap-2">
|
||||
@@ -835,15 +941,30 @@ function HistoryDropdown(props: HistoryDropdownProps) {
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onLoad(d.id)}
|
||||
onClick={openOrLoad}
|
||||
className="block w-full text-left"
|
||||
title="点击加载"
|
||||
title={isActiveJob ? "点击查看进度" : "点击加载"}
|
||||
>
|
||||
<span className="text-[11.5px] font-semibold text-slate-800 line-clamp-2 dark:text-foreground">
|
||||
{d.name}
|
||||
</span>
|
||||
<span className="text-[10px] text-slate-400 mt-0.5 block font-mono">
|
||||
Step {d.furthestStep} ·{" "}
|
||||
<span className="text-[10px] text-slate-400 mt-0.5 flex items-center gap-1 font-mono">
|
||||
{d.status === "running" ? (
|
||||
<span className="inline-flex items-center gap-1 text-primary font-semibold">
|
||||
<Loader2 className="w-3 h-3 animate-spin" />
|
||||
进行中
|
||||
</span>
|
||||
) : d.status === "awaiting_input" ? (
|
||||
<span className="inline-flex items-center gap-1 text-amber-500 font-semibold">
|
||||
<span className="inline-block w-1.5 h-1.5 rounded-full bg-amber-400 animate-pulse" />
|
||||
待澄清
|
||||
</span>
|
||||
) : d.status === "error" ? (
|
||||
<span className="text-rose-500 font-semibold">出错</span>
|
||||
) : (
|
||||
<span>Step {d.furthestStep}</span>
|
||||
)}
|
||||
<span className="text-slate-300">·</span>
|
||||
{new Date(d.updatedAt).toLocaleString("zh-CN", { hour12: false })}
|
||||
</span>
|
||||
</button>
|
||||
@@ -854,11 +975,15 @@ function HistoryDropdown(props: HistoryDropdownProps) {
|
||||
<>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => onLoad(d.id)}
|
||||
onClick={openOrLoad}
|
||||
className="p-1 text-slate-500 hover:text-primary hover:bg-slate-100 rounded transition"
|
||||
title="加载"
|
||||
title={isActiveJob ? "查看进度" : "加载"}
|
||||
>
|
||||
<Upload className="w-3.5 h-3.5" />
|
||||
{isActiveJob ? (
|
||||
<Activity className="w-3.5 h-3.5 text-primary" />
|
||||
) : (
|
||||
<Upload className="w-3.5 h-3.5" />
|
||||
)}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
|
||||
Reference in new issue
Block a user