From d29b3292f02991e24a7da95b095aae9835a522d6 Mon Sep 17 00:00:00 2001 From: twwu Date: Thu, 27 Mar 2025 12:54:33 +0800 Subject: [PATCH] feat: update JSON schema configuration to include localized help documentation and adjust boolean type handling --- .../json-schema-config.tsx | 12 ++++++- .../visual-editor/edit-card/index.tsx | 4 +-- .../visual-editor/hooks.ts | 36 +++++++++---------- .../components/workflow/nodes/llm/utils.ts | 3 +- web/i18n/language.ts | 2 +- 5 files changed, 34 insertions(+), 23 deletions(-) diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-config.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-config.tsx index 148d65346c..f77781ea8b 100644 --- a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-config.tsx +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/json-schema-config.tsx @@ -14,6 +14,7 @@ import { MittProvider, VisualEditorContextProvider } from './visual-editor/conte import ErrorMessage from './error-message' import { useVisualEditorStore } from './visual-editor/store' import Toast from '@/app/components/base/toast' +import { useGetLanguage } from '@/context/i18n' type JsonSchemaConfigProps = { defaultSchema?: SchemaRoot @@ -38,12 +39,21 @@ const DEFAULT_SCHEMA: SchemaRoot = { additionalProperties: false, } +const HELP_DOC_URL = { + zh_Hans: 'https://docs.dify.ai/zh-hans/guides/workflow/structured-outputs', + en_US: 'https://docs.dify.ai/guides/workflow/structured-outputs', + ja_JP: 'https://docs.dify.ai/ja-jp/guides/workflow/structured-outputs', +} + +type LocaleKey = keyof typeof HELP_DOC_URL + const JsonSchemaConfig: FC = ({ defaultSchema, onSave, onClose, }) => { const { t } = useTranslation() + const locale = useGetLanguage() as LocaleKey const [currentTab, setCurrentTab] = useState(SchemaView.VisualEditor) const [jsonSchema, setJsonSchema] = useState(defaultSchema || DEFAULT_SCHEMA) const [json, setJson] = useState(JSON.stringify(jsonSchema, null, 2)) @@ -227,7 +237,7 @@ const JsonSchemaConfig: FC = ({
diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/edit-card/index.tsx b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/edit-card/index.tsx index 241b45387e..e162ca0c6c 100644 --- a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/edit-card/index.tsx +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/edit-card/index.tsx @@ -38,11 +38,11 @@ type EditCardProps = { const TYPE_OPTIONS = [ { value: Type.string, text: 'string' }, { value: Type.number, text: 'number' }, - { value: Type.boolean, text: 'boolean' }, + // { value: Type.boolean, text: 'boolean' }, { value: Type.object, text: 'object' }, { value: ArrayType.string, text: 'array[string]' }, { value: ArrayType.number, text: 'array[number]' }, - { value: ArrayType.boolean, text: 'array[boolean]' }, + // { value: ArrayType.boolean, text: 'array[boolean]' }, { value: ArrayType.object, text: 'array[object]' }, ] diff --git a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/hooks.ts b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/hooks.ts index 204d03af05..8004d034d2 100644 --- a/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/hooks.ts +++ b/web/app/components/workflow/nodes/llm/components/json-schema-config-modal/visual-editor/hooks.ts @@ -130,12 +130,12 @@ export const useSchemaNodeOperations = (props: VisualEditorProps) => { type: Type.number, } break - case ArrayType.boolean: - schema.type = Type.array - schema.items = { - type: Type.boolean, - } - break + // case ArrayType.boolean: + // schema.type = Type.array + // schema.items = { + // type: Type.boolean, + // } + // break case ArrayType.object: schema.type = Type.array schema.items = { @@ -304,12 +304,12 @@ export const useSchemaNodeOperations = (props: VisualEditorProps) => { type: Type.number, } break - case ArrayType.boolean: - schema.type = Type.array - schema.items = { - type: Type.boolean, - } - break + // case ArrayType.boolean: + // schema.type = Type.array + // schema.items = { + // type: Type.boolean, + // } + // break case ArrayType.object: schema.type = Type.array schema.items = { @@ -393,12 +393,12 @@ export const useSchemaNodeOperations = (props: VisualEditorProps) => { type: Type.number, } break - case ArrayType.boolean: - schema.type = Type.array - schema.items = { - type: Type.boolean, - } - break + // case ArrayType.boolean: + // schema.type = Type.array + // schema.items = { + // type: Type.boolean, + // } + // break case ArrayType.object: schema.type = Type.array schema.items = { diff --git a/web/app/components/workflow/nodes/llm/utils.ts b/web/app/components/workflow/nodes/llm/utils.ts index 0756eee450..2d8966c828 100644 --- a/web/app/components/workflow/nodes/llm/utils.ts +++ b/web/app/components/workflow/nodes/llm/utils.ts @@ -28,7 +28,8 @@ export const getHasChildren = (schema: Field) => { export const inferType = (value: any): Type => { if (Array.isArray(value)) return Type.array - if (typeof value === 'boolean') return Type.boolean + // type boolean will be treated as string + if (typeof value === 'boolean') return Type.string if (typeof value === 'number') return Type.number if (typeof value === 'string') return Type.string if (typeof value === 'object') return Type.object diff --git a/web/i18n/language.ts b/web/i18n/language.ts index cd770977bd..c86d31ffa0 100644 --- a/web/i18n/language.ts +++ b/web/i18n/language.ts @@ -33,7 +33,7 @@ export const languages = data.languages export const LanguagesSupported = languages.filter(item => item.supported).map(item => item.value) export const getLanguage = (locale: string) => { - if (locale === 'zh-Hans') + if (['zh-Hans', 'ja-JP'].includes(locale)) return locale.replace('-', '_') return LanguagesSupported[0].replace('-', '_')