Enhance workflow engine and frontend components with transition speech support
- Introduce edge transition speech functionality in the WorkflowEngine to provide optional speech during node transitions. - Update pipeline execution to utilize the new transition speech feature, enhancing user experience by masking delays during transitions. - Modify frontend components to support transition speech in edge specifications, allowing users to define and edit transition speech for edges. - Refactor edge handling logic in the WorkflowEditor to accommodate the new transition speech field, improving workflow management capabilities.
This commit is contained in:
@@ -120,7 +120,12 @@ function fromFlow(nodes: Node[], edges: Edge[]): WorkflowGraph {
|
||||
id: e.id,
|
||||
source: e.source,
|
||||
target: e.target,
|
||||
data: (e.data as { condition?: string; label?: string }) ?? {},
|
||||
data:
|
||||
(e.data as {
|
||||
condition?: string;
|
||||
label?: string;
|
||||
transition_speech?: string;
|
||||
}) ?? {},
|
||||
})),
|
||||
};
|
||||
}
|
||||
@@ -238,7 +243,14 @@ function Canvas({
|
||||
);
|
||||
|
||||
const updateEdgeData = useCallback(
|
||||
(id: string, patch: { condition?: string; label?: string }) => {
|
||||
(
|
||||
id: string,
|
||||
patch: {
|
||||
condition?: string;
|
||||
label?: string;
|
||||
transition_speech?: string;
|
||||
},
|
||||
) => {
|
||||
setEdges((es) =>
|
||||
es.map((e) =>
|
||||
e.id === id ? { ...e, data: { ...(e.data ?? {}), ...patch } } : e,
|
||||
@@ -677,12 +689,23 @@ function EdgeForm({
|
||||
onDelete,
|
||||
}: {
|
||||
edge: Edge;
|
||||
onSave: (patch: { condition: string; label: string }) => void;
|
||||
onSave: (patch: {
|
||||
condition: string;
|
||||
label: string;
|
||||
transition_speech: string;
|
||||
}) => void;
|
||||
onDelete: () => void;
|
||||
}) {
|
||||
const data = (edge.data ?? {}) as { condition?: string; label?: string };
|
||||
const data = (edge.data ?? {}) as {
|
||||
condition?: string;
|
||||
label?: string;
|
||||
transition_speech?: string;
|
||||
};
|
||||
const [label, setLabel] = useState(data.label ?? "");
|
||||
const [condition, setCondition] = useState(data.condition ?? "");
|
||||
const [transitionSpeech, setTransitionSpeech] = useState(
|
||||
data.transition_speech ?? "",
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -718,6 +741,22 @@ function EdgeForm({
|
||||
className="resize-none border-hairline-strong bg-background text-foreground placeholder:text-muted-soft"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col gap-2">
|
||||
<label className="text-sm font-medium text-foreground">
|
||||
过渡语(可选)
|
||||
</label>
|
||||
<Textarea
|
||||
rows={2}
|
||||
value={transitionSpeech}
|
||||
placeholder="切换到下一节点前先说的一句过渡语,用于掩盖延迟,例如:好的,我帮你转接。"
|
||||
onChange={(e) => setTransitionSpeech(e.target.value)}
|
||||
className="resize-none border-hairline-strong bg-background text-foreground placeholder:text-muted-soft"
|
||||
/>
|
||||
<span className="text-xs text-muted-soft">
|
||||
命中该条件、切换节点的瞬间播报,不写入对话上下文。
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<DialogFooter className="flex-row justify-between sm:justify-between">
|
||||
@@ -729,7 +768,13 @@ function EdgeForm({
|
||||
<Trash2 size={15} />
|
||||
删除连线
|
||||
</Button>
|
||||
<Button onClick={() => onSave({ condition, label })}>保存条件</Button>
|
||||
<Button
|
||||
onClick={() =>
|
||||
onSave({ condition, label, transition_speech: transitionSpeech })
|
||||
}
|
||||
>
|
||||
保存条件
|
||||
</Button>
|
||||
</DialogFooter>
|
||||
</>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user