mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 21:13:50 +00:00
fix: get plugin input variables from history (#2255)
This commit is contained in:
@@ -5,6 +5,20 @@ import { FlowNodeTypeEnum } from '../../workflow/node/constant';
|
|||||||
export const getPluginInputsFromStoreNodes = (nodes: StoreNodeItemType[]) => {
|
export const getPluginInputsFromStoreNodes = (nodes: StoreNodeItemType[]) => {
|
||||||
return nodes.find((node) => node.flowNodeType === FlowNodeTypeEnum.pluginInput)?.inputs || [];
|
return nodes.find((node) => node.flowNodeType === FlowNodeTypeEnum.pluginInput)?.inputs || [];
|
||||||
};
|
};
|
||||||
export const getPluginRunContent = (e: { pluginInputs: FlowNodeInputItemType[] }) => {
|
export const getPluginRunContent = ({
|
||||||
return JSON.stringify(e);
|
pluginInputs,
|
||||||
|
variables
|
||||||
|
}: {
|
||||||
|
pluginInputs: FlowNodeInputItemType[];
|
||||||
|
variables: Record<string, any>;
|
||||||
|
}) => {
|
||||||
|
const pluginInputsWithValue = pluginInputs.map((input) => {
|
||||||
|
const { key } = input;
|
||||||
|
const value = variables?.hasOwnProperty(key) ? variables[key] : input.defaultValue;
|
||||||
|
return {
|
||||||
|
...input,
|
||||||
|
value
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return JSON.stringify(pluginInputsWithValue);
|
||||||
};
|
};
|
||||||
|
@@ -31,10 +31,34 @@ const RenderInput = () => {
|
|||||||
);
|
);
|
||||||
}, [pluginInputs]);
|
}, [pluginInputs]);
|
||||||
|
|
||||||
|
const historyFormValues = useMemo(() => {
|
||||||
|
if (histories.length === 0) return undefined;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const inputValueString = histories[0].value[0].text?.content || '[]';
|
||||||
|
return JSON.parse(inputValueString).reduce(
|
||||||
|
(
|
||||||
|
acc: Record<string, any>,
|
||||||
|
{
|
||||||
|
key,
|
||||||
|
value
|
||||||
|
}: {
|
||||||
|
key: string;
|
||||||
|
value: any;
|
||||||
|
}
|
||||||
|
) => ({ ...acc, [key]: value }),
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to parse input value:', error);
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}, [histories]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (isEqual(getValues(), defaultFormValues)) return;
|
if (isEqual(getValues(), defaultFormValues)) return;
|
||||||
reset(defaultFormValues);
|
reset(historyFormValues || defaultFormValues);
|
||||||
}, [defaultFormValues, histories]);
|
}, [defaultFormValues, historyFormValues]);
|
||||||
|
|
||||||
const isDisabledInput = histories.length > 0;
|
const isDisabledInput = histories.length > 0;
|
||||||
|
|
||||||
|
@@ -51,7 +51,7 @@ const PluginRunContextProvider = ({
|
|||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const generatingMessage = useCallback(
|
const generatingMessage = useCallback(
|
||||||
({ event, text = '', status, name, tool, variables }: generatingMessageProps) => {
|
({ event, text = '', status, name, tool }: generatingMessageProps) => {
|
||||||
setHistories((state) =>
|
setHistories((state) =>
|
||||||
state.map((item, index) => {
|
state.map((item, index) => {
|
||||||
if (index !== state.length - 1 || item.obj !== ChatRoleEnum.AI) return item;
|
if (index !== state.length - 1 || item.obj !== ChatRoleEnum.AI) return item;
|
||||||
@@ -170,7 +170,8 @@ const PluginRunContextProvider = ({
|
|||||||
type: ChatItemValueTypeEnum.text,
|
type: ChatItemValueTypeEnum.text,
|
||||||
text: {
|
text: {
|
||||||
content: getPluginRunContent({
|
content: getPluginRunContent({
|
||||||
pluginInputs
|
pluginInputs,
|
||||||
|
variables: e
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -201,7 +201,8 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
|
|||||||
type: ChatItemValueTypeEnum.text,
|
type: ChatItemValueTypeEnum.text,
|
||||||
text: {
|
text: {
|
||||||
content: getPluginRunContent({
|
content: getPluginRunContent({
|
||||||
pluginInputs: getPluginInputsFromStoreNodes(app.modules)
|
pluginInputs: getPluginInputsFromStoreNodes(app.modules),
|
||||||
|
variables
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user