From 5ef91562425bc54a8f8c8f1d94fe4bb699826d64 Mon Sep 17 00:00:00 2001 From: AkaraChen Date: Thu, 26 Dec 2024 14:44:05 +0800 Subject: [PATCH] feat: custom credential form --- .../nodes/_base/components/agent-strategy.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx b/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx index d21190b1ff..ab1500cbfa 100644 --- a/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx +++ b/web/app/components/workflow/nodes/_base/components/agent-strategy.tsx @@ -26,15 +26,21 @@ export type AgentStrategyProps = { onFormValueChange: (value: ToolVarInputs) => void } -type MaxIterFormSchema = Omit & { type: 'max-iter' } +type CustomSchema = Omit & { type: Type } & Field + +type MaxIterFormSchema = CustomSchema<'max-iter'> +type ToolSelectorSchema = CustomSchema<'tool-selector'> + +type CustomField = MaxIterFormSchema | ToolSelectorSchema export const AgentStrategy = (props: AgentStrategyProps) => { const { strategy, onStrategyChange, formSchema, formValue, onFormValueChange } = props const { t } = useTranslation() - const renderField: ComponentProps>['customRenderField'] = (schema, props) => { + const renderField: ComponentProps>['customRenderField'] = (schema, props) => { switch (schema.type) { case 'max-iter': { - const value = props.value[schema.variable] + const defaultValue = schema.default ? Number.parseInt(schema.default) : 1 + const value = props.value[schema.variable] || defaultValue const onChange = (value: number) => { props.onChange({ ...props.value, [schema.variable]: value }) } @@ -45,7 +51,7 @@ export const AgentStrategy = (props: AgentStrategyProps) => { value={value} // TODO: maybe empty, handle this onChange={onChange as any} - defaultValue={3} + defaultValue={defaultValue} size='sm' min={1} max={10} @@ -63,7 +69,7 @@ export const AgentStrategy = (props: AgentStrategyProps) => { { strategy ?
- + formSchemas={[ ...formSchema, { @@ -76,6 +82,7 @@ export const AgentStrategy = (props: AgentStrategyProps) => { name: 'max iter', required: true, show_on: [], + default: '3', } as MaxIterFormSchema, ]} value={formValue}