From 38edb06897f6eb7990726775fb4331f30b469feb Mon Sep 17 00:00:00 2001 From: Joel Date: Fri, 30 Aug 2024 15:21:37 +0800 Subject: [PATCH] feat: list filter output --- web/app/components/workflow/constants.ts | 1 + .../nodes/_base/components/variable/utils.ts | 19 ++++++++++++++++--- .../workflow/nodes/list-filter/types.ts | 4 +++- .../workflow/nodes/list-filter/use-config.ts | 2 ++ 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/web/app/components/workflow/constants.ts b/web/app/components/workflow/constants.ts index c1f94bb91a..cb495f439b 100644 --- a/web/app/components/workflow/constants.ts +++ b/web/app/components/workflow/constants.ts @@ -368,6 +368,7 @@ export const SUPPORT_OUTPUT_VARS_NODE = [ BlockEnum.Start, BlockEnum.LLM, BlockEnum.KnowledgeRetrieval, BlockEnum.Code, BlockEnum.TemplateTransform, BlockEnum.HttpRequest, BlockEnum.Tool, BlockEnum.VariableAssigner, BlockEnum.VariableAggregator, BlockEnum.QuestionClassifier, BlockEnum.ParameterExtractor, BlockEnum.Iteration, + BlockEnum.ListFilter, ] export const LLM_OUTPUT_STRUCT: Var[] = [ diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index b14619e938..7e5a859e42 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -13,6 +13,7 @@ import { VarType as ToolVarType } from '../../../tool/types' import type { ToolNodeType } from '../../../tool/types' import type { ParameterExtractorNodeType } from '../../../parameter-extractor/types' import type { IterationNodeType } from '../../../iteration/types' +import type { ListFilterNodeType } from '../../../list-filter/types' import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types' import type { StartNodeType } from '@/app/components/workflow/nodes/start/types' import type { ConversationVariable, EnvironmentVariable, Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types' @@ -75,6 +76,8 @@ const formatItem = ( ): NodeOutPutVar => { const { id, data } = item + console.log(data.type) + const res: NodeOutPutVar = { nodeId: id, title: data.title, @@ -257,18 +260,21 @@ const formatItem = ( } case BlockEnum.ListFilter: { + if (!(data as ListFilterNodeType).var_type) + break + res.vars = [ { variable: 'result', - type: VarType.array, // TODO dyn value + type: (data as ListFilterNodeType).var_type, }, { variable: 'first_record', - type: VarType.string, // TODO dyn value + type: (data as ListFilterNodeType).item_var_type, }, { variable: 'last_record', - type: VarType.string, // TODO dyn value + type: (data as ListFilterNodeType).item_var_type, }, ] break @@ -1039,6 +1045,13 @@ export const getNodeOutputVars = (node: Node, isChatMode: boolean): ValueSelecto res.push([id, 'output']) break } + + case BlockEnum.ListFilter: { + res.push([id, 'result']) + res.push([id, 'first_record']) + res.push([id, 'last_record']) + break + } } return res diff --git a/web/app/components/workflow/nodes/list-filter/types.ts b/web/app/components/workflow/nodes/list-filter/types.ts index f422e284fe..c778f42d94 100644 --- a/web/app/components/workflow/nodes/list-filter/types.ts +++ b/web/app/components/workflow/nodes/list-filter/types.ts @@ -1,5 +1,5 @@ import type { ComparisonOperator } from '../if-else/types' -import type { CommonNodeType, ValueSelector } from '@/app/components/workflow/types' +import type { CommonNodeType, ValueSelector, VarType } from '@/app/components/workflow/types' export enum OrderBy { ASC = 'asc', @@ -19,6 +19,8 @@ export type Condition = { export type ListFilterNodeType = CommonNodeType & { variable: ValueSelector + var_type: VarType // Cache for the type of output variable + item_var_type: VarType // Cache for the type of output variable filter_by: Condition[] order_by: { enabled: boolean diff --git a/web/app/components/workflow/nodes/list-filter/use-config.ts b/web/app/components/workflow/nodes/list-filter/use-config.ts index 5335d6eced..d80fc3d87d 100644 --- a/web/app/components/workflow/nodes/list-filter/use-config.ts +++ b/web/app/components/workflow/nodes/list-filter/use-config.ts @@ -77,6 +77,8 @@ const useConfig = (id: string, payload: ListFilterNodeType) => { const { varType, itemVarType } = getType(draft.variable) const isFileArray = varType === VarType.arrayFile + draft.var_type = varType + draft.item_var_type = itemVarType draft.filter_by = [{ key: isFileArray ? 'name' : '', comparison_operator: getOperators(itemVarType, isFileArray ? { key: 'name' } : undefined)[0],