sync: 鍚屾灞€鍩熺綉鏈€鏂颁唬鐮?(source master @ b69568e4)
This commit is contained in:
1 parent
4f7f07504a
commit
8bc8b0e082
1651 files changed
+278599
-11416
No files matched your search
@@ -5,6 +5,7 @@ import type { ClarificationPayload } from "./multi-agent";
|
||||
import { reportRoundtableError } from "./diagnostics-report";
|
||||
import { resolveAllowMultiple } from "@/roundtable-planning/lib/clarification";
|
||||
import { normalizeIntentReadySummary } from "@/roundtable-planning/lib/roundtable-constants";
|
||||
import type { ReportRequirementSnapshot } from "@/report-collaboration/api/types";
|
||||
|
||||
export type { ClarificationPayload };
|
||||
|
||||
@@ -15,6 +16,8 @@ export const POSITION_INTENT_AGENT_ID = "position-roundtable-intent";
|
||||
/** Dedicated Step 1 agent for the 8BF roundtable workspace (same prompt family
|
||||
* as `roundtable-intent`, independently tunable via the agent config UI). */
|
||||
export const EIGHTBF_INTENT_AGENT_ID = "eightbf-roundtable-intent";
|
||||
/** Dedicated real streaming agent for report-collaboration requirement dialogue. */
|
||||
export const REPORT_COLLABORATION_INTENT_AGENT_ID = "report-collaboration-intent";
|
||||
|
||||
/**
|
||||
* Task-intent agent (Step 1) API. Mirror of multi-agent.ts but with a single
|
||||
@@ -156,6 +159,8 @@ export interface IntentSummary {
|
||||
riskWarnings?: string[];
|
||||
keyPoints?: string[];
|
||||
strategicSignificance?: string[];
|
||||
/** Present only for the report-collaboration intent agent. */
|
||||
report_requirement?: Omit<ReportRequirementSnapshot, "revision">;
|
||||
}
|
||||
|
||||
/** Final hand-off shape emitted only by the position-roundtable intent agent. */
|
||||
@@ -206,6 +211,8 @@ export interface StreamIntentRequest {
|
||||
signal?: AbortSignal;
|
||||
/** Fires for every AI text chunk parsed out of LangGraph messages-tuple frames. */
|
||||
onTextDelta?: (text: string, messageId: string) => void;
|
||||
/** Separate provider-native reasoning delta when it is not embedded in `<think>`. */
|
||||
onReasoningDelta?: (text: string, messageId: string) => void;
|
||||
/**
|
||||
* Fires whenever the inferred SSE phase changes. The UI uses this to flip
|
||||
* the placeholder bubble's caption from "调度中" → "已连接,等待响应" →
|
||||
@@ -314,6 +321,18 @@ function extractAiTextDelta(parsed: unknown): { text: string; id: string } | nul
|
||||
return { text, id };
|
||||
}
|
||||
|
||||
function extractAiReasoningDelta(parsed: unknown): { text: string; id: string } | null {
|
||||
if (!Array.isArray(parsed) || parsed.length < 1) return null;
|
||||
const chunk = parsed[0];
|
||||
if (!chunk || typeof chunk !== "object") return null;
|
||||
const obj = chunk as Record<string, unknown>;
|
||||
const kwargs = obj.additional_kwargs;
|
||||
if (!kwargs || typeof kwargs !== "object") return null;
|
||||
const reasoning = (kwargs as Record<string, unknown>).reasoning_content;
|
||||
if (typeof reasoning !== "string" || !reasoning) return null;
|
||||
return { text: reasoning, id: typeof obj.id === "string" ? obj.id : "" };
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a live `type:"tool"` `ask_clarification` frame into a ClarificationPayload.
|
||||
*
|
||||
@@ -622,6 +641,8 @@ export async function streamIntent(req: StreamIntentRequest): Promise<StreamInte
|
||||
|
||||
const delta = extractAiTextDelta(parsed);
|
||||
if (delta) req.onTextDelta?.(delta.text, delta.id);
|
||||
const reasoningDelta = extractAiReasoningDelta(parsed);
|
||||
if (reasoningDelta) req.onReasoningDelta?.(reasoningDelta.text, reasoningDelta.id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,11 +39,16 @@ export interface ChainFlowStage {
|
||||
goal?: string | null;
|
||||
}
|
||||
|
||||
/** 节点执行状态(任务分析回放传入;缺省展示 Ready)。 */
|
||||
export type ChainFlowSeatState = "waiting" | "running" | "done" | "failed";
|
||||
|
||||
export interface ChainFlowDiagramProps {
|
||||
stages: ChainFlowStage[];
|
||||
/** 点击席位节点卡片(总控节点不触发)。 */
|
||||
onNodeClick?: (agentId: string, name?: string) => void;
|
||||
className?: string;
|
||||
/** 传入时节点卡片叠加执行状态徽标(任务分析的运行回放);不影响原有展示。 */
|
||||
seatStates?: Record<string, { state: ChainFlowSeatState; durationMs?: number }> | null;
|
||||
}
|
||||
|
||||
// ── 布局常量(世界坐标,单位 px)─────────────────────────────────────────────
|
||||
@@ -84,7 +89,7 @@ interface PlacedNode {
|
||||
rightX: number;
|
||||
}
|
||||
|
||||
export function ChainFlowDiagram({ stages, onNodeClick, className }: ChainFlowDiagramProps) {
|
||||
export function ChainFlowDiagram({ stages, onNodeClick, className, seatStates }: ChainFlowDiagramProps) {
|
||||
// ── 列 / 节点 / 连线 / 标签布局 ──────────────────────────────────────────
|
||||
const layout = useMemo(() => {
|
||||
// 列:总控 + 各 Stage。
|
||||
@@ -302,32 +307,70 @@ export function ChainFlowDiagram({ stages, onNodeClick, className }: ChainFlowDi
|
||||
<path d="M0,0 L6.5,3 L0,6 Z" fill="currentColor" />
|
||||
</marker>
|
||||
</defs>
|
||||
{layout.edges.map((edge) => (
|
||||
<path
|
||||
key={edge.id}
|
||||
d={edge.d}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.75}
|
||||
markerEnd="url(#cfd-arrow)"
|
||||
/>
|
||||
))}
|
||||
{layout.edges.map((edge) => {
|
||||
// 回放态:进入「执行中」节点的连线启用流动虚线动画。
|
||||
const targetId = edge.id.split("->")[1]?.split("<")[0] ?? "";
|
||||
const flowing =
|
||||
seatStates != null && seatStates[targetId]?.state === "running";
|
||||
return (
|
||||
<path
|
||||
className={flowing ? "cfd-flowing-edge" : undefined}
|
||||
key={edge.id}
|
||||
d={edge.d}
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth={1.75}
|
||||
markerEnd="url(#cfd-arrow)"
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</svg>
|
||||
|
||||
{/* 节点卡片(参考「业务链条配置器」样式:左彩色描边 + 头像 + 名称 +
|
||||
L-阶段徽标 + 同色角色行 + 底部 Ready 心跳条;图标仍用我方 getAvatar)。 */}
|
||||
L-阶段徽标 + 同色角色行 + 底部 Ready 心跳条;图标仍用我方 getAvatar)。
|
||||
seatStates 传入时(任务分析回放)叠加执行状态徽标与状态描边。 */}
|
||||
{layout.cols.flatMap((col, colIdx) =>
|
||||
col.nodes.map((n) => {
|
||||
const isCoordinator = n.id === COORDINATOR_ID;
|
||||
const nc = nodeColorOf(n.avatarType);
|
||||
// 回放态(任务分析)传入了 "__coordinator__" 状态时,总控节点同样显示执行状态。
|
||||
const seatState = seatStates
|
||||
? seatStates[n.id] ?? (isCoordinator ? seatStates["__coordinator__"] : undefined)
|
||||
: undefined;
|
||||
const state = seatState?.state;
|
||||
const stateStyle = state
|
||||
? ({
|
||||
waiting: "text-muted-foreground",
|
||||
running: "text-amber-600 dark:text-amber-300",
|
||||
done: "text-emerald-600 dark:text-emerald-300",
|
||||
failed: "text-red-600 dark:text-red-400",
|
||||
} as const)[state]
|
||||
: null;
|
||||
const stateLabel =
|
||||
state === "waiting"
|
||||
? "等待"
|
||||
: state === "running"
|
||||
? "执行中"
|
||||
: state === "done"
|
||||
? "完成"
|
||||
: state === "failed"
|
||||
? "失败"
|
||||
: null;
|
||||
const stateSeconds = seatState?.durationMs
|
||||
? Math.max(1, Math.round(seatState.durationMs / 1000))
|
||||
: null;
|
||||
return (
|
||||
<div
|
||||
key={n.id}
|
||||
className={cn("absolute", !isCoordinator && "cursor-pointer")}
|
||||
className={cn(
|
||||
"absolute",
|
||||
(!isCoordinator || seatState) && "cursor-pointer",
|
||||
state === "waiting" && "opacity-60",
|
||||
)}
|
||||
style={{ left: n.x, top: n.y, width: NODE_W, height: NODE_H }}
|
||||
onPointerDown={(e) => e.stopPropagation()}
|
||||
onClick={() => {
|
||||
if (isCoordinator) return;
|
||||
if (isCoordinator && !seatState) return;
|
||||
// 全屏时先退出(详情抽屉 z-50 会被 z-[100] 全屏层盖住),再打开抽屉。
|
||||
if (fullscreen) setFullscreen(false);
|
||||
onNodeClick?.(n.id, n.name);
|
||||
@@ -339,9 +382,15 @@ export function ChainFlowDiagram({ stages, onNodeClick, className }: ChainFlowDi
|
||||
isCoordinator
|
||||
? "border-border bg-primary/[0.04]"
|
||||
: "border-border hover:-translate-y-0.5 hover:shadow-[0_8px_22px_rgba(15,23,42,0.10)]",
|
||||
state === "running" && "border-amber-400/80 cfd-running-node",
|
||||
state === "failed" && "border-red-500/70",
|
||||
)}
|
||||
// 左侧 4px 彩色描边:内联上色,避免被 border-border 的四边色覆盖。
|
||||
style={{ borderLeftColor: nc.hex, borderLeftWidth: 4 }}
|
||||
style={{
|
||||
borderLeftColor: nc.hex,
|
||||
borderLeftWidth: 4,
|
||||
...(state === "running" ? { boxShadow: "0 0 0 3px rgba(245,158,11,0.15)" } : {}),
|
||||
}}
|
||||
>
|
||||
{/* 上:头像 + 名称 + 阶段徽标 + 角色行 */}
|
||||
<div className="flex items-start gap-2 overflow-hidden">
|
||||
@@ -359,13 +408,34 @@ export function ChainFlowDiagram({ stages, onNodeClick, className }: ChainFlowDi
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* 下:身份 + Ready 心跳条 */}
|
||||
{/* 下:身份 + 状态行(回放模式显示执行状态,否则 Ready 心跳条) */}
|
||||
<div className="flex items-center justify-between border-t border-border/60 pt-1 text-[8px] text-muted-foreground">
|
||||
<span className="truncate">{isCoordinator ? "总控协调核心" : "智能体席位"}</span>
|
||||
<span className="ml-1.5 flex shrink-0 items-center gap-1 rounded bg-muted px-1 py-0.5 font-medium text-primary">
|
||||
<span className="size-1 rounded-full bg-emerald-500" />
|
||||
Ready
|
||||
</span>
|
||||
{state && stateLabel ? (
|
||||
<span
|
||||
className={cn(
|
||||
"ml-1.5 flex shrink-0 items-center gap-1 rounded px-1 py-0.5 font-medium",
|
||||
stateStyle,
|
||||
)}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"size-1.5 rounded-full",
|
||||
state === "done" && "bg-emerald-500",
|
||||
state === "running" && "animate-pulse bg-amber-500",
|
||||
state === "failed" && "bg-red-500",
|
||||
state === "waiting" && "bg-muted-foreground/60",
|
||||
)}
|
||||
/>
|
||||
{stateLabel}
|
||||
{stateSeconds != null && state !== "waiting" ? ` · ${stateSeconds}s` : ""}
|
||||
</span>
|
||||
) : (
|
||||
<span className="ml-1.5 flex shrink-0 items-center gap-1 rounded bg-muted px-1 py-0.5 font-medium text-primary">
|
||||
<span className="size-1 rounded-full bg-emerald-500" />
|
||||
Ready
|
||||
</span>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -445,22 +515,33 @@ export function ChainFlowDiagram({ stages, onNodeClick, className }: ChainFlowDi
|
||||
style={{ width: mmW, height: mmH }}
|
||||
onClick={onMinimapClick}
|
||||
>
|
||||
{/* 节点缩略块 */}
|
||||
{layout.allNodes.map((n) => (
|
||||
<div
|
||||
key={n.id}
|
||||
className={cn(
|
||||
"absolute rounded-[1px]",
|
||||
n.id === COORDINATOR_ID ? "bg-primary/70" : "bg-foreground/35",
|
||||
)}
|
||||
style={{
|
||||
left: n.x * mmScale,
|
||||
top: n.y * mmScale,
|
||||
width: NODE_W * mmScale,
|
||||
height: NODE_H * mmScale,
|
||||
}}
|
||||
/>
|
||||
))}
|
||||
{/* 节点缩略块(回放模式按状态着色) */}
|
||||
{layout.allNodes.map((n) => {
|
||||
const state = n.id === COORDINATOR_ID ? null : seatStates?.[n.id]?.state ?? null;
|
||||
return (
|
||||
<div
|
||||
key={n.id}
|
||||
className={cn(
|
||||
"absolute rounded-[1px]",
|
||||
n.id === COORDINATOR_ID
|
||||
? "bg-primary/70"
|
||||
: state === "done"
|
||||
? "bg-emerald-500/70"
|
||||
: state === "running"
|
||||
? "bg-amber-500/80"
|
||||
: state === "failed"
|
||||
? "bg-red-500/80"
|
||||
: "bg-foreground/35",
|
||||
)}
|
||||
style={{
|
||||
left: n.x * mmScale,
|
||||
top: n.y * mmScale,
|
||||
width: NODE_W * mmScale,
|
||||
height: NODE_H * mmScale,
|
||||
}}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
{/* 当前视口框 */}
|
||||
<div
|
||||
className="absolute border-2 border-primary bg-primary/10"
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
import { renderToStaticMarkup } from "react-dom/server";
|
||||
|
||||
import { MessageStepsCard, type BubbleStep } from "./MessageStepsCard";
|
||||
|
||||
const beginStep: BubbleStep = {
|
||||
id: "begin-1",
|
||||
key: "tool_calling:begin_write_file",
|
||||
label: "使用 begin_write_file 工具",
|
||||
ts: "10:00",
|
||||
args: {
|
||||
description: "准备报告",
|
||||
path: "/mnt/user-data/outputs/internal.md",
|
||||
},
|
||||
};
|
||||
|
||||
test("roundtable renders nothing for a lone begin_write_file control step", () => {
|
||||
assert.equal(renderToStaticMarkup(<MessageStepsCard steps={[beginStep]} />), "");
|
||||
});
|
||||
|
||||
test("roundtable keeps ordinary streaming status beside a hidden control step", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<MessageStepsCard
|
||||
steps={[
|
||||
beginStep,
|
||||
{
|
||||
id: "streaming-1",
|
||||
key: "streaming:",
|
||||
label: "正在生成正文",
|
||||
ts: "10:01",
|
||||
},
|
||||
]}
|
||||
streaming
|
||||
/>,
|
||||
);
|
||||
|
||||
assert.doesNotMatch(html, /begin_write_file|internal\.md|准备报告/);
|
||||
assert.match(html, /正在生成正文/);
|
||||
});
|
||||
|
||||
test("roundtable hides begin_write_file without hiding a real write_file step", () => {
|
||||
const html = renderToStaticMarkup(
|
||||
<MessageStepsCard
|
||||
steps={[
|
||||
beginStep,
|
||||
{
|
||||
id: "write-1",
|
||||
key: "tool_calling:write_file",
|
||||
label: "写入文件",
|
||||
ts: "10:01",
|
||||
args: {
|
||||
description: "生成正式报告",
|
||||
path: "/mnt/user-data/outputs/report.md",
|
||||
},
|
||||
},
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
|
||||
assert.doesNotMatch(html, /begin_write_file|internal\.md|准备报告/);
|
||||
assert.match(html, /生成正式报告/);
|
||||
assert.match(html, /report\.md/);
|
||||
});
|
||||
@@ -22,6 +22,7 @@ import {
|
||||
ChainOfThoughtStep,
|
||||
} from "@/components/ai-elements/chain-of-thought";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { isInternalToolStepKey } from "@/core/tools/visibility";
|
||||
import { collectRoundtableDeliverablePaths } from "@/roundtable-planning/lib/streaming-artifacts";
|
||||
import { cn } from "@/lib/utils";
|
||||
import {
|
||||
@@ -65,23 +66,26 @@ export function MessageStepsCard({
|
||||
onArtifactStepClick,
|
||||
resolveAgentName,
|
||||
}: MessageStepsCardProps) {
|
||||
const visibleSteps = steps.filter((step) => !isInternalToolStepKey(step.key));
|
||||
// 把步骤拆成「工具调用」与「思考过程」两类 —— 与主聊天 MessageGroup 的 `lastToolCallStep` /
|
||||
// `lastReasoningStep` 划分对齐。
|
||||
const toolSteps = steps.filter(isToolStep);
|
||||
const toolSteps = visibleSteps.filter(isToolStep);
|
||||
const lastToolStep = toolSteps[toolSteps.length - 1];
|
||||
const priorToolSteps =
|
||||
lastToolStep && toolSteps.length > 1 ? toolSteps.slice(0, -1) : [];
|
||||
|
||||
// 末尾若是非工具步骤(streaming/connecting/tool_result),作为「思考中」尾标签。
|
||||
// 找到最后一个工具步骤之后的所有步骤;若没有工具步骤,则全部都算思考。
|
||||
const lastToolIdx = lastToolStep ? steps.lastIndexOf(lastToolStep) : -1;
|
||||
const trailingReasoning = steps.slice(lastToolIdx + 1).filter((s) => !isToolStep(s));
|
||||
const lastToolIdx = lastToolStep ? visibleSteps.lastIndexOf(lastToolStep) : -1;
|
||||
const trailingReasoning = visibleSteps
|
||||
.slice(lastToolIdx + 1)
|
||||
.filter((s) => !isToolStep(s));
|
||||
const lastReasoning = trailingReasoning[trailingReasoning.length - 1];
|
||||
|
||||
const [showAbove, setShowAbove] = useState<boolean>(false);
|
||||
|
||||
// 没有任何步骤 —— 不渲染卡(由 caller 决定是否还要其他占位)。
|
||||
if (steps.length === 0) return null;
|
||||
if (visibleSteps.length === 0) return null;
|
||||
|
||||
// 只有一种「思考」尾标签、没有任何工具调用 —— 直接渲染一行小灯泡,不用大卡。
|
||||
// 这样避免「调度中 / 已连接」这类瞬时阶段被搞成完整的折叠卡。
|
||||
|
||||
@@ -34,6 +34,8 @@ export interface PersonaDrawerProps {
|
||||
selectedModel: string;
|
||||
availableModels: ModelOption[];
|
||||
modelsLoading: boolean;
|
||||
/** 席位 → 业务链配置的「产物提交 position」(小写 agent_id / 席位名 → 值);缺省不展示该行。 */
|
||||
seatArtifactPositions?: Record<string, number>;
|
||||
onClose: () => void;
|
||||
onSave: (id: number) => void;
|
||||
}
|
||||
@@ -66,11 +68,16 @@ export function PersonaDrawer({
|
||||
selectedModel,
|
||||
availableModels,
|
||||
modelsLoading,
|
||||
seatArtifactPositions,
|
||||
onClose,
|
||||
onSave,
|
||||
}: PersonaDrawerProps) {
|
||||
const cfg = agentConfigs[seatId];
|
||||
const roleName = roles.find((r) => r.id === seatId)?.name ?? "专家智能体";
|
||||
const roleEntry = roles.find((r) => r.id === seatId);
|
||||
const roleName = roleEntry?.name ?? "专家智能体";
|
||||
// 该席位在业务链上配置的「产物提交 position」——提交过程产物时传给外部任务系统。
|
||||
const lookupKey = roleEntry?.agentId?.trim().toLowerCase() || roleName.trim().toLowerCase();
|
||||
const artifactPosition = lookupKey ? seatArtifactPositions?.[lookupKey] : undefined;
|
||||
|
||||
return (
|
||||
<div className="mx-6 mb-4 p-4.5 bg-gradient-to-r from-[var(--brand-200)]/50 via-[var(--brand-200)]/15 to-white border-2 border-primary rounded-2xl shadow-[0_8px_30px_rgba(245,34,45,0.06)] relative animate-fade-in">
|
||||
@@ -153,6 +160,22 @@ export function PersonaDrawer({
|
||||
</select>
|
||||
</div>
|
||||
|
||||
{seatArtifactPositions && (
|
||||
<div className="space-y-1">
|
||||
<label className="text-[9px] font-black text-slate-500 uppercase tracking-wider block">
|
||||
产物提交 position
|
||||
</label>
|
||||
<div
|
||||
className="w-full bg-white border border-slate-200 rounded-xl px-2.5 py-1.5 text-xs font-bold font-mono"
|
||||
title="该席位提交过程产物时传给外部任务系统的 position 值(业务链条里逐席位配置)"
|
||||
>
|
||||
{typeof artifactPosition === "number"
|
||||
? artifactPosition
|
||||
: <span className="text-slate-400 font-sans">未配置(提交按 0)</span>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-1">
|
||||
<div className="flex items-center justify-between text-[9px] font-black text-slate-500">
|
||||
<span>随机创造性倾向 (Temp)</span>
|
||||
|
||||
@@ -115,6 +115,8 @@ export interface Step2PanelProps {
|
||||
agentConfigs: Record<number, AgentConfig>;
|
||||
selectedAgentId: number | null;
|
||||
roles: RoleEntry[];
|
||||
/** 席位 → 业务链配置的「产物提交 position」(小写 agent_id / 席位名 → 值);缺省不展示。 */
|
||||
seatArtifactPositions?: Record<string, number>;
|
||||
// ─── 按席位筛选会商记录(状态在页面层,与左侧角色卡片共用)──────────────
|
||||
/** 当前筛选标识;null = 显示全部。 */
|
||||
seatFilter: SeatFilter | null;
|
||||
@@ -187,6 +189,7 @@ export function Step2Panel(props: Step2PanelProps) {
|
||||
agentConfigs,
|
||||
selectedAgentId,
|
||||
roles,
|
||||
seatArtifactPositions,
|
||||
seatFilter,
|
||||
setSeatFilter,
|
||||
parallelBatch,
|
||||
@@ -580,6 +583,7 @@ export function Step2Panel(props: Step2PanelProps) {
|
||||
selectedModel={selectedModel}
|
||||
availableModels={availableModels}
|
||||
modelsLoading={modelsLoading}
|
||||
seatArtifactPositions={seatArtifactPositions}
|
||||
onClose={() => setSelectedAgentId(null)}
|
||||
onSave={onSavePersona}
|
||||
/>
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
* - 以「这条气泡是否 **流式过**」作为「它是不是真正的模型生成」的判据:
|
||||
* 只有 `streaming === true` 出现过的气泡才建度量项。用户提问 / 系统播报 /
|
||||
* 澄清回复这类一次性整条推入、从不流式的气泡天然不会有速度胶囊。
|
||||
* - 流式中用滑动窗口算实时 tok/s;流式结束(streaming 翻 false)冻结时长与速率。
|
||||
* - 流式中用滑动窗口算实时 tok/s;窗口内无新字符则掉向 0(不再钉死最后两点)。
|
||||
* - 流式结束(streaming 翻 false)冻结时长与全程平均速率。
|
||||
*
|
||||
* 返回 `Map<id, MessageMetric>`,复用主聊天的 `MessageMetric` 形状,
|
||||
* 以便直接喂给同一个 `SpeedPill`。
|
||||
@@ -16,6 +17,14 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
|
||||
import type { MessageMetric } from "@/components/workspace/messages/use-message-metrics";
|
||||
import {
|
||||
GENERATION_IDLE_MS,
|
||||
SAMPLE_THROTTLE_MS,
|
||||
charsToTokensPerSec,
|
||||
pushSpeedSample,
|
||||
rollingTokensPerSec,
|
||||
type SpeedSample,
|
||||
} from "@/components/workspace/messages/speed-metrics";
|
||||
|
||||
/** 本 hook 需要的最小气泡形状(Step 1/2/3 的消息类型都满足)。 */
|
||||
export interface SpeedTrackableMessage {
|
||||
@@ -24,18 +33,11 @@ export interface SpeedTrackableMessage {
|
||||
streaming?: boolean;
|
||||
}
|
||||
|
||||
/** 两字符 ≈ 一 token —— 与主聊天 / 站内其它处保持一致的粗估。 */
|
||||
const CHARS_PER_TOKEN = 2;
|
||||
|
||||
/** 流式期间的采样节流。 */
|
||||
const SAMPLE_THROTTLE_MS = 60;
|
||||
|
||||
type Sample = { at: number; chars: number };
|
||||
|
||||
type TimingEntry = {
|
||||
firstSeenAt: number;
|
||||
endedAt: number | null;
|
||||
samples: Sample[];
|
||||
lastGrewAt: number;
|
||||
samples: SpeedSample[];
|
||||
lastChars: number;
|
||||
};
|
||||
|
||||
@@ -69,6 +71,7 @@ export function useDialogueSpeedMetrics(
|
||||
entry = {
|
||||
firstSeenAt: now,
|
||||
endedAt: null,
|
||||
lastGrewAt: now,
|
||||
samples: [{ at: now, chars }],
|
||||
lastChars: chars,
|
||||
};
|
||||
@@ -79,19 +82,20 @@ export function useDialogueSpeedMetrics(
|
||||
const chars = contentLength(dialogue);
|
||||
if (streaming) {
|
||||
const grew = chars !== entry.lastChars;
|
||||
if (grew && now - lastSampleAtRef.current >= SAMPLE_THROTTLE_MS) {
|
||||
entry.samples.push({ at: now, chars });
|
||||
entry.lastChars = chars;
|
||||
if (entry.samples.length > 256) {
|
||||
entry.samples.splice(0, entry.samples.length - 256);
|
||||
if (grew) {
|
||||
entry.lastGrewAt = now;
|
||||
if (now - lastSampleAtRef.current >= SAMPLE_THROTTLE_MS) {
|
||||
pushSpeedSample(entry.samples, now, chars);
|
||||
lastSampleAtRef.current = now;
|
||||
}
|
||||
lastSampleAtRef.current = now;
|
||||
} else if (grew) {
|
||||
entry.lastChars = chars;
|
||||
}
|
||||
if (entry.endedAt != null) {
|
||||
entry.endedAt = null;
|
||||
}
|
||||
} else if (entry.endedAt === null) {
|
||||
// 流式结束 → 冻结时长,并以最终内容长度收口。
|
||||
entry.endedAt = now;
|
||||
// 流式结束 → 冻结到最后一次出字,不含结束后的等待。
|
||||
entry.endedAt = entry.lastGrewAt;
|
||||
entry.lastChars = chars;
|
||||
}
|
||||
}
|
||||
@@ -99,7 +103,7 @@ export function useDialogueSpeedMetrics(
|
||||
setTick((v) => v + 1);
|
||||
}, [dialogues]);
|
||||
|
||||
// 仍有气泡在流式时慢速 tick,让实时时长 / 速率平滑刷新。
|
||||
// 仍有气泡在流式时慢速 tick,让实时时长 / 停顿回落平滑刷新。
|
||||
const anyStreaming = dialogues.some((d) => d.streaming === true);
|
||||
useEffect(() => {
|
||||
if (!anyStreaming) return;
|
||||
@@ -118,30 +122,20 @@ export function useDialogueSpeedMetrics(
|
||||
const durationMs = Math.max(0, endedAt - entry.firstSeenAt);
|
||||
|
||||
let tokensPerSec = 0;
|
||||
if (isActive && entry.samples.length >= 2) {
|
||||
// 滑动窗口:取最近 ~1.5s 的样本,反映当前速度而非全程平均。
|
||||
const samples = entry.samples;
|
||||
let start = samples.findIndex((s) => s.at >= now - 1500);
|
||||
if (start === -1) start = samples.length - 2;
|
||||
if (start < 0) start = 0;
|
||||
const head = samples[start];
|
||||
const tail = samples[samples.length - 1];
|
||||
if (head && tail) {
|
||||
const elapsedMs = tail.at - head.at;
|
||||
const chars = Math.max(0, tail.chars - head.chars);
|
||||
if (elapsedMs > 0) {
|
||||
tokensPerSec = ((chars / elapsedMs) * 1000) / CHARS_PER_TOKEN;
|
||||
}
|
||||
}
|
||||
let isPaused = false;
|
||||
if (isActive) {
|
||||
tokensPerSec = rollingTokensPerSec(entry.samples, entry.lastChars, now);
|
||||
isPaused =
|
||||
tokensPerSec <= 0 && now - entry.lastGrewAt >= GENERATION_IDLE_MS;
|
||||
} else if (durationMs > 0) {
|
||||
// 已完成:按全程平均。
|
||||
tokensPerSec = ((entry.lastChars / durationMs) * 1000) / CHARS_PER_TOKEN;
|
||||
tokensPerSec = charsToTokensPerSec(entry.lastChars, durationMs);
|
||||
}
|
||||
|
||||
out.set(dialogue.id, {
|
||||
tokensPerSec,
|
||||
durationMs,
|
||||
isActive,
|
||||
isPaused,
|
||||
// 圆桌气泡无 usage_metadata,速率永远是字符估算。
|
||||
fromUsage: false,
|
||||
// 圆桌每条气泡就是一位席位的一次发言,逐条都展示(无需「turn-final」收敛)。
|
||||
|
||||
@@ -55,12 +55,14 @@ function payloadFrom(
|
||||
): TaskProcessReportPayload {
|
||||
const name = target.name?.trim() || fileName(target.path);
|
||||
const agentId = target.agentId?.trim() || target.threadId;
|
||||
// 产物提交 position:优先取业务链里给该席位智能体配置的值,未配置回退默认。
|
||||
const position = config.positionFor?.(target) ?? config.position;
|
||||
return {
|
||||
taskId: config.taskId,
|
||||
agentId,
|
||||
agentName: target.agentName?.trim() || agentId,
|
||||
content,
|
||||
position: config.position,
|
||||
position,
|
||||
reportName: name,
|
||||
submitStatus,
|
||||
};
|
||||
@@ -146,8 +148,11 @@ export function useTaskArtifactSubmission(
|
||||
|
||||
let record = entriesRef.current[key]?.record;
|
||||
let reportId = record?.taskDeliveryId || undefined;
|
||||
const resumedRegistration = Boolean(reportId);
|
||||
if (!reportId) {
|
||||
const receipt = await config.createProcessReport(payloadFrom(config, target, content, 0));
|
||||
// 外部任务系统(8BF)的实际契约:add 接口以 submitStatus=1 直接完成提交,
|
||||
// 返回 {code:200, data:id}。登记即提交,不再走「先落 0 再改 1」两段式。
|
||||
const receipt = await config.createProcessReport(payloadFrom(config, target, content, 1));
|
||||
reportId = receipt.id;
|
||||
const artifact: RoundtableArtifactReference = {
|
||||
threadId: target.threadId,
|
||||
@@ -163,9 +168,11 @@ export function useTaskArtifactSubmission(
|
||||
taskDeliveryId: reportId,
|
||||
artifact,
|
||||
});
|
||||
} else {
|
||||
// 仅历史「已登记未提交」的记录(旧流程登记时 submitStatus=0)需要补一次
|
||||
// update 把外部记录翻成已提交;这条路径失败仍视为提交失败。
|
||||
await config.updateProcessReport(reportId, payloadFrom(config, target, content, 1));
|
||||
}
|
||||
|
||||
await config.updateProcessReport(reportId, payloadFrom(config, target, content, 1));
|
||||
const submitted = await saveRoundtableArtifactSubmission(config.taskId, {
|
||||
submitted: true,
|
||||
taskDeliveryId: reportId,
|
||||
|
||||
@@ -55,6 +55,13 @@ export interface ChainSeat {
|
||||
* 使同一条业务链既能继续用于原会商,也能在岗位协同中按岗位筛选可问答的智能体。
|
||||
*/
|
||||
position_id?: string | null;
|
||||
/**
|
||||
* 该席位提交过程产物时传给外部任务系统的 `position` 值(8BF 会商页用)。
|
||||
* 不同席位智能体对应不同的产物位置,缺省 / null = 提交时回退 0。
|
||||
* 随 `seats` JSON 落库(无需 DB 列,但需在后端 `ChainSeatSchema` 显式声明)。
|
||||
* 注意与 `position_id`(岗位协同的岗位归属)无关。
|
||||
*/
|
||||
artifact_position?: number | null;
|
||||
/**
|
||||
* 该席位在业务链中配置的岗位职责。会商「智能体配置」面板只读展示;
|
||||
* 随 `seats` JSON 落库(无需 DB 列)。空 / 缺省 = 未填写。
|
||||
|
||||
@@ -318,10 +318,17 @@ export function normalizeIntentReadySummary(parsed: unknown): IntentSummary | nu
|
||||
const objective =
|
||||
typeof obj.objective === "string" ? obj.objective.trim() : "";
|
||||
if (!objective) return null;
|
||||
const reportRequirement =
|
||||
obj.report_requirement && typeof obj.report_requirement === "object"
|
||||
? obj.report_requirement
|
||||
: undefined;
|
||||
return {
|
||||
objective,
|
||||
constraints: toStringArray(obj.constraints),
|
||||
assumptions: toStringArray(obj.assumptions),
|
||||
...(reportRequirement
|
||||
? { report_requirement: reportRequirement as IntentSummary["report_requirement"] }
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,14 @@ export interface TaskProcessReportPayload {
|
||||
export interface TaskArtifactSubmissionConfig {
|
||||
/** External task-system id, not the local roundtable draft storage key. */
|
||||
taskId: string;
|
||||
/** 提交产物时传给外部任务系统的默认 position(产物位置)。 */
|
||||
position: number;
|
||||
/**
|
||||
* 按席位智能体解析提交产物的 position(业务链里逐席位配置的「产物提交 position」)。
|
||||
* 入参是 hook 解析后的 target(`agentId` 已归一为席位 agent_id);返回
|
||||
* null / undefined = 该席位未配置,回退 `position` 默认值。
|
||||
*/
|
||||
positionFor?: (target: TaskArtifactTarget) => number | null | undefined;
|
||||
createProcessReport: (payload: TaskProcessReportPayload) => Promise<{ id: string }>;
|
||||
updateProcessReport: (reportId: string, payload: TaskProcessReportPayload) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -697,6 +697,8 @@ export default function BusinessChainEditorPage() {
|
||||
seat_mode: s.seat_mode ?? null,
|
||||
// 岗位协同专用岗位归属:普通圆桌忽略,但保存时必须原样保留。
|
||||
position_id: s.position_id ?? null,
|
||||
// 席位「产物提交 position」:提交过程产物时传给外部任务系统;null = 回退默认 0。
|
||||
artifact_position: s.artifact_position ?? null,
|
||||
// 业务链席位岗位职责:编辑器已不提供输入,保存时原样保留存量值(会商智能体配置面板只读展示)。
|
||||
job_responsibilities: s.job_responsibilities?.trim() || null,
|
||||
};
|
||||
|
||||
@@ -304,9 +304,9 @@ export default function DashboardAgentPage() {
|
||||
const dashPages: DashboardPage[] = useMemo(
|
||||
() => [
|
||||
{ id: "overview", label: desensitizeText("总览"), icon: <Compass className="h-4 w-4" />, content: <SituationOverview data={safeReport} /> },
|
||||
{ id: "enemy", label: desensitizeText("敌情"), icon: <Crosshair className="h-4 w-4" />, content: <EnemyDetail data={safeReport?.enemy} /> },
|
||||
{ id: "ours", label: desensitizeText("我情"), icon: <Shield className="h-4 w-4" />, content: <OurSituation data={safeReport?.ours} /> },
|
||||
{ id: "field", label: desensitizeText("战场环境"), icon: <Mountain className="h-4 w-4" />, content: <EnvironmentDetail data={safeReport?.environment} /> },
|
||||
{ id: "enemy", label: desensitizeText("优先敌情"), icon: <Crosshair className="h-4 w-4" />, content: <EnemyDetail data={safeReport?.enemy} /> },
|
||||
{ id: "ours", label: desensitizeText("重要我情"), icon: <Shield className="h-4 w-4" />, content: <OurSituation data={safeReport?.ours} /> },
|
||||
{ id: "field", label: desensitizeText("特定战场环境"), icon: <Mountain className="h-4 w-4" />, content: <EnvironmentDetail data={safeReport?.environment} /> },
|
||||
{ id: "judge", label: desensitizeText("情况判断"), icon: <Lightbulb className="h-4 w-4" />, content: <Judgement data={safeReport?.judgement} /> },
|
||||
{ id: "decision", label: desensitizeText("决心建议"), icon: <Flag className="h-4 w-4" />, content: <Decision data={safeReport?.decision} /> },
|
||||
{ id: "disposal", label: desensitizeText("处置建议"), icon: <FileText className="h-4 w-4" />, content: <Disposal data={safeReport?.disposal} /> },
|
||||
|
||||
@@ -361,6 +361,11 @@ export default function RoundtablePlanningPage({
|
||||
hideHeaderSettings = false,
|
||||
/** 可选的外部任务过程产物提交适配器(8BF 使用,通用圆桌保持不显示)。 */
|
||||
taskArtifactSubmissionConfig,
|
||||
/**
|
||||
* 席位 → 业务链配置的「产物提交 position」映射(键为小写 agent_id / 席位名)。
|
||||
* 仅用于「智能体配置」抽屉里的只读展示,帮助核对提交产物时会带的 position 值。
|
||||
*/
|
||||
seatArtifactPositions,
|
||||
/**
|
||||
* 第三步的交付范围。普通会商保留报告后的流程图、最终方案/席位列表与可视化大屏;
|
||||
* 8BF 只交付 Markdown 总结报告,避免两个入口互相改变行为。
|
||||
@@ -417,6 +422,8 @@ export default function RoundtablePlanningPage({
|
||||
newTaskLabel?: string;
|
||||
hideHeaderSettings?: boolean;
|
||||
taskArtifactSubmissionConfig?: TaskArtifactSubmissionConfig;
|
||||
/** 席位 → 业务链配置的「产物提交 position」(小写 agent_id / 席位名 → 值),只读展示用。 */
|
||||
seatArtifactPositions?: Record<string, number>;
|
||||
step3Mode?: "full" | "report-only";
|
||||
}) {
|
||||
const { theme } = useTheme();
|
||||
@@ -2614,6 +2621,7 @@ export default function RoundtablePlanningPage({
|
||||
orchestrationPlan={orchestrationPlan}
|
||||
dagNodeStates={step2.dagNodeStates}
|
||||
agentNameToRole={step2.agentNameToRole}
|
||||
seatArtifactPositions={seatArtifactPositions}
|
||||
selectedModel={selectedModel}
|
||||
availableModels={availableModels}
|
||||
modelsLoading={modelsLoading}
|
||||
|
||||
Reference in new issue
Block a user