diff --git a/web/app/components/app-sidebar/index.tsx b/web/app/components/app-sidebar/index.tsx
index 65e35b78a..0a216de8b 100644
--- a/web/app/components/app-sidebar/index.tsx
+++ b/web/app/components/app-sidebar/index.tsx
@@ -10,6 +10,7 @@ import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints'
import { useStore as useAppStore } from '@/app/components/app/store'
import cn from '@/utils/classnames'
import { useSearchParams } from 'next/navigation'
+import { useGetLayoutByChannel } from '@/hooks/use-channel'
export type IAppDetailNavProps = {
iconType?: 'app' | 'dataset' | 'notion'
@@ -56,6 +57,9 @@ const AppDetailNav = ({
}
}, [appSidebarExpand, setAppSiderbarExpand])
+ // 通过 channel 获取 layout 数据内容
+ const showLayout = useGetLayoutByChannel()
+
const searchParams = useSearchParams()
// 从 router 查询参数,若有 sidebar选项,按照参数设置,没有的话,默认是展示内容
@@ -68,7 +72,7 @@ const AppDetailNav = ({
return (
diff --git a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx
index 9040de1b2..b4d1d32ed 100644
--- a/web/app/components/app/configuration/tools/external-data-tool-modal.tsx
+++ b/web/app/components/app/configuration/tools/external-data-tool-modal.tsx
@@ -20,6 +20,7 @@ import type {
import { useToastContext } from '@/app/components/base/toast'
import AppIcon from '@/app/components/base/app-icon'
import { noop } from 'lodash-es'
+import { useGetLayoutByChannel } from '@/hooks/use-channel'
const systemTypes = ['api']
type ExternalDataToolModalProps = {
@@ -137,27 +138,42 @@ const ExternalDataToolModal: FC
= ({
const handleSave = () => {
if (!localeData.type) {
- notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: t('appDebug.feature.tools.modal.toolType.title') }) })
+ notify({
+ type: 'error',
+ message: t('appDebug.errorMessage.valueOfVarRequired', { key: t('appDebug.feature.tools.modal.toolType.title') }),
+ })
return
}
if (!localeData.label) {
- notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: t('appDebug.feature.tools.modal.name.title') }) })
+ notify({
+ type: 'error',
+ message: t('appDebug.errorMessage.valueOfVarRequired', { key: t('appDebug.feature.tools.modal.name.title') }),
+ })
return
}
if (!localeData.variable) {
- notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: t('appDebug.feature.tools.modal.variableName.title') }) })
+ notify({
+ type: 'error',
+ message: t('appDebug.errorMessage.valueOfVarRequired', { key: t('appDebug.feature.tools.modal.variableName.title') }),
+ })
return
}
if (localeData.variable && !/[a-zA-Z_][a-zA-Z0-9_]{0,29}/g.test(localeData.variable)) {
- notify({ type: 'error', message: t('appDebug.varKeyError.notValid', { key: t('appDebug.feature.tools.modal.variableName.title') }) })
+ notify({
+ type: 'error',
+ message: t('appDebug.varKeyError.notValid', { key: t('appDebug.feature.tools.modal.variableName.title') }),
+ })
return
}
if (localeData.type === 'api' && !localeData.config?.api_based_extension_id) {
- notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? 'API Extension' : 'API 扩展' }) })
+ notify({
+ type: 'error',
+ message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? 'API Extension' : 'API 扩展' }),
+ })
return
}
@@ -183,6 +199,9 @@ const ExternalDataToolModal: FC = ({
const action = data.type ? t('common.operation.edit') : t('common.operation.add')
+ // 通过 channel 获取 layout 数据内容
+ const showLayout = useGetLayoutByChannel()
+
return (
= ({
placeholder={t('appDebug.feature.tools.modal.name.placeholder') || ''}
/>
{ setShowEmojiPicker(true) }}
+ onClick={() => {
+ setShowEmojiPicker(true)
+ }}
className='!h-9 !w-9 cursor-pointer rounded-lg border-[0.5px] border-black/5 '
icon={localeData.icon}
background={localeData.icon_background}
@@ -245,9 +266,9 @@ const ExternalDataToolModal: FC = ({
-
+
{t('common.apiBasedExtension.link')}
diff --git a/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx b/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx
index 297e2b3f0..2eb3c1c5d 100644
--- a/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx
+++ b/web/app/components/base/features/new-feature-panel/moderation/moderation-setting-modal.tsx
@@ -25,19 +25,20 @@ import { useModalContext } from '@/context/modal-context'
import { CustomConfigurationStatusEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import cn from '@/utils/classnames'
import { noop } from 'lodash-es'
+import { useGetLayoutByChannel } from '@/hooks/use-channel'
const systemTypes = ['openai_moderation', 'keywords', 'api']
type Provider = {
- key: string
- name: string
- form_schema?: CodeBasedExtensionItem['form_schema']
+ key: string;
+ name: string;
+ form_schema?: CodeBasedExtensionItem['form_schema'];
}
type ModerationSettingModalProps = {
- data: ModerationConfig
- onCancel: () => void
- onSave: (moderationConfig: ModerationConfig) => void
+ data: ModerationConfig;
+ onCancel: () => void;
+ onSave: (moderationConfig: ModerationConfig) => void;
}
const ModerationSettingModal: FC = ({
@@ -48,7 +49,11 @@ const ModerationSettingModal: FC = ({
const { t } = useTranslation()
const { notify } = useToastContext()
const { locale } = useContext(I18n)
- const { data: modelProviders, isLoading, mutate } = useSWR('/workspaces/current/model-providers', fetchModelProviders)
+ const {
+ data: modelProviders,
+ isLoading,
+ mutate,
+ } = useSWR('/workspaces/current/model-providers', fetchModelProviders)
const [localeData, setLocaleData] = useState(data)
const { setShowAccountSettingModal } = useModalContext()
const handleOpenSettingsModal = () => {
@@ -63,12 +68,24 @@ const ModerationSettingModal: FC = ({
'/code-based-extension?module=moderation',
fetchCodeBasedExtensionList,
)
- const openaiProvider = modelProviders?.data.find(item => item.provider === 'langgenius/openai/openai')
- const systemOpenaiProviderEnabled = openaiProvider?.system_configuration.enabled
- const systemOpenaiProviderQuota = systemOpenaiProviderEnabled ? openaiProvider?.system_configuration.quota_configurations.find(item => item.quota_type === openaiProvider.system_configuration.current_quota_type) : undefined
+ const openaiProvider = modelProviders?.data.find(
+ item => item.provider === 'langgenius/openai/openai',
+ )
+ const systemOpenaiProviderEnabled
+ = openaiProvider?.system_configuration.enabled
+ const systemOpenaiProviderQuota = systemOpenaiProviderEnabled
+ ? openaiProvider?.system_configuration.quota_configurations.find(
+ item =>
+ item.quota_type
+ === openaiProvider.system_configuration.current_quota_type,
+ )
+ : undefined
const systemOpenaiProviderCanUse = systemOpenaiProviderQuota?.is_valid
- const customOpenaiProvidersCanUse = openaiProvider?.custom_configuration.status === CustomConfigurationStatusEnum.active
- const isOpenAIProviderConfigured = customOpenaiProvidersCanUse || systemOpenaiProviderCanUse
+ const customOpenaiProvidersCanUse
+ = openaiProvider?.custom_configuration.status
+ === CustomConfigurationStatusEnum.active
+ const isOpenAIProviderConfigured
+ = customOpenaiProvidersCanUse || systemOpenaiProviderCanUse
const providers: Provider[] = [
{
key: 'openai_moderation',
@@ -82,26 +99,32 @@ const ModerationSettingModal: FC = ({
key: 'api',
name: t('common.apiBasedExtension.selector.title'),
},
- ...(
- codeBasedExtensionList
- ? codeBasedExtensionList.data.map((item) => {
- return {
- key: item.name,
- name: locale === 'zh-Hans' ? item.label['zh-Hans'] : item.label['en-US'],
- form_schema: item.form_schema,
- }
- })
- : []
- ),
+ ...(codeBasedExtensionList
+ ? codeBasedExtensionList.data.map((item) => {
+ return {
+ key: item.name,
+ name:
+ locale === 'zh-Hans'
+ ? item.label['zh-Hans']
+ : item.label['en-US'],
+ form_schema: item.form_schema,
+ }
+ })
+ : []),
]
- const currentProvider = providers.find(provider => provider.key === localeData.type)
+ const currentProvider = providers.find(
+ provider => provider.key === localeData.type,
+ )
const handleDataTypeChange = (type: string) => {
let config: undefined | Record
const currProvider = providers.find(provider => provider.key === type)
- if (systemTypes.findIndex(t => t === type) < 0 && currProvider?.form_schema) {
+ if (
+ systemTypes.findIndex(t => t === type) < 0
+ && currProvider?.form_schema
+ ) {
config = currProvider?.form_schema.reduce((prev, next) => {
prev[next.variable] = next.default
return prev
@@ -118,10 +141,8 @@ const ModerationSettingModal: FC = ({
const value = e.target.value
const arr = value.split('\n').reduce((prev: string[], next: string) => {
- if (next !== '')
- prev.push(next.slice(0, 100))
- if (next === '' && prev[prev.length - 1] !== '')
- prev.push(next)
+ if (next !== '') prev.push(next.slice(0, 100))
+ if (next === '' && prev[prev.length - 1] !== '') prev.push(next)
return prev
}, [])
@@ -135,7 +156,10 @@ const ModerationSettingModal: FC = ({
})
}
- const handleDataContentChange = (contentType: string, contentConfig: ModerationContentConfig) => {
+ const handleDataContentChange = (
+ contentType: string,
+ contentConfig: ModerationContentConfig,
+ ) => {
setLocaleData({
...localeData,
config: {
@@ -170,13 +194,15 @@ const ModerationSettingModal: FC = ({
const { inputs_config, outputs_config } = config!
const params: Record = {}
- if (type === 'keywords')
- params.keywords = config?.keywords
+ if (type === 'keywords') params.keywords = config?.keywords
if (type === 'api')
params.api_based_extension_id = config?.api_based_extension_id
- if (systemTypes.findIndex(t => t === type) < 0 && currentProvider?.form_schema) {
+ if (
+ systemTypes.findIndex(t => t === type) < 0
+ && currentProvider?.form_schema
+ ) {
currentProvider.form_schema.forEach((form) => {
params[form.variable] = config?.[form.variable]
})
@@ -197,178 +223,269 @@ const ModerationSettingModal: FC = ({
if (localeData.type === 'openai_moderation' && !isOpenAIProviderConfigured)
return
- if (!localeData.config?.inputs_config?.enabled && !localeData.config?.outputs_config?.enabled) {
- notify({ type: 'error', message: t('appDebug.feature.moderation.modal.content.condition') })
+ if (
+ !localeData.config?.inputs_config?.enabled
+ && !localeData.config?.outputs_config?.enabled
+ ) {
+ notify({
+ type: 'error',
+ message: t('appDebug.feature.moderation.modal.content.condition'),
+ })
return
}
if (localeData.type === 'keywords' && !localeData.config.keywords) {
- notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? 'keywords' : '关键词' }) })
+ notify({
+ type: 'error',
+ message: t('appDebug.errorMessage.valueOfVarRequired', {
+ key: locale !== LanguagesSupported[1] ? 'keywords' : '关键词',
+ }),
+ })
return
}
- if (localeData.type === 'api' && !localeData.config.api_based_extension_id) {
- notify({ type: 'error', message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? 'API Extension' : 'API 扩展' }) })
+ if (
+ localeData.type === 'api'
+ && !localeData.config.api_based_extension_id
+ ) {
+ notify({
+ type: 'error',
+ message: t('appDebug.errorMessage.valueOfVarRequired', {
+ key: locale !== LanguagesSupported[1] ? 'API Extension' : 'API 扩展',
+ }),
+ })
return
}
- if (systemTypes.findIndex(t => t === localeData.type) < 0 && currentProvider?.form_schema) {
+ if (
+ systemTypes.findIndex(t => t === localeData.type) < 0
+ && currentProvider?.form_schema
+ ) {
for (let i = 0; i < currentProvider.form_schema.length; i++) {
- if (!localeData.config?.[currentProvider.form_schema[i].variable] && currentProvider.form_schema[i].required) {
+ if (
+ !localeData.config?.[currentProvider.form_schema[i].variable]
+ && currentProvider.form_schema[i].required
+ ) {
notify({
type: 'error',
- message: t('appDebug.errorMessage.valueOfVarRequired', { key: locale !== LanguagesSupported[1] ? currentProvider.form_schema[i].label['en-US'] : currentProvider.form_schema[i].label['zh-Hans'] }),
+ message: t('appDebug.errorMessage.valueOfVarRequired', {
+ key:
+ locale !== LanguagesSupported[1]
+ ? currentProvider.form_schema[i].label['en-US']
+ : currentProvider.form_schema[i].label['zh-Hans'],
+ }),
})
return
}
}
}
- if (localeData.config.inputs_config?.enabled && !localeData.config.inputs_config.preset_response && localeData.type !== 'api') {
- notify({ type: 'error', message: t('appDebug.feature.moderation.modal.content.errorMessage') })
+ if (
+ localeData.config.inputs_config?.enabled
+ && !localeData.config.inputs_config.preset_response
+ && localeData.type !== 'api'
+ ) {
+ notify({
+ type: 'error',
+ message: t('appDebug.feature.moderation.modal.content.errorMessage'),
+ })
return
}
- if (localeData.config.outputs_config?.enabled && !localeData.config.outputs_config.preset_response && localeData.type !== 'api') {
- notify({ type: 'error', message: t('appDebug.feature.moderation.modal.content.errorMessage') })
+ if (
+ localeData.config.outputs_config?.enabled
+ && !localeData.config.outputs_config.preset_response
+ && localeData.type !== 'api'
+ ) {
+ notify({
+ type: 'error',
+ message: t('appDebug.feature.moderation.modal.content.errorMessage'),
+ })
return
}
onSave(formatData(localeData))
}
+ // 通过 channel 获取 layout 数据内容
+ const showLayout = useGetLayoutByChannel()
+
return (
-
-
-
{t('appDebug.feature.moderation.modal.title')}
-
+
+
+
+ {t('appDebug.feature.moderation.modal.title')}
+
+
+
+
-
-
+
+
{t('appDebug.feature.moderation.modal.provider.title')}
-
- {
- providers.map(provider => (
+
+ {providers.map(provider => (
+
handleDataTypeChange(provider.key)}
+ >
handleDataTypeChange(provider.key)}
- >
-
- {provider.name}
-
- ))
- }
+ localeData.type === provider.key
+ && 'border-[5px] border-components-radio-border-checked',
+ )}
+ >
+ {provider.name}
+
+ ))}
- {
- !isLoading && !isOpenAIProviderConfigured && localeData.type === 'openai_moderation' && (
-
-
-
- {t('appDebug.feature.moderation.modal.openaiNotConfig.before')}
-
- {t('common.settings.provider')}
-
- {t('appDebug.feature.moderation.modal.openaiNotConfig.after')}
-
-
- )
- }
-
- {
- localeData.type === 'keywords' && (
-
-
{t('appDebug.feature.moderation.modal.provider.keywords')}
-
{t('appDebug.feature.moderation.modal.keywords.tip')}
-
-
-
- {(localeData.config?.keywords || '').split('\n').filter(Boolean).length}/100 {t('appDebug.feature.moderation.modal.keywords.line')}
-
-
-
- )
- }
- {
- localeData.type === 'api' && (
-
-
- )
- }
- {
- systemTypes.findIndex(t => t === localeData.type) < 0
- && currentProvider?.form_schema
- && (
-
+ {localeData.type === 'keywords' && (
+
+
+ {t('appDebug.feature.moderation.modal.provider.keywords')}
+
+
+ {t('appDebug.feature.moderation.modal.keywords.tip')}
+
+
+
+
+
+ {
+ (localeData.config?.keywords || '')
+ .split('\n')
+ .filter(Boolean).length
+ }
+
+ /
+
+ 100 {t('appDebug.feature.moderation.modal.keywords.line')}
+
+
+
+
+ )}
+ {localeData.type === 'api' && (
+
+ )}
+ {systemTypes.findIndex(t => t === localeData.type) < 0
+ && currentProvider?.form_schema && (
+
+ )}
+
handleDataContentChange('inputs_config', config)}
- info={(localeData.type === 'api' && t('appDebug.feature.moderation.modal.content.fromApi')) || ''}
+ config={
+ localeData.config?.inputs_config || {
+ enabled: false,
+ preset_response: '',
+ }
+ }
+ onConfigChange={config =>
+ handleDataContentChange('inputs_config', config)
+ }
+ info={
+ (localeData.type === 'api'
+ && t('appDebug.feature.moderation.modal.content.fromApi'))
+ || ''
+ }
showPreset={!(localeData.type === 'api')}
/>
handleDataContentChange('outputs_config', config)}
- info={(localeData.type === 'api' && t('appDebug.feature.moderation.modal.content.fromApi')) || ''}
+ config={
+ localeData.config?.outputs_config || {
+ enabled: false,
+ preset_response: '',
+ }
+ }
+ onConfigChange={config =>
+ handleDataContentChange('outputs_config', config)
+ }
+ info={
+ (localeData.type === 'api'
+ && t('appDebug.feature.moderation.modal.content.fromApi'))
+ || ''
+ }
showPreset={!(localeData.type === 'api')}
/>
- {t('appDebug.feature.moderation.modal.content.condition')}
-
-