后台挂起

This commit is contained in:
fengxiangdebaozi committed 2026-06-04 20:00:58 +08:00
1 parent 788118ce3d
commit 19399482e1
21 files changed
+626 -50

No files matched your search

@@ -18,6 +18,7 @@ import { getAvatarTypeFor } from "../lib/roundtable-constants";
import {
isTerminalJobStatus,
type DispatchChainNode,
type JobDialogue,
type RoundtableJob,
type StartJobPayload,
} from "../lib/job-types";
@@ -65,6 +66,7 @@ function mapJob(raw: Record<string, unknown>): RoundtableJob {
orchestrationMode: (raw.orchestrationMode as RoundtableJob["orchestrationMode"]) ?? "recommend",
chain: (raw.chain as RoundtableJob["chain"]) ?? null,
error: (raw.error as string | null) ?? null,
dialogues: Array.isArray(raw.dialogues) ? (raw.dialogues as JobDialogue[]) : [],
createdAt: (raw.createdAt as string | null) ?? null,
updatedAt: (raw.updatedAt as string | null) ?? null,
};
@@ -67,6 +67,7 @@ export function DispatchChainJobModal({
consensusPercentage={job?.consensusPercentage ?? 0}
onView={job && onView ? () => onView(job) : undefined}
error={job?.error}
dialogues={job?.dialogues}
pendingClarification={job?.pendingClarification}
onResume={
jobId
@@ -14,7 +14,7 @@
* (business-chain.ts)。连线动画 CSS 在 `styles/roundtable-planning.css` 全局段
* (Radix Dialog portal 到 body,不在 .roundtable-planning 作用域内,故用全局类 + 语义 token)。
*/
import { Fragment, useState } from "react";
import { Fragment, useEffect, useRef, useState } from "react";
import { CheckIcon, ChevronRightIcon, EyeIcon, Loader2Icon, SendIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
@@ -30,9 +30,11 @@ import { cn } from "@/lib/utils";
import { getAvatar } from "./Avatars";
import { chainTagClasses } from "../lib/business-chain";
import { getAvatarTypeFor } from "../lib/roundtable-constants";
import type {
ChainNodeState,
DispatchChainNode,
JobDialogue,
JobPhase,
JobStatus,
} from "../lib/job-types";
@@ -62,6 +64,8 @@ export interface DispatchChainModalProps {
onCancel?: () => void;
/** 出错详情(status==='error')。 */
error?: string | null;
/** 研讨对话记录(leader 说明 + 各席位交付)。 */
dialogues?: JobDialogue[];
}
const _NON_TERMINAL: ReadonlySet<JobStatus> = new Set<JobStatus>(["queued", "running", "awaiting_input"]);
@@ -99,8 +103,24 @@ export function DispatchChainModal({
onResume,
onCancel,
error,
dialogues,
}: DispatchChainModalProps) {
const [answer, setAnswer] = useState("");
const convoRef = useRef<HTMLDivElement>(null);
// 新对话进来时自动滚到底部。
const dialogueCount = dialogues?.length ?? 0;
useEffect(() => {
const el = convoRef.current;
if (el) el.scrollTop = el.scrollHeight;
}, [dialogueCount]);
// 对话气泡的头像配色:总控固定蓝;席位优先取流程图节点色,回退按 agentId 派生。
const avatarForDialogue = (d: JobDialogue): string => {
if (d.role === "leader") return "blue";
const node = nodes.find((n) => n.agentId === d.agentId);
return node?.avatarType || (d.agentId ? getAvatarTypeFor(d.agentId, node?.order ? node.order - 1 : 0) : "blue");
};
// 总控节点:初始化 / 决策派活阶段高亮
const coordinatorState: ChainNodeState =
phase === "initializing" || phase === "leader_thinking" ? "active" : "done";
@@ -147,7 +167,7 @@ export function DispatchChainModal({
</DialogHeader>
{/* 横向流程图(横向滚动) */}
<div className="custom-scrollbar min-h-0 flex-1 overflow-x-auto overflow-y-hidden py-10">
<div className="custom-scrollbar shrink-0 overflow-x-auto overflow-y-hidden py-8">
<div className="flex min-w-max items-start gap-0 px-6">
{/* 总控节点 */}
<FlowNode
@@ -192,6 +212,28 @@ export function DispatchChainModal({
</div>
</div>
{/* 研讨对话(leader 说明 + 各席位交付,真网关下即真模型真实对话) */}
{dialogues && dialogues.length > 0 && (
<div
ref={convoRef}
className="custom-scrollbar min-h-0 flex-1 overflow-y-auto border-t px-1 py-3"
>
<div className="space-y-3.5">
{dialogues.map((d) => (
<div key={d.id} className="flex gap-2.5">
<div className="shrink-0">{getAvatar(avatarForDialogue(d), "h-7 w-7")}</div>
<div className="min-w-0 flex-1">
<div className="text-xs font-semibold text-foreground/80">{d.name}</div>
<div className="mt-0.5 whitespace-pre-wrap break-words text-sm leading-relaxed text-foreground/70">
{d.content || "…"}
</div>
</div>
</div>
))}
</div>
</div>
)}
{/* 出错详情 */}
{status === "error" && error && (
<div className="shrink-0 rounded-lg border border-destructive/30 bg-destructive/10 px-3 py-2 text-xs text-destructive">
@@ -52,16 +52,23 @@ export function MessageBubble({
<div className="flex-1 min-w-0 space-y-1">
<div className="flex items-center justify-between">
<div className="flex items-center gap-2">
<span className={cn("text-xs font-extrabold text-slate-900", senderNameClassName)}>
<span
className={cn(
"roundtable-chat-message font-extrabold text-slate-900",
senderNameClassName,
)}
>
{senderName}
</span>
{badge && (
<span className="text-[calc(9px*var(--ui-font-scale,1))] font-mono font-black uppercase text-[var(--brand-900)] bg-[var(--brand-200)] border border-red-200 px-1.5 py-0.2 rounded">
<span className="roundtable-chat-meta font-mono font-black uppercase text-[var(--brand-900)] bg-[var(--brand-200)] border border-red-200 px-1.5 py-0.2 rounded">
{badge}
</span>
)}
</div>
<span className="text-[calc(10px*var(--ui-font-scale,1))] text-slate-400 font-mono font-medium shrink-0">{time}</span>
<span className="roundtable-chat-meta text-slate-400 font-mono font-medium shrink-0">
{time}
</span>
</div>
{children}
</div>
@@ -75,7 +82,7 @@ export function MessageBubble({
*/
export function MessageLoadingPlaceholder({ label }: { label?: string }) {
return (
<div className="flex items-center gap-2 py-1.5 text-xs text-slate-600">
<div className="roundtable-chat-message flex items-center gap-2 py-1.5 text-slate-600">
<Loader2 className="w-4 h-4 animate-spin text-primary" />
<span className="font-medium">{label ?? "正在连接智能体..."}</span>
<span className="inline-flex items-center gap-0.5">
@@ -118,10 +125,10 @@ export const sharedMarkdownComponents = {
<h2 className="text-sm font-bold mt-2 mb-1">{children}</h2>
),
h3: ({ children }: { children?: React.ReactNode }) => (
<h3 className="text-xs font-bold mt-1.5 mb-0.5">{children}</h3>
<h3 className="text-sm font-bold mt-1.5 mb-0.5">{children}</h3>
),
h4: ({ children }: { children?: React.ReactNode }) => (
<h4 className="text-xs font-bold mt-1 mb-0.5">{children}</h4>
<h4 className="text-sm font-bold mt-1 mb-0.5">{children}</h4>
),
strong: ({ children }: { children?: React.ReactNode }) => (
<strong className="font-bold text-slate-900">{children}</strong>
@@ -139,13 +146,13 @@ export const sharedMarkdownComponents = {
const isBlock = /language-/.test(className ?? "");
if (isBlock) {
return (
<pre className="bg-slate-100 text-slate-800 rounded-md p-2 my-1 overflow-x-auto text-[calc(11px*var(--ui-font-scale,1))] font-mono">
<pre className="roundtable-chat-message bg-slate-100 text-slate-800 rounded-md p-2 my-1 overflow-x-auto font-mono">
<code>{children}</code>
</pre>
);
}
return (
<code className="bg-slate-100 text-slate-800 rounded px-1 py-0.5 text-[calc(11px*var(--ui-font-scale,1))] font-mono">
<code className="roundtable-chat-message bg-slate-100 text-slate-800 rounded px-1 py-0.5 font-mono">
{children}
</code>
);
@@ -161,7 +168,7 @@ export const sharedMarkdownComponents = {
</a>
),
table: ({ children }: { children?: React.ReactNode }) => (
<table className="my-1 border-collapse text-[calc(11px*var(--ui-font-scale,1))]">{children}</table>
<table className="roundtable-chat-message my-1 border-collapse">{children}</table>
),
th: ({ children }: { children?: React.ReactNode }) => (
<th className="border border-slate-300 px-1.5 py-0.5 bg-slate-50 font-bold text-left">
@@ -254,7 +261,7 @@ export function ReasoningBlock({
<button
type="button"
onClick={handleToggle}
className="inline-flex items-center gap-1.5 text-[calc(11.5px*var(--ui-font-scale,1))] text-slate-500 hover:text-slate-700 transition-colors cursor-pointer"
className="roundtable-chat-message inline-flex items-center gap-1.5 text-slate-500 hover:text-slate-700 transition-colors cursor-pointer"
>
<BrainIcon className={cn("size-3.5", streaming && "text-primary animate-pulse")} />
<span className={cn(streaming && "animate-pulse")}>{headerLabel}</span>
@@ -265,7 +272,7 @@ export function ReasoningBlock({
{open && (
<div
className={cn(
"rounded-md border border-slate-200 bg-slate-50/60 px-3 py-2 text-[calc(11.5px*var(--ui-font-scale,1))] text-slate-600 leading-relaxed",
"roundtable-chat-message rounded-md border border-slate-200 bg-slate-50/60 px-3 py-2 text-slate-600",
contentClassName,
)}
>
@@ -86,10 +86,15 @@ export function MessageStepsCard({
const display = getStepDisplay(lastReasoning.key, lastReasoning.label, lastReasoning.args);
const Icon = display.icon;
return (
<div className={cn("flex items-center gap-2 text-[calc(11.5px*var(--ui-font-scale,1))] text-slate-500 py-0.5", className)}>
<div
className={cn(
"roundtable-chat-message flex items-center gap-2 text-slate-500 py-0.5",
className,
)}
>
<Icon className="size-3.5 text-slate-400" />
<span>{display.label}</span>
<span className="text-[calc(10px*var(--ui-font-scale,1))] text-slate-400 font-mono">{lastReasoning.ts}</span>
<span className="roundtable-chat-meta text-slate-400 font-mono">{lastReasoning.ts}</span>
</div>
);
}
@@ -108,7 +113,7 @@ export function MessageStepsCard({
>
<ChainOfThoughtStep
label={
<span className="text-[calc(11.5px*var(--ui-font-scale,1))] opacity-60">
<span className="roundtable-chat-message opacity-60">
{showAbove ? "隐藏步骤" : `查看其他 ${priorToolSteps.length} 个步骤`}
</span>
}
@@ -189,9 +194,9 @@ function ToolStep({
: undefined
}
label={
<span className="text-[calc(12px*var(--ui-font-scale,1))] text-slate-700">
<span className="roundtable-chat-message text-slate-700">
<span className="font-medium">{display.label}</span>
<span className="ml-2 text-[calc(10px*var(--ui-font-scale,1))] text-slate-400 font-mono">{step.ts}</span>
<span className="roundtable-chat-meta ml-2 text-slate-400 font-mono">{step.ts}</span>
</span>
}
>
@@ -204,10 +209,10 @@ function ReasoningStep({ step, streaming }: { step: BubbleStep; streaming: boole
const display = getStepDisplay(step.key, step.label, step.args);
const Icon = display.icon;
return (
<div className="flex items-center gap-2 text-[calc(11.5px*var(--ui-font-scale,1))] text-slate-500">
<div className="roundtable-chat-message flex items-center gap-2 text-slate-500">
<Icon className={cn("size-3.5", streaming ? "text-primary animate-pulse" : "text-slate-400")} />
<span>{display.label}</span>
<span className="text-[calc(10px*var(--ui-font-scale,1))] text-slate-400 font-mono">{step.ts}</span>
<span className="roundtable-chat-meta text-slate-400 font-mono">{step.ts}</span>
</div>
);
}
@@ -351,7 +351,7 @@ function Step1Message({
{isStreaming && !hasContent ? (
<MessageLoadingPlaceholder label={msg.phase} />
) : isAgent ? (
<div className="text-xs text-slate-700 leading-relaxed font-medium break-words space-y-2 roundtable-md">
<div className="roundtable-chat-message text-slate-700 font-medium break-words space-y-2">
{introText && <MarkdownContent>{introText}</MarkdownContent>}
{parts.summary && <IntentReadySummaryCard summary={parts.summary} />}
{/*
@@ -422,7 +422,7 @@ function Step1Message({
)}
</div>
) : (
<div className="text-xs text-slate-700 leading-relaxed font-medium whitespace-pre-wrap break-words roundtable-md">
<div className="roundtable-chat-message text-slate-700 font-medium whitespace-pre-wrap break-words">
{msg.content}
</div>
)}
@@ -289,9 +289,9 @@ export function Step2Panel(props: Step2PanelProps) {
)}
</div>
{pendingClarification.context && (
<p className="text-[calc(11px*var(--ui-font-scale,1))] text-amber-800 italic">{pendingClarification.context}</p>
<p className="roundtable-chat-message text-amber-800 italic">{pendingClarification.context}</p>
)}
<p className="text-xs text-slate-800 leading-relaxed font-medium whitespace-pre-wrap break-words">
<p className="roundtable-chat-message text-slate-800 font-medium whitespace-pre-wrap break-words">
{pendingClarification.question}
</p>
{Array.isArray(pendingClarification.options) &&
@@ -310,7 +310,7 @@ export function Step2Panel(props: Step2PanelProps) {
key={`${idx}-${label}`}
type="button"
onClick={() => onSubmitClarification(label)}
className="text-[calc(11px*var(--ui-font-scale,1))] font-bold px-3 py-1.5 rounded-full bg-white border border-amber-300 text-amber-900 hover:bg-amber-100 transition active:scale-95 cursor-pointer"
className="roundtable-chat-message font-bold px-3 py-1.5 rounded-full bg-white border border-amber-300 text-amber-900 hover:bg-amber-100 transition active:scale-95 cursor-pointer"
>
{label}
</button>
@@ -472,7 +472,7 @@ export function Step2Message({
<ReasoningBlock streaming={isStreaming}>{reasoning}</ReasoningBlock>
)}
<div className="text-xs text-slate-700 leading-relaxed font-medium break-words roundtable-md">
<div className="roundtable-chat-message text-slate-700 font-medium break-words">
{isStreaming && !hasContent && <MessageLoadingPlaceholder label={msg.confidence} />}
<MarkdownContent>{content}</MarkdownContent>
{isStreaming && <StreamingCursor />}
@@ -594,17 +594,17 @@ function PresentFileCard({
<div className="flex min-w-0 items-start gap-2">
<FileIcon className="mt-0.5 size-4 shrink-0 text-slate-400" />
<span
className="min-w-0 flex-1 truncate text-[calc(12px*var(--ui-font-scale,1))] font-medium text-slate-700"
className="roundtable-chat-message min-w-0 flex-1 truncate font-medium text-slate-700"
title={filename}
>
{filename}
</span>
</div>
<div className="flex min-w-0 items-center justify-between gap-2">
<span className="rounded bg-slate-100 px-1.5 py-0.5 text-[calc(10px*var(--ui-font-scale,1))] font-mono font-semibold text-slate-500">
<span className="roundtable-chat-meta rounded bg-slate-100 px-1.5 py-0.5 font-mono font-semibold text-slate-500">
{typeLabel}
</span>
<span className="text-[calc(10px*var(--ui-font-scale,1))] text-slate-400">点击预览</span>
<span className="roundtable-chat-meta text-slate-400">点击预览</span>
</div>
</button>
);
@@ -45,6 +45,16 @@ export interface DispatchChainNode {
lastSpokeCycle?: number;
}
/** 一条研讨对话记录(leader 说明 / 某席位交付)。 */
export interface JobDialogue {
id: number;
role: "leader" | "seat";
agentId: string | null;
name: string;
content: string;
cycle: number;
}
/** 一条后台作业的完整快照(§2.5)——对齐后端 `RoundtableJobResponse`(camelCase)。 */
export interface RoundtableJob {
id: string;
@@ -59,6 +69,8 @@ export interface RoundtableJob {
orchestrationMode: "recommend" | "chain";
chain: { id: string; title: string } | null;
error: string | null;
/** 研讨对话记录(leader 说明 + 各席位交付),跑完 / 进行中都可看真实内容。 */
dialogues: JobDialogue[];
createdAt: string | null;
updatedAt: string | null;
}
@@ -55,7 +55,7 @@ export function renderStepArgs(
<ChainOfThoughtSearchResult>{displayName}</ChainOfThoughtSearchResult>
)}
{task && (
<div className="mt-1 max-h-64 overflow-y-auto rounded-md border border-slate-200 bg-white px-2.5 py-1 text-[11px] text-slate-600 leading-relaxed">
<div className="roundtable-chat-message mt-1 max-h-64 overflow-y-auto rounded-md border border-slate-200 bg-white px-2.5 py-1 text-slate-600">
<MarkdownContent>{task}</MarkdownContent>
</div>
)}
@@ -98,7 +98,7 @@ export function renderStepArgs(
case "ask_clarification": {
const question = typeof args.question === "string" ? args.question : "";
return question ? (
<span className="block text-[11px] text-slate-600 line-clamp-2 mt-0.5">
<span className="roundtable-chat-message block text-slate-600 line-clamp-2 mt-0.5">
{question}
</span>
) : null;
@@ -374,8 +374,8 @@ export default function RoundtablePlanningPage() {
model: selectedModel || undefined, // 模型沿用第二步选择
orchestrationMode,
chain: chainMeta,
threadIds: step2.threadIds ?? undefined,
coordinatorName: step2.coordinatorName ?? undefined,
// 不传 threadIds:后台作业由真网关自建全新线程,绝不复用前端本地研讨的线程
// (那些线程可能有活跃 run,复用会撞 409)。
});
}
} catch (err) {
@@ -10,6 +10,19 @@
--rt-primary-active: var(--brand-950, #a8071a);
--rt-primary-soft: var(--brand-200, #feeded);
--rt-page-bg: #fef6f6;
/* 消息列表正文字号 —— 与右侧沙箱 CodeEditor / Markdown 预览的 text-sm 对齐 */
--roundtable-chat-font-size: var(--text-sm, 0.875rem);
--roundtable-chat-meta-font-size: var(--text-xs, 0.75rem);
}
/* 会商对话区:气泡正文、步骤卡、Markdown 块统一继承 */
.roundtable-chat-message {
font-size: var(--roundtable-chat-font-size);
line-height: 1.625;
}
.roundtable-chat-meta {
font-size: var(--roundtable-chat-meta-font-size);
}
.roundtable-planning ::-webkit-scrollbar-thumb {