业务链条

This commit is contained in:
fengxiangdebaozi committed 2026-06-02 21:15:46 +08:00
1 parent 30410b0a93
commit 9ae6184dc1
20 files changed
+2440 -24

No files matched your search

@@ -1,10 +1,12 @@
"use client";
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useNavigate } from "react-router-dom";
import {
CheckIcon,
ChevronDownIcon,
ChevronUpIcon,
LayersIcon,
Loader2Icon,
RefreshCwIcon,
SparklesIcon,
@@ -29,7 +31,9 @@ import {
StreamingCursor,
} from "./MessageBubble";
import { MessageStepsCard } from "./MessageStepsCard";
import { BusinessChainPicker } from "./BusinessChainPicker";
import type { IntentSummary } from "../api/intent";
import type { SeatSelectionResult } from "../lib/business-chain";
import {
filterRecommendCandidates,
listRecommendHistory,
@@ -68,8 +72,12 @@ export interface RecommendAgentsDialogProps {
*/
draftId?: string | null;
onCancel: () => void;
/** Called with the user's final selection of agent ids (in display order). */
onConfirm: (agents: Array<{ agent_id: string; name: string }>) => void;
/**
* Called with the user's final seat selection + the orchestration mode.
* 智能推荐模式回传 `{ agents, mode: "recommend" }`;业务链条模式(阶段 3)
* 回传 `{ agents, mode: "chain", chain }`。
*/
onConfirm: (result: SeatSelectionResult) => void;
}
const MIN_SELECTED = 2;
@@ -189,6 +197,9 @@ export function RecommendAgentsDialog({
// 映射也作用于弹窗;浅色不挂,弹窗浅色外观不变。
const { theme } = useTheme();
const isDark = theme === "dark";
const navigate = useNavigate();
// 席位来源模式:智能推荐 / 业务链条。默认**业务链条**。
const [mode, setMode] = useState<"recommend" | "chain">("chain");
const [state, setState] = useState<InternalState>(INITIAL_STATE);
const [selectedIds, setSelectedIds] = useState<Set<string>>(new Set());
@@ -442,18 +453,27 @@ export function RecommendAgentsDialog({
[intent, draftId, cancelInflight, analyze, applyHistory],
);
// Trigger the pipeline whenever the dialog opens. Closing it aborts any
// in-flight stream so the next open starts clean.
// 推荐管线只在「智能推荐」模式下跑一次。默认是业务链条模式 —— 此时不触发推荐
// 模型调用,等用户切到「智能推荐」tab 才启动;每次 open 内只跑一次(切 tab 来回
// 不重复跑),关闭时复位 latch。
const recommendStartedRef = useRef(false);
// 关闭 / 卸载时中止 in-flight 推荐流。
useEffect(() => {
if (!open) {
cancelInflight();
return;
}
void start(false);
return () => {
cancelInflight();
};
}, [open, start, cancelInflight]);
}, [cancelInflight]);
useEffect(() => {
if (!open) {
recommendStartedRef.current = false;
cancelInflight();
return;
}
if (mode === "recommend" && !recommendStartedRef.current) {
recommendStartedRef.current = true;
void start(false);
}
}, [open, mode, start, cancelInflight]);
const handleToggle = useCallback((agentId: string) => {
setSelectedIds((prev) => {
@@ -510,9 +530,14 @@ export function RecommendAgentsDialog({
for (const c of otherCards) {
if (selectedIds.has(c.agent_id)) ordered.push({ agent_id: c.agent_id, name: c.name });
}
onConfirm(ordered);
onConfirm({ agents: ordered, mode: "recommend" });
}, [canConfirm, recommendedCards, otherCards, selectedIds, onConfirm]);
const handleGoConfig = useCallback(() => {
onCancel();
navigate("/page/workspace/roundtable/chains");
}, [navigate, onCancel]);
const handleOpenChange = useCallback(
(next: boolean) => {
if (!next) onCancel();
@@ -534,10 +559,45 @@ export function RecommendAgentsDialog({
选择参会智能体
</DialogTitle>
<DialogDescription>
根据你的任务目标,系统为你推荐了最合适的智能体。你可以取消勾选,也可以从下方添加其他智能体。
{mode === "recommend"
? "根据你的任务目标,系统为你推荐了最合适的智能体。你可以取消勾选,也可以从下方添加其他智能体。"
: "从已配置的业务链条中选择一条,Step 2 将按链条顺序进行多智能体研讨。"}
</DialogDescription>
</DialogHeader>
{/* 模式选择:智能推荐 / 业务链条 */}
<div className="shrink-0 inline-flex self-start rounded-lg border border-border bg-muted/40 p-0.5 text-xs font-medium">
<button
type="button"
onClick={() => setMode("recommend")}
className={cn(
"flex items-center gap-1.5 rounded-md px-3 py-1.5 transition-colors",
mode === "recommend"
? "bg-card text-primary shadow-sm"
: "text-muted-foreground hover:text-foreground",
)}
>
<SparklesIcon className="size-3.5" />
智能推荐
</button>
<button
type="button"
onClick={() => setMode("chain")}
className={cn(
"flex items-center gap-1.5 rounded-md px-3 py-1.5 transition-colors",
mode === "chain"
? "bg-card text-primary shadow-sm"
: "text-muted-foreground hover:text-foreground",
)}
>
<LayersIcon className="size-3.5" />
业务链条
</button>
</div>
{/* ===== 智能推荐模式(现状,零行为变更)===== */}
{mode === "recommend" && (
<>
{/* ============================================================
TOP: 模型生成内容
包含状态行 + 步骤卡 + 思考过程(`<think>`)+ 推荐理由 markdown。
@@ -684,6 +744,17 @@ export function RecommendAgentsDialog({
</Button>
</div>
</DialogFooter>
</>
)}
{/* ===== 业务链条模式 ===== */}
{mode === "chain" && (
<BusinessChainPicker
onConfirm={onConfirm}
onCancel={onCancel}
onGoConfig={handleGoConfig}
/>
)}
</DialogContent>
</Dialog>
);