mirror of
http://112.124.100.131/huang.ze/ebiz-dify-ai.git
synced 2025-12-10 11:26:52 +08:00
feat: support assistant frontend (#2139)
Co-authored-by: StyleZhang <jasonapring2015@outlook.com>
This commit is contained in:
64
web/app/components/tools/utils/to-form-schema.ts
Normal file
64
web/app/components/tools/utils/to-form-schema.ts
Normal file
@@ -0,0 +1,64 @@
|
||||
import type { ToolCredential, ToolParameter } from '../types'
|
||||
const toType = (type: string) => {
|
||||
switch (type) {
|
||||
case 'string':
|
||||
return 'text-input'
|
||||
case 'number':
|
||||
return 'number-input'
|
||||
default:
|
||||
return type
|
||||
}
|
||||
}
|
||||
export const toolParametersToFormSchemas = (parameters: ToolParameter[]) => {
|
||||
if (!parameters)
|
||||
return []
|
||||
|
||||
const formSchemas = parameters.map((parameter) => {
|
||||
return {
|
||||
...parameter,
|
||||
variable: parameter.name,
|
||||
type: toType(parameter.type),
|
||||
show_on: [],
|
||||
options: parameter.options?.map((option) => {
|
||||
return {
|
||||
...option,
|
||||
show_on: [],
|
||||
}
|
||||
}),
|
||||
tooltip: parameter.human_description,
|
||||
}
|
||||
})
|
||||
return formSchemas
|
||||
}
|
||||
|
||||
export const toolCredentialToFormSchemas = (parameters: ToolCredential[]) => {
|
||||
if (!parameters)
|
||||
return []
|
||||
|
||||
const formSchemas = parameters.map((parameter) => {
|
||||
return {
|
||||
...parameter,
|
||||
variable: parameter.name,
|
||||
label: parameter.label,
|
||||
tooltip: parameter.help,
|
||||
show_on: [],
|
||||
options: parameter.options?.map((option) => {
|
||||
return {
|
||||
...option,
|
||||
show_on: [],
|
||||
}
|
||||
}),
|
||||
}
|
||||
})
|
||||
return formSchemas
|
||||
}
|
||||
|
||||
export const addDefaultValue = (value: Record<string, any>, formSchemas: { variable: string; default?: any }[]) => {
|
||||
const newValues = { ...value }
|
||||
formSchemas.forEach((formSchema) => {
|
||||
const itemValue = value[formSchema.variable]
|
||||
if (formSchema.default && (value === undefined || itemValue === null || itemValue === ''))
|
||||
newValues[formSchema.variable] = formSchema.default
|
||||
})
|
||||
return newValues
|
||||
}
|
||||
Reference in New Issue
Block a user