wwf
3 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
app/components/tools/utils/to-form-schema.ts
@@ -1,5 +1,5 @@
import type { ToolCredential, ToolParameter } from '../types'
export const toType = (type: string) => {
const toType = (type: string) => {
  switch (type) {
    case 'string':
      return 'text-input'
@@ -62,35 +62,4 @@
      newValues[formSchema.variable] = formSchema.default
  })
  return newValues
}
export const generateFormValue = (value: Record<string, any>, formSchemas: { variable: string; default?: any }[], isReasoning = false) => {
  const newValues = {} as any
  formSchemas.forEach((formSchema) => {
    const itemValue = value[formSchema.variable]
    if ((formSchema.default !== undefined) && (value === undefined || itemValue === null || itemValue === '' || itemValue === undefined)) {
      newValues[formSchema.variable] = {
        ...(isReasoning ? { value: null, auto: 1 } : { value: formSchema.default }),
      }
    }
  })
  return newValues
}
export const getPlainValue = (value: Record<string, any>) => {
  const plainValue = { ...value }
  Object.keys(plainValue).forEach((key) => {
    plainValue[key] = value[key].value
  })
  return plainValue
}
export const getStructureValue = (value: Record<string, any>) => {
  const newValue = { ...value } as any
  Object.keys(newValue).forEach((key) => {
    newValue[key] = {
      value: value[key],
    }
  })
  return newValue
}