feat: node version (#1484)

* feat: node version tip

* fix

* i18n

* init version

* fix ts

* fix ts

* fix ts
This commit is contained in:
heheer
2024-05-14 23:26:03 +08:00
committed by GitHub
parent b779e2806d
commit fb04889a31
37 changed files with 185 additions and 20 deletions

View File

@@ -31,6 +31,12 @@
"To Chat": "Go to Chat",
"To Settings": "View Details",
"Variable Key Repeat Tip": "Variable key is duplicate",
"app": {
"modules": {
"click to update": "click to update",
"has new version": "has new version"
}
},
"module": {
"Combine Modules": "Combine Modules",
"Custom Title Tip": "This title will be displayed during the conversation",

View File

@@ -30,6 +30,12 @@
"To Chat": "前去对话",
"To Settings": "查看详情",
"Variable Key Repeat Tip": "变量 key 重复",
"app": {
"modules": {
"click to update": "点击更新",
"has new version": "有新版本"
}
},
"module": {
"Combine Modules": "组合模块",
"Custom Title Tip": "该标题名字会展示在对话过程中",

View File

@@ -18,11 +18,14 @@ import { ResponseBox } from '@/components/ChatBox/WholeResponseModal';
import EmptyTip from '@fastgpt/web/components/common/EmptyTip';
import { getPreviewPluginModule } from '@/web/core/plugin/api';
import { getErrText } from '@fastgpt/global/common/error/utils';
import { storeNode2FlowNode } from '@/web/core/workflow/utils';
import { storeNode2FlowNode, updateFlowNodeVersion } from '@/web/core/workflow/utils';
import { getNanoid } from '@fastgpt/global/common/string/tools';
import { useContextSelector } from 'use-context-selector';
import { WorkflowContext } from '../../../context';
import { useI18n } from '@/web/context/I18n';
import { moduleTemplatesFlat } from '@fastgpt/global/core/workflow/template/constants';
import { QuestionOutlineIcon } from '@chakra-ui/icons';
import MyTooltip from '@/components/MyTooltip';
type Props = FlowNodeItemType & {
children?: React.ReactNode | React.ReactNode[] | string;
@@ -65,6 +68,7 @@ const NodeCard = (props: Props) => {
const setHoverNodeId = useContextSelector(WorkflowContext, (v) => v.setHoverNodeId);
const onUpdateNodeError = useContextSelector(WorkflowContext, (v) => v.onUpdateNodeError);
const onChangeNode = useContextSelector(WorkflowContext, (v) => v.onChangeNode);
const onResetNode = useContextSelector(WorkflowContext, (v) => v.onResetNode);
// custom title edit
const { onOpenModal: onOpenCustomTitleModal, EditModal: EditTitleModal } = useEditTitle({
@@ -77,12 +81,21 @@ const NodeCard = (props: Props) => {
[isTool, nodeList]
);
const node = nodeList.find((node) => node.nodeId === nodeId);
const template = moduleTemplatesFlat.find((item) => item.flowNodeType === node?.flowNodeType);
const hasNewVersion = useMemo(() => {
return (
template?.flowNodeType !== FlowNodeTypeEnum.pluginModule &&
node?.version !== template?.version
);
}, [node?.version, template?.flowNodeType, template?.version]);
/* Node header */
const Header = useMemo(() => {
return (
<Box position={'relative'}>
{/* debug */}
<Box className="custom-drag-handle" px={4} py={3}>
<Box px={4} py={3}>
{/* tool target handle */}
{showToolHandle && <ToolTargetHandle nodeId={nodeId} />}
@@ -123,6 +136,33 @@ const NodeCard = (props: Props) => {
}}
/>
)}
<Box flex={1} />
{hasNewVersion && (
<MyTooltip label={appT('app.modules.click to update')}>
<Button
bg={'yellow.50'}
color={'yellow.600'}
variant={'ghost'}
h={8}
px={2}
rounded={'6px'}
fontSize={'xs'}
fontWeight={'medium'}
cursor={'pointer'}
_hover={{ bg: 'yellow.100' }}
onClick={() => {
if (!node || !template) return;
onResetNode({
id: nodeId,
node: updateFlowNodeVersion(node, template)
});
}}
>
<Box>{appT('app.modules.has new version')}</Box>
<QuestionOutlineIcon ml={1} />
</Button>
</MyTooltip>
)}
</Flex>
<MenuRender
nodeId={nodeId}
@@ -141,13 +181,17 @@ const NodeCard = (props: Props) => {
t,
name,
menuForbid,
hasNewVersion,
pluginId,
flowNodeType,
intro,
onOpenCustomTitleModal,
onChangeNode,
toast,
appT
appT,
node,
template,
onResetNode
]);
return (
@@ -236,7 +280,8 @@ const MenuRender = React.memo(function MenuRender({
inputs: node.data.inputs,
outputs: node.data.outputs,
showStatus: node.data.showStatus,
pluginId: node.data.pluginId
pluginId: node.data.pluginId,
version: node.data.version
};
return state.concat(
storeNode2FlowNode({
@@ -250,7 +295,8 @@ const MenuRender = React.memo(function MenuRender({
showStatus: template.showStatus,
pluginId: template.pluginId,
inputs: template.inputs,
outputs: template.outputs
outputs: template.outputs,
version: template.version
}
})
);
@@ -265,7 +311,7 @@ const MenuRender = React.memo(function MenuRender({
},
[setEdges, setNodes]
);
const onclickSyncVersion = useCallback(async () => {
const onClickSyncVersion = useCallback(async () => {
if (!pluginId) return;
try {
setLoading(true);
@@ -310,7 +356,7 @@ const MenuRender = React.memo(function MenuRender({
icon: 'common/refreshLight',
label: t('plugin.Synchronous version'),
variant: 'whiteBase',
onClick: onOpenConfirmSync(onclickSyncVersion)
onClick: onOpenConfirmSync(onClickSyncVersion)
}
]
: []),
@@ -362,21 +408,21 @@ const MenuRender = React.memo(function MenuRender({
</>
);
}, [
ConfirmDeleteModal,
ConfirmSyncModal,
DebugInputModal,
flowNodeType,
menuForbid?.copy,
menuForbid?.debug,
menuForbid?.copy,
menuForbid?.delete,
t,
flowNodeType,
onOpenConfirmSync,
onClickSyncVersion,
onOpenConfirmDeleteNode,
ConfirmSyncModal,
ConfirmDeleteModal,
DebugInputModal,
openDebugNode,
nodeId,
onCopyNode,
onDelNode,
onOpenConfirmDeleteNode,
onOpenConfirmSync,
onclickSyncVersion,
openDebugNode,
t
onDelNode
]);
return Render;

View File

@@ -19,6 +19,7 @@ export const flowNode2StoreNodes = ({
flowNodeType: item.data.flowNodeType,
showStatus: item.data.showStatus,
position: item.position,
version: item.data.version,
inputs: item.data.inputs,
outputs: item.data.outputs,
pluginId: item.data.pluginId

View File

@@ -22,6 +22,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
intro: plugin.intro,
showStatus: true,
isTool: plugin.isTool,
version: '481',
inputs: [],
outputs: []
})) || [];

View File

@@ -47,6 +47,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
name: plugin.name,
intro: plugin.intro,
showStatus: false,
version: '481',
inputs: [],
outputs: []
}));

View File

@@ -39,6 +39,7 @@ export const defaultForm: EditFormType = {
x: 616.4226348688949,
y: -165.05298493910115
},
version: '481',
inputs: [],
outputs: []
},
@@ -52,6 +53,7 @@ export const defaultForm: EditFormType = {
x: 1607.7142331269126,
y: -151.8669210746189
},
version: '481',
inputs: [],
outputs: []
}

View File

@@ -26,6 +26,7 @@ export const appTemplates: (AppItemType & {
x: 531.2422736065552,
y: -486.7611729549753
},
version: '481',
inputs: [
{
key: 'welcomeText',
@@ -88,6 +89,7 @@ export const appTemplates: (AppItemType & {
x: 558.4082376415505,
y: 123.72387429194112
},
version: '481',
inputs: [
{
key: 'userChatInput',
@@ -119,6 +121,7 @@ export const appTemplates: (AppItemType & {
x: 1097.7317280958762,
y: -244.16014496351386
},
version: '481',
inputs: [
{
key: 'model',
@@ -253,6 +256,7 @@ export const appTemplates: (AppItemType & {
x: 496.57560693988853,
y: -490.7611729549753
},
version: '481',
inputs: [
{
key: 'welcomeText',
@@ -332,6 +336,7 @@ export const appTemplates: (AppItemType & {
x: 558.4082376415505,
y: 123.72387429194112
},
version: '481',
inputs: [
{
key: 'userChatInput',
@@ -363,6 +368,7 @@ export const appTemplates: (AppItemType & {
x: 1097.7317280958762,
y: -244.16014496351386
},
version: '481',
inputs: [
{
key: 'model',
@@ -497,6 +503,7 @@ export const appTemplates: (AppItemType & {
x: 531.2422736065552,
y: -486.7611729549753
},
version: '481',
inputs: [
{
key: 'welcomeText',
@@ -559,6 +566,7 @@ export const appTemplates: (AppItemType & {
x: 558.4082376415505,
y: 123.72387429194112
},
version: '481',
inputs: [
{
key: 'userChatInput',
@@ -590,6 +598,7 @@ export const appTemplates: (AppItemType & {
x: 1638.509551404687,
y: -341.0428450861567
},
version: '481',
inputs: [
{
key: 'model',
@@ -709,6 +718,7 @@ export const appTemplates: (AppItemType & {
x: 918.5901682164496,
y: -227.11542247619582
},
version: '481',
inputs: [
{
key: 'datasets',
@@ -821,6 +831,7 @@ export const appTemplates: (AppItemType & {
x: 531.2422736065552,
y: -486.7611729549753
},
version: '481',
inputs: [
{
key: 'welcomeText',
@@ -883,6 +894,7 @@ export const appTemplates: (AppItemType & {
x: 558.4082376415505,
y: 123.72387429194112
},
version: '481',
inputs: [
{
key: 'userChatInput',
@@ -914,6 +926,7 @@ export const appTemplates: (AppItemType & {
x: 2701.1267277679685,
y: -767.8956312653042
},
version: '481',
inputs: [
{
key: 'model',
@@ -1034,6 +1047,7 @@ export const appTemplates: (AppItemType & {
x: 1020.9667229609946,
y: -385.0060974413916
},
version: '481',
inputs: [
{
key: 'model',
@@ -1114,6 +1128,7 @@ export const appTemplates: (AppItemType & {
x: 1874.9167551056487,
y: 434.98431875888207
},
version: '481',
inputs: [
{
key: 'text',
@@ -1139,6 +1154,7 @@ export const appTemplates: (AppItemType & {
x: 1851.010152279949,
y: -613.3555232387284
},
version: '481',
inputs: [
{
key: 'datasets',

View File

@@ -27,6 +27,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 531.2422736065552,
y: -486.7611729549753
},
version: '481',
inputs: [
{
key: NodeInputKeyEnum.welcomeText,
@@ -79,6 +80,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 558.4082376415505,
y: 123.72387429194112
},
version: '481',
inputs: [
{
key: 'userChatInput',
@@ -115,6 +117,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 1106.3238387960757,
y: -350.6030674683474
},
version: '481',
inputs: [
{
key: 'model',
@@ -247,6 +250,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 1638.509551404687,
y: -341.0428450861567
},
version: '481', // [FlowNodeTypeEnum.chatNode]
inputs: [
{
key: 'model',
@@ -366,6 +370,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 918.5901682164496,
y: -227.11542247619582
},
version: '481',
inputs: [
{
key: 'datasets',
@@ -484,6 +489,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 500,
y: 545
},
version: '481',
inputs: [
{
key: 'datasets',
@@ -597,6 +603,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 500 + 500 * (i + 1),
y: 545
},
version: tool.version,
inputs: tool.inputs,
outputs: tool.outputs
}
@@ -625,6 +632,7 @@ export function form2AppWorkflow(data: AppSimpleEditFormType): WorkflowType {
x: 1062.1738942532802,
y: -223.65033022650476
},
version: '481',
inputs: [
{
key: 'model',

View File

@@ -39,6 +39,7 @@ export const getGlobalVariableNode = (nodes: FlowNodeItemType[], t: TFunction) =
intro: '',
unique: true,
forbidDelete: true,
version: '481',
inputs: [],
outputs: []
};
@@ -418,6 +419,7 @@ export const v1Workflow2V2 = (
pluginId,
pluginType: node.pluginType,
parentId: node.parentId,
version: 'v2.0',
inputs,
outputs

View File

@@ -24,7 +24,11 @@ import {
} from '@fastgpt/global/core/workflow/utils';
import { getSystemVariables } from '../app/utils';
import { TFunction } from 'next-i18next';
import { ReferenceValueProps } from '@fastgpt/global/core/workflow/type/io';
import {
FlowNodeInputItemType,
FlowNodeOutputItemType,
ReferenceValueProps
} from '@fastgpt/global/core/workflow/type/io';
import { IfElseListItemType } from '@fastgpt/global/core/workflow/template/system/ifElse/type';
import { VariableConditionEnum } from '@fastgpt/global/core/workflow/template/system/ifElse/constant';
@@ -87,7 +91,8 @@ export const storeNode2FlowNode = ({
...templateOutput,
value: storeOutput.value
};
})
}),
version: storeNode.version || '481'
};
return {
@@ -298,3 +303,34 @@ export const getWorkflowGlobalVariables = (
return [...globalVariables, ...systemVariables];
};
export type CombinedItemType = Partial<FlowNodeInputItemType> & Partial<FlowNodeOutputItemType>;
export const updateFlowNodeVersion = (
node: FlowNodeItemType,
template: FlowNodeTemplateType
): FlowNodeItemType => {
function updateArrayBasedOnTemplate<T extends FlowNodeInputItemType | FlowNodeOutputItemType>(
nodeArray: T[],
templateArray: T[]
): T[] {
return templateArray.map((templateItem) => {
const nodeItem = nodeArray.find((item) => item.key === templateItem.key);
if (nodeItem) {
return { ...templateItem, ...nodeItem } as T;
}
return { ...templateItem };
});
}
const updatedNode: FlowNodeItemType = { ...node, ...template, name: node.name };
if (node.inputs && template.inputs) {
updatedNode.inputs = updateArrayBasedOnTemplate(node.inputs, template.inputs);
}
if (node.outputs && template.outputs) {
updatedNode.outputs = updateArrayBasedOnTemplate(node.outputs, template.outputs);
}
return updatedNode;
};