diff --git a/web/app/components/base/form/components/base/base-form.tsx b/web/app/components/base/form/components/base/base-form.tsx index d54cc19f19..89a673f5f1 100644 --- a/web/app/components/base/form/components/base/base-form.tsx +++ b/web/app/components/base/form/components/base/base-form.tsx @@ -88,6 +88,19 @@ const BaseForm = ({ }) return result }) + const moreOnValues = useStore(form.store, (s: any) => { + const result: Record = {} + formSchemas.forEach((schema) => { + const { more_on } = schema + const moreOn = typeof more_on === 'function' ? more_on(form) : more_on + if (moreOn?.length) { + moreOn?.forEach((condition) => { + result[condition.variable] = s.values[condition.variable] + }) + } + }) + return result + }) useImperativeHandle(ref, () => { return { @@ -104,11 +117,18 @@ const BaseForm = ({ const formSchema = formSchemas?.find(schema => schema.name === field.name) if (formSchema) { + const { more_on = [] } = formSchema + const moreOn = typeof more_on === 'function' ? more_on(form) : more_on + const more = (moreOn || []).every((condition) => { + const conditionValue = moreOnValues[condition.variable] + return Array.isArray(condition.value) ? condition.value.includes(conditionValue) : conditionValue === condition.value + }) + return ( { const validators = getValidators(formSchema) diff --git a/web/app/components/base/form/hooks/use-check-validated.ts b/web/app/components/base/form/hooks/use-check-validated.ts index b4f3ec2b9a..6eb8b636bf 100644 --- a/web/app/components/base/form/hooks/use-check-validated.ts +++ b/web/app/components/base/form/hooks/use-check-validated.ts @@ -15,13 +15,14 @@ export const useCheckValidated = (form: AnyFormApi, FormSchemas: FormSchema[]) = const errorArray = Object.keys(fields).reduce((acc: string[], key: string) => { const currentSchema = FormSchemas.find(schema => schema.name === key) const { show_on = [] } = currentSchema || {} - const showOnValues = show_on.reduce((acc, condition) => { + const showOn = typeof show_on === 'function' ? show_on(form) : show_on + const showOnValues = (showOn || []).reduce((acc, condition) => { acc[condition.variable] = values[condition.variable] return acc }, {} as Record) - const show = show_on?.every((condition) => { + const show = (showOn || []).every((condition) => { const conditionValue = showOnValues[condition.variable] - return conditionValue === condition.value + return Array.isArray(condition.value) ? condition.value.includes(conditionValue) : conditionValue === condition.value }) const errors: any[] = show ? fields[key].errors : [] diff --git a/web/app/components/base/form/types.ts b/web/app/components/base/form/types.ts index 1be503c764..8cae987441 100644 --- a/web/app/components/base/form/types.ts +++ b/web/app/components/base/form/types.ts @@ -62,6 +62,7 @@ export type FormSchema = { default?: any tooltip?: string | TypeWithI18N show_on?: FormShowOnObject[] | ((form: AnyFormApi) => FormShowOnObject[]) + more_on?: FormShowOnObject[] | ((form: AnyFormApi) => FormShowOnObject[]) url?: string scope?: string help?: string | TypeWithI18N diff --git a/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts b/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts index 3b8bff99af..853dfb907c 100644 --- a/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts +++ b/web/app/components/workflow-app/hooks/use-nodes-sync-draft.ts @@ -85,7 +85,17 @@ export const useNodesSyncDraft = () => { }, environment_variables: environmentVariables, conversation_variables: conversationVariables, - memory_blocks: memoryVariables.map(({ node, value_type, more, ...rest }) => rest), + memory_blocks: memoryVariables.map(({ node, value_type, more, model, ...rest }) => { + return { + ...rest, + model: model ? { + completion_params: model.completion_params, + mode: model.mode, + provider: model.provider, + name: model.model, + } : undefined, + } + }), hash: syncWorkflowDraftHash, }, } diff --git a/web/app/components/workflow/hooks/use-memory-variable.ts b/web/app/components/workflow/hooks/use-memory-variable.ts index 04aac8ca7f..2c8e030bc8 100644 --- a/web/app/components/workflow/hooks/use-memory-variable.ts +++ b/web/app/components/workflow/hooks/use-memory-variable.ts @@ -109,6 +109,12 @@ export const useFormatMemoryVariables = () => { return { ...v, value_type: ChatVarType.Memory, + model: v.model ? { + completion_params: v.model?.completion_params, + mode: v.model?.mode, + provider: v.model?.provider, + model: v.model?.name, + } : undefined, } }) }, []) diff --git a/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-memory-schema.ts b/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-memory-schema.ts index 1464651e23..8bf1fe73d2 100644 --- a/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-memory-schema.ts +++ b/web/app/components/workflow/panel/chat-variable-panel/hooks/use-form/use-memory-schema.ts @@ -70,6 +70,7 @@ export const useMemorySchema = () => { label: t('workflow.chatVariable.modal.updateEvery'), type: FormTypeEnum.textNumber, fieldClassName: 'flex justify-between', + required: true, show_on: [ { variable: 'value_type', @@ -175,11 +176,14 @@ export const useMemorySchema = () => { name: 'model', label: t('workflow.chatVariable.modal.memoryModel'), type: FormTypeEnum.modelSelector, + required: true, show_on: [ { variable: 'value_type', value: [ChatVarType.Memory], }, + ], + more_on: [ { variable: 'more', value: true, @@ -205,6 +209,8 @@ export const useMemorySchema = () => { variable: 'value_type', value: [ChatVarType.Memory], }, + ], + more_on: [ { variable: 'more', value: true, @@ -221,6 +227,8 @@ export const useMemorySchema = () => { variable: 'value_type', value: [ChatVarType.Memory], }, + ], + more_on: [ { variable: 'more', value: true, @@ -235,7 +243,8 @@ export const useMemoryDefaultValues = () => { template: '', instruction: '', strategy: 'on_turns', - update_turns: 0, + update_turns: 500, + preserved_turns: 10, scope: 'app', term: 'session', more: false,