refactor(workflow): streamline workflow settings management
- Introduced new utility functions `settingsFromWorkflowGraph` and `workflowGraphWithSettings` to encapsulate settings extraction and graph updates. - Updated `useWorkflowEditorState` to utilize the new utility functions for improved clarity and maintainability. - Refactored `AssistantPage` and `WorkflowCanvas` components to leverage the new settings management functions, ensuring consistent handling of workflow settings across the application. - Removed redundant settings handling code, enhancing overall code cleanliness.
This commit is contained in:
@@ -53,6 +53,7 @@ import {
|
||||
type TurnConfig,
|
||||
} from "@/lib/api";
|
||||
import type { WorkflowSettings } from "@/components/workflow/types";
|
||||
import { workflowGraphWithSettings } from "@/components/workflow/graph-settings";
|
||||
import { SectionCard } from "@/components/editor/section-card";
|
||||
import {
|
||||
defaultGraph,
|
||||
@@ -571,7 +572,6 @@ export function AssistantPage(props: AssistantPageProps) {
|
||||
JSON.stringify({
|
||||
name: workflowName,
|
||||
graph: workflowGraph,
|
||||
settings: workflowSettings,
|
||||
dynamicVariableDefinitions: effectiveWorkflowDynamicVariableDefinitions,
|
||||
}),
|
||||
);
|
||||
@@ -721,12 +721,14 @@ export function AssistantPage(props: AssistantPageProps) {
|
||||
graph.settings?.turnConfig ?? assistant.turnConfig,
|
||||
),
|
||||
};
|
||||
// 编辑器会把兼容字段和默认值写回 graph。状态与保存基线必须使用
|
||||
// 同一个规范化结果,否则页面刚打开就会被误判为有未保存改动。
|
||||
const normalizedGraph = workflowGraphWithSettings(graph, wfSettings);
|
||||
setWorkflowName(assistant.name);
|
||||
setWorkflowGraph(graph);
|
||||
setWorkflowSettings(wfSettings);
|
||||
setWorkflowGraph(normalizedGraph);
|
||||
const dynamicVariableDefinitions =
|
||||
activeWorkflowDynamicVariableDefinitions(
|
||||
graph,
|
||||
normalizedGraph,
|
||||
assistant.dynamicVariableDefinitions ?? {},
|
||||
);
|
||||
setWorkflowDynamicVariableDefinitions(
|
||||
@@ -735,8 +737,7 @@ export function AssistantPage(props: AssistantPageProps) {
|
||||
setSavedSnapshot(
|
||||
JSON.stringify({
|
||||
name: assistant.name,
|
||||
graph,
|
||||
settings: wfSettings,
|
||||
graph: normalizedGraph,
|
||||
dynamicVariableDefinitions,
|
||||
}),
|
||||
);
|
||||
@@ -818,7 +819,6 @@ export function AssistantPage(props: AssistantPageProps) {
|
||||
? JSON.stringify({
|
||||
name: workflowName,
|
||||
graph: workflowGraph,
|
||||
settings: workflowSettings,
|
||||
dynamicVariableDefinitions:
|
||||
effectiveWorkflowDynamicVariableDefinitions,
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user