refactor: type improvements that doesn't modify functionality (#17970)

This commit is contained in:
yusheng chen
2025-04-14 16:06:10 +08:00
committed by GitHub
parent 53efb2bad5
commit 4c99e9dc73
39 changed files with 69 additions and 63 deletions

View File

@@ -73,7 +73,7 @@ const AgentTools: FC = () => {
formattingChangedDispatcher()
}
const handleToolAuthSetting = (value: any) => {
const handleToolAuthSetting = (value: AgentToolWithMoreInfo) => {
const newModelConfig = produce(modelConfig, (draft) => {
const tool = (draft.agentConfig.tools).find((item: any) => item.provider_id === value?.collection?.id && item.tool_name === value?.tool_name)
if (tool)
@@ -121,7 +121,7 @@ const AgentTools: FC = () => {
}
headerRight={
<div className='flex items-center'>
<div className='text-xs font-normal leading-[18px] text-text-tertiary'>{tools.filter((item: any) => !!item.enabled).length}/{tools.length}&nbsp;{t('appDebug.agent.tools.enabled')}</div>
<div className='text-xs font-normal leading-[18px] text-text-tertiary'>{tools.filter(item => !!item.enabled).length}/{tools.length}&nbsp;{t('appDebug.agent.tools.enabled')}</div>
{tools.length < MAX_TOOLS_NUM && (
<>
<div className='ml-3 mr-1 h-3.5 w-px bg-divider-regular'></div>
@@ -273,7 +273,7 @@ const AgentTools: FC = () => {
{isShowSettingTool && (
<SettingBuiltInTool
toolName={currentTool?.tool_name as string}
setting={currentTool?.tool_parameters as any}
setting={currentTool?.tool_parameters}
collection={currentTool?.collection as Collection}
isBuiltIn={currentTool?.collection?.type === CollectionType.builtIn}
isModel={currentTool?.collection?.type === CollectionType.model}
@@ -291,7 +291,7 @@ const AgentTools: FC = () => {
type: 'success',
message: t('common.api.actionSuccess'),
})
handleToolAuthSetting(currentTool as any)
handleToolAuthSetting(currentTool)
setShowSettingAuth(false)
}}
/>

View File

@@ -56,8 +56,8 @@ const SettingBuiltInTool: FC<Props> = ({
const [tools, setTools] = useState<Tool[]>([])
const currTool = tools.find(tool => tool.name === toolName)
const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : []
const infoSchemas = formSchemas.filter((item: any) => item.form === 'llm')
const settingSchemas = formSchemas.filter((item: any) => item.form !== 'llm')
const infoSchemas = formSchemas.filter(item => item.form === 'llm')
const settingSchemas = formSchemas.filter(item => item.form !== 'llm')
const hasSetting = settingSchemas.length > 0
const [tempSetting, setTempSetting] = useState(setting)
const [currType, setCurrType] = useState('info')
@@ -99,7 +99,7 @@ const SettingBuiltInTool: FC<Props> = ({
const isValid = (() => {
let valid = true
settingSchemas.forEach((item: any) => {
settingSchemas.forEach((item) => {
if (item.required && !tempSetting[item.name])
valid = false
})
@@ -120,7 +120,7 @@ const SettingBuiltInTool: FC<Props> = ({
<div className=''>
{infoSchemas.length > 0 && (
<div className='space-y-1 py-2'>
{infoSchemas.map((item: any, index) => (
{infoSchemas.map((item, index) => (
<div key={index} className='py-1'>
<div className='flex items-center gap-2'>
<div className='code-sm-semibold text-text-secondary'>{item.label[language]}</div>
@@ -147,7 +147,7 @@ const SettingBuiltInTool: FC<Props> = ({
<Form
value={tempSetting}
onChange={setTempSetting}
formSchemas={settingSchemas as any}
formSchemas={settingSchemas}
isEditMode={false}
showOnVariableMap={{}}
validating={false}

View File

@@ -368,8 +368,8 @@ const ConfigContent: FC<Props> = ({
provider={model?.provider}
completionParams={model?.completion_params}
modelId={model?.name}
setModel={onSingleRetrievalModelChange as any}
onCompletionParamsChange={onSingleRetrievalModelParamsChange as any}
setModel={onSingleRetrievalModelChange}
onCompletionParamsChange={onSingleRetrievalModelParamsChange}
hideDebugWithMultipleModel
debugWithMultipleModel={false}
/>

View File

@@ -8,6 +8,7 @@ import ModelParameterModal from '@/app/components/header/account-setting/model-p
import ModelIcon from '@/app/components/header/account-setting/model-provider-page/model-icon'
import ModelName from '@/app/components/header/account-setting/model-provider-page/model-name'
import {
type FormValue,
MODEL_STATUS_TEXT,
ModelStatusEnum,
} from '@/app/components/header/account-setting/model-provider-page/declarations'
@@ -45,7 +46,7 @@ const ModelParameterTrigger: FC<ModelParameterTriggerProps> = ({
}
onMultipleModelConfigsChange(true, newModelConfigs)
}
const handleParamsChange = (params: any) => {
const handleParamsChange = (params: FormValue) => {
const newModelConfigs = [...multipleModelConfigs]
newModelConfigs[index] = {
...newModelConfigs[index],

View File

@@ -227,7 +227,7 @@ const Configuration: FC = () => {
}, [modelModeType])
const [dataSets, setDataSets] = useState<DataSet[]>([])
const contextVar = modelConfig.configs.prompt_variables.find((item: any) => item.is_context_var)?.key
const contextVar = modelConfig.configs.prompt_variables.find(item => item.is_context_var)?.key
const hasSetContextVar = !!contextVar
const [isShowSelectDataSet, { setTrue: showSelectDataSet, setFalse: hideSelectDataSet }] = useBoolean(false)
const selectedIds = dataSets.map(item => item.id)
@@ -245,7 +245,7 @@ const Configuration: FC = () => {
formattingChangedDispatcher()
let newDatasets = data
if (data.find(item => !item.name)) { // has not loaded selected dataset
const newSelected = produce(data, (draft: any) => {
const newSelected = produce(data, (draft) => {
data.forEach((item, index) => {
if (!item.name) { // not fetched database
const newItem = dataSets.find(i => i.id === item.id)
@@ -513,7 +513,7 @@ const Configuration: FC = () => {
if (modelConfig.chat_prompt_config && modelConfig.chat_prompt_config.prompt.length > 0)
setChatPromptConfig(modelConfig.chat_prompt_config)
else
setChatPromptConfig(clone(DEFAULT_CHAT_PROMPT_CONFIG) as any)
setChatPromptConfig(clone(DEFAULT_CHAT_PROMPT_CONFIG))
setCompletionPromptConfig(modelConfig.completion_prompt_config || clone(DEFAULT_COMPLETION_PROMPT_CONFIG) as any)
setCanReturnToSimpleMode(false)
}

View File

@@ -79,7 +79,7 @@ const PromptValuePanel: FC<IPromptValuePanelProps> = ({
}
const onClear = () => {
const newInputs: Record<string, any> = {}
const newInputs: Inputs = {}
promptVariables.forEach((item) => {
newInputs[item.key] = ''
})