Commit 337cd100 by Finley Ge Committed by GitHub

fix(workflow): avoid duplicate tool parameter rendering (#7465)

parent d0a890e9
...@@ -74,6 +74,31 @@ type WorkflowUtilsContextValue = { ...@@ -74,6 +74,31 @@ type WorkflowUtilsContextValue = {
errorOutputs: FlowNodeOutputItemType[]; errorOutputs: FlowNodeOutputItemType[];
}; };
}; };
/** 将工具输入和普通节点输入分开,避免 Agent 生成参数在节点内重复渲染。 */
export const splitToolInputsByMode = (inputs: FlowNodeInputItemType[], isTool: boolean) => {
const toolInputs: FlowNodeInputItemType[] = [];
const commonInputs: FlowNodeInputItemType[] = [];
inputs.forEach((item) => {
const normalizedInput = normalizeFlowNodeInputType(item, { isTool });
const isAgentGeneratedInput =
isAgentGeneratedToolInput(normalizedInput) && canInputBeAgentGenerated(normalizedInput);
if (isTool && isAgentGeneratedInput && item.canEdit) {
toolInputs.push(item);
return;
}
commonInputs.push(normalizedInput);
});
return {
toolInputs,
commonInputs
};
};
export const WorkflowUtilsContext = createContext<WorkflowUtilsContextValue>({ export const WorkflowUtilsContext = createContext<WorkflowUtilsContextValue>({
initData: (...args: Parameters<WorkflowUtilsContextValue['initData']>) => { initData: (...args: Parameters<WorkflowUtilsContextValue['initData']>) => {
void args; void args;
...@@ -148,18 +173,7 @@ export const WorkflowUtilsProvider = ({ children }: { children: ReactNode }) => ...@@ -148,18 +173,7 @@ export const WorkflowUtilsProvider = ({ children }: { children: ReactNode }) =>
const splitToolInputs = useCallback( const splitToolInputs = useCallback(
(inputs: FlowNodeInputItemType[], nodeId: string) => { (inputs: FlowNodeInputItemType[], nodeId: string) => {
const isTool = toolNodesMap[nodeId] ?? false; const isTool = toolNodesMap[nodeId] ?? false;
const { toolInputs, commonInputs } = splitToolInputsByMode(inputs, isTool);
const toolInputs: FlowNodeInputItemType[] = [];
const commonInputs: FlowNodeInputItemType[] = [];
inputs.forEach((item) => {
const normalizedInput = normalizeFlowNodeInputType(item, { isTool });
const isAgentGeneratedInput =
isAgentGeneratedToolInput(normalizedInput) && canInputBeAgentGenerated(normalizedInput);
if (isTool && isAgentGeneratedInput && item.canEdit) {
toolInputs.push(item);
}
commonInputs.push(normalizedInput);
});
return { return {
isTool, isTool,
......
import { describe, expect, it } from 'vitest';
import { splitToolInputsByMode } from '@/pageComponents/app/detail/WorkflowComponents/context/workflowUtilsContext';
import { FlowNodeInputTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
describe('splitToolInputsByMode', () => {
it('keeps Agent-generated editable inputs out of common inputs', () => {
const toolInput = {
key: 'query',
label: 'query',
canEdit: true,
toolDescription: 'Search query',
isToolParam: true,
renderTypeList: [FlowNodeInputTypeEnum.reference]
};
const commonInput = {
key: 'url',
label: 'url',
renderTypeList: [FlowNodeInputTypeEnum.reference]
};
const result = splitToolInputsByMode([toolInput, commonInput], true);
expect(result.toolInputs).toEqual([toolInput]);
expect(result.commonInputs.map((input) => input.key)).toEqual(['url']);
});
it('keeps the same input in common inputs when it is not a tool', () => {
const input = {
key: 'query',
label: 'query',
canEdit: true,
toolDescription: 'Search query',
isToolParam: true,
renderTypeList: [FlowNodeInputTypeEnum.reference]
};
const result = splitToolInputsByMode([input], false);
expect(result.toolInputs).toEqual([]);
expect(result.commonInputs).toHaveLength(1);
});
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment