mirror of
https://github.com/labring/FastGPT.git
synced 2025-08-02 20:58:12 +00:00
fix: savechat.feat: extract flow
This commit is contained in:
@@ -139,7 +139,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
|
||||
// }
|
||||
|
||||
// save chat
|
||||
if (typeof chatId === 'string') {
|
||||
if (chatId) {
|
||||
await saveChat({
|
||||
chatId,
|
||||
appId,
|
||||
|
@@ -11,8 +11,7 @@ const NodeAnswer = ({
|
||||
}: NodeProps<FlowModuleItemType>) => {
|
||||
return (
|
||||
<NodeCard minW={'400px'} moduleId={moduleId} {...props}>
|
||||
<Divider text="Input" />
|
||||
<Container>
|
||||
<Container borderTop={'2px solid'} borderTopColor={'myGray.200'}>
|
||||
<RenderInput moduleId={moduleId} onChangeNode={onChangeNode} flowInputList={inputs} />
|
||||
</Container>
|
||||
</NodeCard>
|
||||
|
@@ -55,7 +55,7 @@ const NodeCQNode = ({
|
||||
onChangeNode({
|
||||
moduleId,
|
||||
type: 'outputs',
|
||||
key: agentKey,
|
||||
key: '',
|
||||
value: newOutputVal
|
||||
});
|
||||
}}
|
||||
|
@@ -13,6 +13,8 @@ import RenderOutput from '../render/RenderOutput';
|
||||
import MyIcon from '@/components/Icon';
|
||||
import ExtractFieldModal from '../modules/ExtractFieldModal';
|
||||
import { ContextExtractEnum } from '@/constants/flow/flowField';
|
||||
import SourceHandle from '../render/SourceHandle';
|
||||
import { FlowOutputItemTypeEnum, FlowValueTypeEnum } from '@/constants/flow';
|
||||
|
||||
const NodeExtract = ({
|
||||
data: { inputs, outputs, moduleId, onChangeNode, ...props }
|
||||
@@ -36,7 +38,22 @@ const NodeExtract = ({
|
||||
key: string;
|
||||
value?: ContextExtractAgentItemType[];
|
||||
}) => (
|
||||
<Box>
|
||||
<Box pt={2}>
|
||||
<Box position={'absolute'} top={0} right={0}>
|
||||
<Button
|
||||
variant={'base'}
|
||||
leftIcon={<AddIcon fontSize={'10px'} />}
|
||||
onClick={() =>
|
||||
setEditExtractField({
|
||||
desc: '',
|
||||
key: '',
|
||||
required: true
|
||||
})
|
||||
}
|
||||
>
|
||||
新增字段
|
||||
</Button>
|
||||
</Box>
|
||||
<TableContainer>
|
||||
<Table>
|
||||
<Thead>
|
||||
@@ -49,10 +66,10 @@ const NodeExtract = ({
|
||||
</Thead>
|
||||
<Tbody>
|
||||
{extractKeys.map((item, index) => (
|
||||
<Tr key={index}>
|
||||
<Tr key={index} position={'relative'}>
|
||||
<Td>{item.key}</Td>
|
||||
<Td whiteSpace={'pre-line'} wordBreak={'break-all'}>
|
||||
{item.desc}{' '}
|
||||
{item.desc}
|
||||
</Td>
|
||||
<Td>{item.required ? '✔' : ''}</Td>
|
||||
<Td whiteSpace={'nowrap'}>
|
||||
@@ -70,11 +87,24 @@ const NodeExtract = ({
|
||||
w={'16px'}
|
||||
cursor={'pointer'}
|
||||
onClick={() => {
|
||||
const newInputValue = extractKeys.filter(
|
||||
(extract) => item.key !== extract.key
|
||||
);
|
||||
const newOutputVal = outputs.filter(
|
||||
(output) => output.key !== item.key
|
||||
);
|
||||
|
||||
onChangeNode({
|
||||
moduleId,
|
||||
type: 'inputs',
|
||||
key: ContextExtractEnum.extractKeys,
|
||||
value: extractKeys.filter((extract) => item.key !== extract.key)
|
||||
value: newInputValue
|
||||
});
|
||||
onChangeNode({
|
||||
moduleId,
|
||||
type: 'outputs',
|
||||
key: '',
|
||||
value: newOutputVal
|
||||
});
|
||||
}}
|
||||
/>
|
||||
@@ -84,21 +114,6 @@ const NodeExtract = ({
|
||||
</Tbody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
<Box mt={2} textAlign={'right'}>
|
||||
<Button
|
||||
variant={'base'}
|
||||
leftIcon={<AddIcon fontSize={'10px'} />}
|
||||
onClick={() =>
|
||||
setEditExtractField({
|
||||
desc: '',
|
||||
key: '',
|
||||
required: true
|
||||
})
|
||||
}
|
||||
>
|
||||
新增字段
|
||||
</Button>
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}}
|
||||
@@ -119,21 +134,39 @@ const NodeExtract = ({
|
||||
|
||||
const exists = extracts.find((item) => item.key === editExtractFiled.key);
|
||||
|
||||
if (exists) {
|
||||
onChangeNode({
|
||||
moduleId,
|
||||
type: 'inputs',
|
||||
key: ContextExtractEnum.extractKeys,
|
||||
value: extracts.map((item) => (item.key === editExtractFiled.key ? data : item))
|
||||
});
|
||||
} else {
|
||||
onChangeNode({
|
||||
moduleId,
|
||||
type: 'inputs',
|
||||
key: ContextExtractEnum.extractKeys,
|
||||
value: extracts.concat(data)
|
||||
});
|
||||
}
|
||||
const newInputs = exists
|
||||
? extracts.map((item) => (item.key === editExtractFiled.key ? data : item))
|
||||
: extracts.concat(data);
|
||||
const newOutputs = exists
|
||||
? outputs.map((output) =>
|
||||
output.key === editExtractFiled.key
|
||||
? {
|
||||
...output,
|
||||
key: data.key,
|
||||
label: `提取结果-${data.desc}`
|
||||
}
|
||||
: output
|
||||
)
|
||||
: outputs.concat({
|
||||
key: data.key,
|
||||
label: `提取结果-${data.desc}`,
|
||||
valueType: FlowValueTypeEnum.string,
|
||||
type: FlowOutputItemTypeEnum.source,
|
||||
targets: []
|
||||
});
|
||||
|
||||
onChangeNode({
|
||||
moduleId,
|
||||
type: 'inputs',
|
||||
key: ContextExtractEnum.extractKeys,
|
||||
value: newInputs
|
||||
});
|
||||
onChangeNode({
|
||||
moduleId,
|
||||
type: 'outputs',
|
||||
key: '',
|
||||
value: newOutputs
|
||||
});
|
||||
|
||||
setEditExtractField(undefined);
|
||||
}}
|
||||
|
@@ -35,7 +35,7 @@ export const Label = ({
|
||||
)}
|
||||
{description && (
|
||||
<MyTooltip label={description} forceShow>
|
||||
<QuestionOutlineIcon display={['none', 'inline']} transform={'translateY(-1px)'} ml={1} />
|
||||
<QuestionOutlineIcon display={['none', 'inline']} ml={1} />
|
||||
</MyTooltip>
|
||||
)}
|
||||
</Box>
|
||||
|
@@ -17,14 +17,14 @@ const Label = ({
|
||||
<Flex as={'label'} justifyContent={'right'} alignItems={'center'} position={'relative'}>
|
||||
{description && (
|
||||
<MyTooltip label={description} forceShow>
|
||||
<QuestionOutlineIcon display={['none', 'inline']} transform={'translateY(-1px)'} mr={1} />
|
||||
<QuestionOutlineIcon display={['none', 'inline']} mr={1} />
|
||||
</MyTooltip>
|
||||
)}
|
||||
{children}
|
||||
</Flex>
|
||||
);
|
||||
|
||||
const RenderBody = ({ flowOutputList }: { flowOutputList: FlowOutputItemType[] }) => {
|
||||
const RenderOutput = ({ flowOutputList }: { flowOutputList: FlowOutputItemType[] }) => {
|
||||
return (
|
||||
<>
|
||||
{flowOutputList.map(
|
||||
@@ -44,4 +44,4 @@ const RenderBody = ({ flowOutputList }: { flowOutputList: FlowOutputItemType[] }
|
||||
);
|
||||
};
|
||||
|
||||
export default React.memo(RenderBody);
|
||||
export default RenderOutput;
|
||||
|
@@ -14,8 +14,8 @@ const SourceHandle = ({ handleKey, valueType, ...props }: Props) => {
|
||||
() =>
|
||||
valueType
|
||||
? FlowValueTypeStyle[valueType]
|
||||
: (FlowValueTypeStyle[FlowValueTypeEnum.other] as any),
|
||||
[]
|
||||
: (FlowValueTypeStyle[FlowValueTypeEnum.any] as any),
|
||||
[valueType]
|
||||
);
|
||||
|
||||
return (
|
||||
|
@@ -15,7 +15,7 @@ const TargetHandle = ({ handleKey, valueType, onConnect, ...props }: Props) => {
|
||||
() =>
|
||||
valueType
|
||||
? FlowValueTypeStyle[valueType]
|
||||
: (FlowValueTypeStyle[FlowValueTypeEnum.other] as any),
|
||||
: (FlowValueTypeStyle[FlowValueTypeEnum.any] as any),
|
||||
[]
|
||||
);
|
||||
|
||||
|
@@ -132,7 +132,7 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
|
||||
connected: item.type !== FlowInputItemTypeEnum.target
|
||||
})),
|
||||
outputs: item.data.outputs.map((item) => ({
|
||||
key: item.key,
|
||||
...item,
|
||||
targets: [] as FlowOutputTargetItemType[]
|
||||
}))
|
||||
}));
|
||||
@@ -254,7 +254,11 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
|
||||
title: t('app.Connection is invalid')
|
||||
});
|
||||
}
|
||||
if (sourceType !== targetType) {
|
||||
if (
|
||||
sourceType !== FlowValueTypeEnum.any &&
|
||||
targetType !== FlowValueTypeEnum.any &&
|
||||
sourceType !== targetType
|
||||
) {
|
||||
return toast({
|
||||
status: 'warning',
|
||||
title: t('app.Connection type is different')
|
||||
@@ -280,6 +284,7 @@ const AppEdit = ({ app, fullScreen, onFullScreen }: Props) => {
|
||||
|
||||
const { mutate: onclickSave, isLoading } = useRequest({
|
||||
mutationFn: () => {
|
||||
console.log(flow2AppModules(), '====');
|
||||
return updateAppDetail(app._id, {
|
||||
modules: flow2AppModules()
|
||||
});
|
||||
|
Reference in New Issue
Block a user