Refactor workflow routing and greeting management in Brain classes

- Update WorkflowBrain to handle greeting playback more effectively, ensuring that the initial greeting completes before transitioning to the first node.
- Introduce new methods for managing greeting states and conditions, enhancing the interaction flow for user turns.
- Refactor WorkflowLLMRouter to improve routing logic and ensure proper handling of conditional paths.
- Enhance tests to verify the correct behavior of greeting management and routing under various scenarios, including waiting for audio playback to finish.
- Update frontend components to reflect changes in edge handling and improve user experience in workflow configurations.
This commit is contained in:
Xin Wang
2026-07-17 22:01:42 +08:00
parent 34c0d12d2a
commit 162a3d8bec
15 changed files with 826 additions and 147 deletions

View File

@@ -27,11 +27,11 @@ import type { ExpressionRule, WorkflowEdgeData } from "../specs";
export function EdgeSettingsPanel({
edge,
sourceType,
hasOtherDefaultPath,
onChange,
}: {
edge: Edge;
sourceType?: string;
hasOtherDefaultPath: boolean;
onChange: (patch: WorkflowEdgeData) => void;
}) {
const data = (edge.data ?? { mode: "always", priority: 10 }) as WorkflowEdgeData;
@@ -100,15 +100,19 @@ export function EdgeSettingsPanel({
<SectionCard
icon={<GitBranch size={15} />}
title="路由方式"
description="选择由 Agent 判断、动态变量表达式判断,或作为确定性默认路径"
description="每个节点最多一条默认路径,也可以配置多条条件路径"
>
<NodeSelect
label="判断方式"
label="条件类型"
value={mode}
options={[
...(sourceType === "agent" ? [{ value: "llm", label: "LLM 判断" }] : []),
{ value: "expression", label: "动态变量表达式" },
{ value: "always", label: "默认路径" },
{
value: "always",
label: "默认路径",
disabled: mode !== "always" && hasOtherDefaultPath,
},
{ value: "llm", label: "大模型判断" },
{ value: "expression", label: "表达式" },
]}
onChange={(value) => {
const nextMode =
@@ -118,6 +122,11 @@ export function EdgeSettingsPanel({
}}
allowNone={false}
/>
{mode !== "always" && hasOtherDefaultPath && (
<span className="-mt-1 block text-xs text-muted-foreground">
使
</span>
)}
<label className="block">
<div className="mb-1.5 text-sm font-medium text-foreground">
@@ -133,7 +142,7 @@ export function EdgeSettingsPanel({
className="border-hairline-strong bg-background text-foreground"
/>
<span className="mt-1.5 block text-xs text-muted-foreground">
</span>
</label>
</SectionCard>
@@ -333,5 +342,3 @@ export function EdgeSettingsPanel({
</div>
);
}

View File

@@ -201,7 +201,11 @@ export function NodeSelect({
<SelectContent className="border-hairline bg-popover text-popover-foreground">
{allowNone && <SelectItem value={NONE}>{noneLabel}</SelectItem>}
{options.map((option) => (
<SelectItem key={option.value} value={option.value}>
<SelectItem
key={option.value}
value={option.value}
disabled={option.disabled}
>
{option.label}
</SelectItem>
))}
@@ -211,4 +215,3 @@ export function NodeSelect({
);
}