feat: support tool multi-select input

This commit is contained in:
hjlarry 2025-12-05 14:41:05 +08:00
parent b509661b08
commit 2b97b280c9
4 changed files with 17 additions and 5 deletions

View File

@ -76,9 +76,13 @@ class PluginParameter(BaseModel):
auto_generate: PluginParameterAutoGenerate | None = None auto_generate: PluginParameterAutoGenerate | None = None
template: PluginParameterTemplate | None = None template: PluginParameterTemplate | None = None
required: bool = False required: bool = False
default: Union[float, int, str, bool] | None = None default: Union[float, int, str, bool, list] | None = None
min: Union[float, int] | None = None min: Union[float, int] | None = None
max: Union[float, int] | None = None max: Union[float, int] | None = None
multiple: bool | None = Field(
default=False,
description="Whether the parameter is multiple select, only valid for select or dynamic-select type",
)
precision: int | None = None precision: int | None = None
options: list[PluginParameterOption] = Field(default_factory=list) options: list[PluginParameterOption] = Field(default_factory=list)
@ -112,8 +116,11 @@ def cast_parameter_value(typ: StrEnum, value: Any, /):
): ):
if value is None: if value is None:
return "" return ""
else: if isinstance(value, list):
return value if isinstance(value, str) else str(value) return value
if isinstance(value, str):
return value
return str(value)
case PluginParameterType.BOOLEAN: case PluginParameterType.BOOLEAN:
if value is None: if value is None:

View File

@ -54,8 +54,8 @@ class ToolNodeData(BaseNodeData, ToolEntity):
for val in value: for val in value:
if not isinstance(val, str): if not isinstance(val, str):
raise ValueError("value must be a list of strings") raise ValueError("value must be a list of strings")
elif typ == "constant" and not isinstance(value, str | int | float | bool | dict): elif typ == "constant" and not isinstance(value, str | int | float | bool | list | dict):
raise ValueError("value must be a string, int, float, bool or dict") raise ValueError("value must be a string, int, float, bool, list or dict")
return typ return typ
tool_parameters: dict[str, ToolInput] tool_parameters: dict[str, ToolInput]

View File

@ -121,6 +121,7 @@ export type CredentialFormSchemaBase = {
label: TypeWithI18N label: TypeWithI18N
type: FormTypeEnum type: FormTypeEnum
required: boolean required: boolean
multiple?: boolean
default?: string default?: string
tooltip?: TypeWithI18N tooltip?: TypeWithI18N
show_on: FormShowOnObject[] show_on: FormShowOnObject[]

View File

@ -110,6 +110,8 @@ const FormInputItem: FC<Props> = ({
return VarType.arrayFile return VarType.arrayFile
else if (type === FormTypeEnum.file) else if (type === FormTypeEnum.file)
return VarType.file return VarType.file
else if (isMultipleSelect)
return VarType.array
else if (isSelect) else if (isSelect)
return VarType.string return VarType.string
// else if (isAppSelector) // else if (isAppSelector)
@ -129,6 +131,8 @@ const FormInputItem: FC<Props> = ({
const getFilterVar = () => { const getFilterVar = () => {
if (isNumber) if (isNumber)
return (varPayload: any) => varPayload.type === VarType.number return (varPayload: any) => varPayload.type === VarType.number
else if (isMultipleSelect)
return (varPayload: any) => [VarType.array, VarType.arrayString, VarType.arrayNumber, VarType.arrayObject].includes(varPayload.type)
else if (isString) else if (isString)
return (varPayload: any) => [VarType.string, VarType.number, VarType.secret].includes(varPayload.type) return (varPayload: any) => [VarType.string, VarType.number, VarType.secret].includes(varPayload.type)
else if (isFile) else if (isFile)