From 267bd72c63fe5c97e37332ce064640083d5b65e0 Mon Sep 17 00:00:00 2001 From: Junyan Qin Date: Fri, 27 Mar 2026 18:10:30 +0800 Subject: [PATCH] fix(web): resolve zodResolver type mismatch for optional description fields Remove .default('') from zod schemas to align input/output types, preventing type conflict between zodResolver and useForm in @hookform/resolvers v5. Use nullish coalescing at entity assignment sites to ensure string type safety. --- web/src/app/home/bots/components/bot-form/BotForm.tsx | 6 +++--- web/src/app/home/knowledge/components/kb-form/KBForm.tsx | 4 ++-- .../components/pipeline-form/PipelineFormComponent.tsx | 8 ++++---- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/web/src/app/home/bots/components/bot-form/BotForm.tsx b/web/src/app/home/bots/components/bot-form/BotForm.tsx index 71198cbc..7048aab7 100644 --- a/web/src/app/home/bots/components/bot-form/BotForm.tsx +++ b/web/src/app/home/bots/components/bot-form/BotForm.tsx @@ -53,7 +53,7 @@ import { CustomApiError } from '@/app/infra/entities/common'; const getFormSchema = (t: (key: string) => string) => z.object({ name: z.string().min(1, { message: t('bots.botNameRequired') }), - description: z.string().optional().default(''), + description: z.string().optional(), adapter: z.string().min(1, { message: t('bots.adapterRequired') }), adapter_config: z.record(z.string(), z.any()), enable: z.boolean().optional(), @@ -337,7 +337,7 @@ export default function BotForm({ const updateBot: Bot = { uuid: initBotId, name: form.getValues().name, - description: form.getValues().description, + description: form.getValues().description ?? '', adapter: form.getValues().adapter, adapter_config: form.getValues().adapter_config, enable: form.getValues().enable, @@ -360,7 +360,7 @@ export default function BotForm({ } else { const newBot: Bot = { name: form.getValues().name, - description: form.getValues().description, + description: form.getValues().description ?? '', adapter: form.getValues().adapter, adapter_config: form.getValues().adapter_config, }; diff --git a/web/src/app/home/knowledge/components/kb-form/KBForm.tsx b/web/src/app/home/knowledge/components/kb-form/KBForm.tsx index 4eee2a64..3d620cd1 100644 --- a/web/src/app/home/knowledge/components/kb-form/KBForm.tsx +++ b/web/src/app/home/knowledge/components/kb-form/KBForm.tsx @@ -46,7 +46,7 @@ import { UUID } from 'uuidjs'; const getFormSchema = (t: (key: string) => string) => z.object({ name: z.string().min(1, { message: t('knowledge.kbNameRequired') }), - description: z.string().optional().default(''), + description: z.string().optional(), emoji: z.string().optional(), ragEngineId: z .string() @@ -238,7 +238,7 @@ export default function KBForm({ const onSubmit = (data: z.infer) => { const kbData: KnowledgeBase = { name: data.name, - description: data.description, + description: data.description ?? '', emoji: data.emoji, knowledge_engine_plugin_id: selectedEngineId, creation_settings: configSettings, diff --git a/web/src/app/home/pipelines/components/pipeline-form/PipelineFormComponent.tsx b/web/src/app/home/pipelines/components/pipeline-form/PipelineFormComponent.tsx index aea3e205..35775a58 100644 --- a/web/src/app/home/pipelines/components/pipeline-form/PipelineFormComponent.tsx +++ b/web/src/app/home/pipelines/components/pipeline-form/PipelineFormComponent.tsx @@ -80,7 +80,7 @@ export default function PipelineFormComponent({ ? z.object({ basic: z.object({ name: z.string().min(1, { message: t('pipelines.nameRequired') }), - description: z.string().optional().default(''), + description: z.string().optional(), emoji: z.string().optional(), }), ai: z.record(z.string(), z.any()), @@ -91,7 +91,7 @@ export default function PipelineFormComponent({ : z.object({ basic: z.object({ name: z.string().min(1, { message: t('pipelines.nameRequired') }), - description: z.string().optional().default(''), + description: z.string().optional(), emoji: z.string().optional(), }), ai: z.record(z.string(), z.any()).optional(), @@ -253,7 +253,7 @@ export default function PipelineFormComponent({ function handleCreate(values: FormValues) { const pipeline: Pipeline = { config: {}, - description: values.basic.description, + description: values.basic.description ?? '', name: values.basic.name, emoji: values.basic.emoji, }; @@ -280,7 +280,7 @@ export default function PipelineFormComponent({ const pipeline: Pipeline = { config: realConfig, // created_at: '', - description: values.basic.description, + description: values.basic.description ?? '', // for_version: '', name: values.basic.name, emoji: values.basic.emoji,