feat: 会商链条启停与深度研究报告结构,并完善问答展示与 8BF 返回。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
董宏凯andCursor committed 2026-08-19 20:37:34 +08:00
1 parent be4851555d
commit 0ce060693b
42 files changed
+5320 -3247

No files matched your search

@@ -53,6 +53,8 @@ export interface ChainUpdatePayload {
gatherFirst?: boolean;
/** 发布开关:true 发布为公共 / false 取消发布;omit 不改。仅 owner 生效。 */
isPublic?: boolean;
/** 启停开关:true 启用 / false 停用;omit 不改。仅 owner / 管理员生效。 */
enabled?: boolean;
}
/**
@@ -88,6 +90,7 @@ interface ServerChain {
seat_mode?: string | null;
gather_first?: boolean;
is_public?: boolean;
enabled?: boolean;
is_mine?: boolean;
owner_name?: string | null;
created_at: string | null;
@@ -106,6 +109,7 @@ function toChain(s: ServerChain): BusinessChain {
seatMode: (s.seat_mode as SeatMode | null) ?? undefined,
gatherFirst: s.gather_first ?? false,
isPublic: s.is_public ?? false,
enabled: s.enabled ?? true,
// 后端缺省时按「我的」处理(向后兼容旧响应)。
isMine: s.is_mine ?? true,
ownerName: s.owner_name ?? undefined,
@@ -141,6 +145,7 @@ function fromUpdate(p: ChainUpdatePayload) {
if (p.seatMode !== undefined) out.seat_mode = p.seatMode;
if (p.gatherFirst !== undefined) out.gather_first = p.gatherFirst;
if (p.isPublic !== undefined) out.is_public = p.isPublic;
if (p.enabled !== undefined) out.enabled = p.enabled;
return out;
}
@@ -171,6 +176,11 @@ export async function setChainPublic(id: string, isPublic: boolean): Promise<Bus
return updateChain(id, { isPublic });
}
/** 启用 / 停用一条链条(仅 owner / 管理员生效)。返回更新后的链条,404 返回 null。 */
export async function setChainEnabled(id: string, enabled: boolean): Promise<BusinessChain | null> {
return updateChain(id, { enabled });
}
/** Fetch one chain. Returns null on 404. */
export async function getChain(id: string): Promise<BusinessChain | null> {
const res = await apiFetch(`${BASE()}/${encodeURIComponent(id)}`, { method: "GET" });
@@ -214,10 +224,22 @@ export async function updateChain(id: string, patch: ChainUpdatePayload): Promis
if (res.status === 404) return null;
const data = await readJson<ServerChain>(res, "update chain");
const chain = toChain(data);
const enabledToggle = patch.enabled === true || patch.enabled === false;
writeYLog({
optType: patch.isPublic === true ? OptType.enabled : patch.isPublic === false ? OptType.disabled : OptType.edit,
optDetail:
patch.isPublic === true
optType: enabledToggle
? patch.enabled
? OptType.enabled
: OptType.disabled
: patch.isPublic === true
? OptType.enabled
: patch.isPublic === false
? OptType.disabled
: OptType.edit,
optDetail: enabledToggle
? patch.enabled
? "CM助手-全量-业务链条-启用"
: "CM助手-全量-业务链条-停用"
: patch.isPublic === true
? "CM助手-全量-业务链条-发布"
: patch.isPublic === false
? "CM助手-全量-业务链条-取消发布"
@@ -9,9 +9,10 @@
* 卡片席位名优先用实时 agent 数据(`listAgents()`,与 `BusinessChainPicker` 一致),
* agent 改名后此弹窗也能同步显示;解析不到才回退到落库快照(`seat.name`)。
*/
import { Fragment, useCallback, useEffect, useState } from "react";
import { Fragment, useCallback, useEffect, useMemo, useState } from "react";
import {
ArrowRightIcon,
ClockIcon,
GlobeIcon,
LayersIcon,
Loader2Icon,
@@ -28,14 +29,15 @@ import {
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Switch } from "@/components/ui/switch";
import { cn } from "@/lib/utils";
import { useDesensitizeSubtree } from "@/roundtable-planning/lib/use-desensitize-subtree";
import { getStoredAuth } from "@/core/auth";
import { listAgents } from "@/core/agents";
import { listChains, setChainPublic, type ChainScope } from "../api/chains";
import { chainTagClasses, type BusinessChain } from "../lib/business-chain";
import { listChains, setChainEnabled, setChainPublic, type ChainScope } from "../api/chains";
import { chainTagClasses, isChainEnabled, type BusinessChain } from "../lib/business-chain";
import { getAvatarTypeFor } from "../lib/roundtable-constants";
export interface BusinessChainListDialogProps {
@@ -57,6 +59,8 @@ export interface BusinessChainListBodyProps {
emptyHint?: string;
}
export type EnabledFilter = "all" | "enabled" | "disabled";
/**
* 业务链条列表主体(筛选 tab + 滚动卡片列表)。
*
@@ -76,7 +80,10 @@ export function BusinessChainListBody({
const isAdmin = getStoredAuth()?.system_role === "admin";
// 筛选:我的 / 公共(已发布)/(管理员)全部。
const [scope, setScope] = useState<ChainScope>("mine");
// 启停筛选:全部 / 启用 / 停用。默认全部,关掉开关后卡片仍留在当前列表。
const [enabledFilter, setEnabledFilter] = useState<EnabledFilter>("all");
const [publishingId, setPublishingId] = useState<string | null>(null);
const [togglingId, setTogglingId] = useState<string | null>(null);
// 实时名称表(id 小写 → 最新 name):用于把席位的落库快照名刷新成最新(agent 改名同步)。
const [nameById, setNameById] = useState<Map<string, string>>(new Map());
@@ -137,8 +144,12 @@ export function BusinessChainListBody({
async (chain: BusinessChain) => {
setPublishingId(chain.id);
try {
await setChainPublic(chain.id, !chain.isPublic);
await refresh(scope);
const updated = await setChainPublic(chain.id, !chain.isPublic);
if (updated) {
setChains((prev) => prev.map((c) => (c.id === updated.id ? updated : c)));
} else {
await refresh(scope);
}
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
} finally {
@@ -148,25 +159,69 @@ export function BusinessChainListBody({
[refresh, scope],
);
const handleToggleEnabled = useCallback(
async (chain: BusinessChain) => {
setTogglingId(chain.id);
try {
const updated = await setChainEnabled(chain.id, !isChainEnabled(chain));
if (updated) {
setChains((prev) => prev.map((c) => (c.id === updated.id ? updated : c)));
} else {
await refresh(scope);
}
} catch (err) {
setError(err instanceof Error ? err.message : String(err));
} finally {
setTogglingId(null);
}
},
[refresh, scope],
);
const visibleChains = useMemo(() => {
if (enabledFilter === "enabled") return chains.filter((c) => isChainEnabled(c));
if (enabledFilter === "disabled") return chains.filter((c) => !isChainEnabled(c));
return chains;
}, [chains, enabledFilter]);
return (
<>
{/* 筛选:我的 / 公共 /(管理员)全部 */}
<div className="shrink-0 flex items-center gap-1 rounded-lg border border-border bg-muted/40 p-0.5 self-start">
{((isAdmin ? ["mine", "public", "all"] : ["mine", "public"]) as ChainScope[]).map((s) => (
<button
key={s}
type="button"
onClick={() => setScope(s)}
className={cn(
"rounded-md px-3 py-1 text-xs font-medium transition",
scope === s
? "bg-primary text-primary-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground",
)}
>
{s === "mine" ? "我的" : s === "public" ? "公共" : "全部"}
</button>
))}
{/* 筛选:我的 / 公共 /(管理员)全部 + 全部 / 启用 / 停用 */}
<div className="flex shrink-0 flex-wrap items-center gap-2">
<div className="flex items-center gap-1 rounded-lg border border-border bg-muted/40 p-0.5 self-start">
{((isAdmin ? ["mine", "public", "all"] : ["mine", "public"]) as ChainScope[]).map((s) => (
<button
key={s}
type="button"
onClick={() => setScope(s)}
className={cn(
"rounded-md px-3 py-1 text-xs font-medium transition",
scope === s
? "bg-primary text-primary-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground",
)}
>
{s === "mine" ? "我的" : s === "public" ? "公共" : "全部"}
</button>
))}
</div>
<div className="flex items-center gap-1 rounded-lg border border-border bg-muted/40 p-0.5 self-start">
{(["all", "enabled", "disabled"] as EnabledFilter[]).map((f) => (
<button
key={f}
type="button"
onClick={() => setEnabledFilter(f)}
className={cn(
"rounded-md px-3 py-1 text-xs font-medium transition",
enabledFilter === f
? "bg-primary text-primary-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground",
)}
>
{f === "all" ? "全部状态" : f === "enabled" ? "启用" : "停用"}
</button>
))}
</div>
</div>
<div className="custom-scrollbar -mr-1 min-h-0 flex-1 overflow-y-auto py-3 pr-1">
@@ -179,30 +234,40 @@ export function BusinessChainListBody({
<div className="rounded-md border border-destructive/30 bg-destructive/5 p-4 text-sm text-destructive">
加载业务链条失败:{error}
</div>
) : chains.length === 0 ? (
) : visibleChains.length === 0 ? (
<div className="flex flex-col items-center justify-center gap-3 px-6 py-12 text-center">
<LayersIcon className="size-10 text-primary/40" />
<div className="text-sm font-semibold">
{scope === "public" ? "还没有公共链条" : "还没有业务链条"}
{enabledFilter !== "all"
? enabledFilter === "enabled"
? "没有启用的业务链条"
: "没有停用的业务链条"
: scope === "public"
? "还没有公共链条"
: "还没有业务链条"}
</div>
<p className="max-w-sm text-xs leading-relaxed text-muted-foreground">
{scope === "public"
? "公共链条是其他账号(或你自己)发布出来、所有人可见的链条。去「我的」里发布一条试试。"
: emptyHint ??
"业务链条是可复用的有序智能体编排。点击下方「配置」去创建第一条链条。"}
{enabledFilter !== "all"
? "试试切换「全部状态」,或到卡片上用开关切换启停。"
: scope === "public"
? "公共链条是其他账号(或你自己)发布出来、所有人可见的链条。去「我的」里发布一条试试。"
: emptyHint ??
"业务链条是可复用的有序智能体编排。点击下方「配置」去创建第一条链条。"}
</p>
</div>
) : (
<div className="space-y-3.5">
{chains.map((chain) => (
{visibleChains.map((chain) => (
<ChainRow
key={chain.id}
chain={chain}
canManage={isAdmin || chain.isMine !== false}
nameById={nameById}
publishing={publishingId === chain.id}
toggling={togglingId === chain.id}
onSettings={() => onConfigure(chain.id)}
onTogglePublic={() => handleTogglePublic(chain)}
onToggleEnabled={() => handleToggleEnabled(chain)}
/>
))}
</div>
@@ -252,22 +317,33 @@ function ChainRow({
canManage,
nameById,
publishing,
toggling,
onSettings,
onTogglePublic,
onToggleEnabled,
}: {
chain: BusinessChain;
/** 能否编辑 / 发布(本人链条 或 管理员)。 */
/** 能否编辑 / 发布 / 启停(本人链条 或 管理员)。 */
canManage: boolean;
nameById: Map<string, string>;
publishing: boolean;
toggling: boolean;
onSettings: () => void;
onTogglePublic: () => void;
onToggleEnabled: () => void;
}) {
// 配置者用户名:后端返回 email,展示时取 @ 前的本地部分更像「用户名」。
const ownerName = chain.ownerName ? chain.ownerName.split("@")[0] : "";
const enabled = isChainEnabled(chain);
const updatedLabel = formatUpdatedAt(chain.updatedAt);
return (
<div className="rounded-2xl border border-border bg-card p-5 transition-colors hover:border-primary/40">
{/* 标题行 + 公共徽标 + 发布/设置按钮 */}
<div
className={cn(
"rounded-2xl border border-border bg-card p-5 transition-colors hover:border-primary/40",
!enabled && "opacity-70",
)}
>
{/* 标题行 + 公共/停用徽标 + 启停开关 / 发布 / 设置按钮 */}
<div className="flex items-center gap-2.5">
<div className="truncate text-base font-semibold">{chain.title || "未命名链条"}</div>
<span className="shrink-0 rounded-full bg-muted px-2 py-0.5 text-xs font-medium tabular-nums text-muted-foreground">
@@ -279,7 +355,26 @@ function ChainRow({
公共
</span>
)}
{!enabled && (
<span className="shrink-0 rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground">
已停用
</span>
)}
<div className="ml-auto flex shrink-0 items-center gap-1.5">
{/* 启停:本人的链条或管理员可操作。 */}
{canManage && (
<label className="flex items-center gap-1.5 pr-1 text-xs text-muted-foreground">
<Switch
checked={enabled}
disabled={toggling}
onCheckedChange={() => onToggleEnabled()}
aria-label={enabled ? "停用该业务链条" : "启用该业务链条"}
/>
<span className={cn("min-w-[2em]", enabled ? "text-foreground" : "text-muted-foreground")}>
{enabled ? "启用" : "停用"}
</span>
</label>
)}
{/* 发布 / 取消发布:本人的链条或管理员可操作。 */}
{canManage && (
<Button
@@ -312,13 +407,20 @@ function ChainRow({
</div>
</div>
{ownerName && (
<div
className="mt-1.5 flex items-center gap-1 text-xs text-muted-foreground"
title={chain.ownerName}
>
<UserIcon className="size-3.5 shrink-0" />
<span className="truncate">配置人:{ownerName}</span>
{(ownerName || updatedLabel) && (
<div className="mt-1.5 flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted-foreground">
{ownerName && (
<div className="flex items-center gap-1" title={chain.ownerName}>
<UserIcon className="size-3.5 shrink-0" />
<span className="truncate">配置人:{ownerName}</span>
</div>
)}
{updatedLabel && (
<div className="flex items-center gap-1" title={chain.updatedAt}>
<ClockIcon className="size-3.5 shrink-0" />
<span>最后修改:{updatedLabel}</span>
</div>
)}
</div>
)}
@@ -401,3 +503,21 @@ function ChainSeatsFlow({
</div>
);
}
/** 后端 `updated_at` 形如 `2026-08-19T17:50:00+08:00`;展示到分钟。 */
function formatUpdatedAt(iso: string | undefined): string {
if (!iso) return "";
const date = new Date(iso);
if (!Number.isNaN(date.getTime())) {
return date.toLocaleString("zh-CN", {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
hour12: false,
});
}
const s = iso.replace("T", " ");
return s.length >= 16 ? s.slice(0, 16) : s;
}
@@ -34,6 +34,7 @@ import { listChains, type ChainScope } from "../api/chains";
import {
CHAIN_MIN_SEATS,
chainTagClasses,
isChainEnabled,
type BusinessChain,
type SeatSelectionResult,
} from "../lib/business-chain";
@@ -77,7 +78,7 @@ export function BusinessChainPicker({
listAgents().catch(() => null), // agent 列表失败不阻断链条展示
]);
if (cancelled) return;
setChains(chainList);
setChains(chainList.filter(isChainEnabled));
if (agents) {
const candidates = filterRecommendCandidates(agents);
setExistingIds(new Set(candidates.map((c) => c.agent_id)));
@@ -95,6 +95,11 @@ export interface BusinessChain {
gatherFirst?: boolean;
/** 是否已发布为公共(所有账号可在「公共」筛选查看 / 选入研讨)。 */
isPublic?: boolean;
/**
* 启停状态。缺省 / undefined = 启用(存量链条无该字段时按启用处理)。
* 停用后管理弹窗仍可见,选链弹窗 / 公共入口不再选用。
*/
enabled?: boolean;
/** 是否当前用户所有(仅本人可编辑 / 删除 / 发布;公共筛选里别人的链条为 false)。 */
isMine?: boolean;
/** 配置者(owner)的可读用户名(后端解析的 email);解析失败时为空。 */
@@ -151,6 +156,11 @@ export interface SeatSelectionResult {
export const CHAIN_MIN_SEATS = 2;
export const CHAIN_MAX_SEATS = 20;
/** 启停状态:缺省 / undefined 视为启用(存量链条无该字段)。 */
export function isChainEnabled(chain: Pick<BusinessChain, "enabled">): boolean {
return chain.enabled !== false;
}
/**
* 由一条业务链条 + 当前候选智能体,构造 `SeatSelectionResult`。
*
@@ -134,6 +134,7 @@ import {
} from "@/roundtable-planning/lib/seat-filter";
import {
buildChainSeatSelection,
isChainEnabled,
type BusinessChain,
type ChainSeat,
type SeatSelectionResult,
@@ -3395,7 +3396,8 @@ function RoundtableEntryRail({
void listChains("public")
.then((all) => {
if (!cancelled) {
setChains(lockBusinessChain ? all.filter((chain) => chain.id === lockedChainId) : all);
const usable = all.filter(isChainEnabled);
setChains(lockBusinessChain ? usable.filter((chain) => chain.id === lockedChainId) : usable);
}
})
.catch(() => {