diff --git a/web/app/components/workflow/skill/editor/skill-editor/tool-setting/tool-settings-section.tsx b/web/app/components/workflow/skill/editor/skill-editor/tool-setting/tool-settings-section.tsx index ef43a4f5ae..99b66aeb86 100644 --- a/web/app/components/workflow/skill/editor/skill-editor/tool-setting/tool-settings-section.tsx +++ b/web/app/components/workflow/skill/editor/skill-editor/tool-setting/tool-settings-section.tsx @@ -13,6 +13,23 @@ import ReasoningConfigForm from '@/app/components/plugins/plugin-detail-panel/to import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema' import { VarKindType } from '@/app/components/workflow/nodes/_base/types' +type ToolFormSchema = { + variable: string + type: string + default?: unknown + [key: string]: unknown +} + +type ToolConfigValueItem = { + auto?: 0 | 1 + value?: { + type: VarKindType + value?: unknown + } +} + +type ToolConfigValueMap = Record + type ToolSettingsSectionProps = { currentProvider?: ToolWithProvider currentTool?: Tool @@ -42,10 +59,16 @@ const ToolSettingsSection: FC = ({ return currentTool.parameters?.filter(param => param.form === 'llm') || [] }, [currentTool]) - const settingsFormSchemas = useMemo(() => toolParametersToFormSchemas(currentToolSettings), [currentToolSettings]) - const paramsFormSchemas = useMemo(() => toolParametersToFormSchemas(currentToolParams), [currentToolParams]) + const settingsFormSchemas = useMemo( + () => toolParametersToFormSchemas(currentToolSettings) as ToolFormSchema[], + [currentToolSettings], + ) + const paramsFormSchemas = useMemo( + () => toolParametersToFormSchemas(currentToolParams) as ToolFormSchema[], + [currentToolParams], + ) - const handleSettingsFormChange = (v: Record) => { + const handleSettingsFormChange = (v: ToolConfigValueMap) => { if (!value || !onChange) return onChange({ @@ -54,7 +77,7 @@ const ToolSettingsSection: FC = ({ }) } - const handleParamsFormChange = (v: Record) => { + const handleParamsFormChange = (v: ToolConfigValueMap) => { if (!value || !onChange) return onChange({ @@ -71,7 +94,7 @@ const ToolSettingsSection: FC = ({ const showSettingsSection = currentToolSettings.length > 0 const showParamsSection = currentToolParams.length > 0 - const getVarKindType = (type: FormTypeEnum) => { + const getVarKindType = (type: FormTypeEnum | string) => { if (type === FormTypeEnum.file || type === FormTypeEnum.files) return VarKindType.variable if (type === FormTypeEnum.select || type === FormTypeEnum.checkbox || type === FormTypeEnum.textNumber || type === FormTypeEnum.array || type === FormTypeEnum.object) @@ -80,24 +103,25 @@ const ToolSettingsSection: FC = ({ return VarKindType.mixed return VarKindType.constant } - const getSafeConfigValue = (rawValue: Record | undefined, schemas: any[]) => { - const nextValue = { ...(rawValue || {}) } + const getSafeConfigValue = (rawValue: ToolConfigValueMap | undefined, schemas: ToolFormSchema[]) => { + const nextValue: ToolConfigValueMap = { ...(rawValue || {}) } schemas.forEach((schema) => { - if (!nextValue[schema.variable]) { + const currentValue = nextValue[schema.variable] + if (!currentValue) { nextValue[schema.variable] = { auto: 0, value: { - type: getVarKindType(schema.type as FormTypeEnum), + type: getVarKindType(schema.type), value: schema.default ?? null, }, } return } - if (nextValue[schema.variable].auto === undefined) - nextValue[schema.variable].auto = 0 - if (nextValue[schema.variable].value === undefined) { - nextValue[schema.variable].value = { - type: getVarKindType(schema.type as FormTypeEnum), + if (currentValue.auto === undefined) + currentValue.auto = 0 + if (currentValue.value === undefined) { + currentValue.value = { + type: getVarKindType(schema.type), value: schema.default ?? null, } } @@ -109,22 +133,22 @@ const ToolSettingsSection: FC = ({ <>
-
{t('detailPanel.toolSelector.settings', { ns: 'plugin' })}
+
{t('detailPanel.toolSelector.reasoningConfig', { ns: 'plugin' })}
{showSettingsSection && ( )} {showParamsSection && ( diff --git a/web/i18n/en-US/plugin.json b/web/i18n/en-US/plugin.json index 95c911224b..94392aa85a 100644 --- a/web/i18n/en-US/plugin.json +++ b/web/i18n/en-US/plugin.json @@ -127,6 +127,7 @@ "detailPanel.toolSelector.paramsTip1": "Controls LLM inference parameters.", "detailPanel.toolSelector.paramsTip2": "When 'Auto' is off, the default value is used.", "detailPanel.toolSelector.placeholder": "Select a tool...", + "detailPanel.toolSelector.reasoningConfig": "REASONING CONFIG", "detailPanel.toolSelector.settings": "USER SETTINGS", "detailPanel.toolSelector.title": "Add tool", "detailPanel.toolSelector.toolLabel": "Tool", diff --git a/web/i18n/zh-Hans/plugin.json b/web/i18n/zh-Hans/plugin.json index e3efaa53eb..f7421b4fbe 100644 --- a/web/i18n/zh-Hans/plugin.json +++ b/web/i18n/zh-Hans/plugin.json @@ -127,6 +127,7 @@ "detailPanel.toolSelector.paramsTip1": "控制 LLM 推理参数。", "detailPanel.toolSelector.paramsTip2": "当“自动”关闭时,使用默认值。", "detailPanel.toolSelector.placeholder": "选择工具", + "detailPanel.toolSelector.reasoningConfig": "推理配置", "detailPanel.toolSelector.settings": "用户设置", "detailPanel.toolSelector.title": "添加工具", "detailPanel.toolSelector.toolLabel": "工具",