wwf
2 天以前 a430284aa21e3ae1f0d5654e55b2ad2852519cc2
app/components/workflow/nodes/tool/use-config.ts
@@ -18,7 +18,6 @@
  useFetchToolsData,
  useNodesReadOnly,
} from '@/app/components/workflow/hooks'
import { canFindTool } from '@/utils'
const useConfig = (id: string, payload: ToolNodeType) => {
  const { nodesReadOnly: readOnly } = useNodesReadOnly()
@@ -30,9 +29,8 @@
  /*
  * tool_configurations: tool setting, not dynamic setting
  * tool_parameters: tool dynamic setting(by user)
  * output_schema: tool dynamic output
  */
  const { provider_id, provider_type, tool_name, tool_configurations, output_schema } = inputs
  const { provider_id, provider_type, tool_name, tool_configurations } = inputs
  const isBuiltIn = provider_type === CollectionType.builtIn
  const buildInTools = useStore(s => s.buildInTools)
  const customTools = useStore(s => s.customTools)
@@ -50,7 +48,7 @@
        return []
    }
  })()
  const currCollection = currentTools.find(item => canFindTool(item.id, provider_id))
  const currCollection = currentTools.find(item => item.id === provider_id)
  // Auth
  const needAuth = !!currCollection?.allow_delete
@@ -93,7 +91,7 @@
        const value = newConfig[key]
        if (schema?.type === 'boolean') {
          if (typeof value === 'string')
            newConfig[key] = Number.parseInt(value, 10)
            newConfig[key] = parseInt(value, 10)
          if (typeof value === 'boolean')
            newConfig[key] = value ? 1 : 0
@@ -101,7 +99,7 @@
        if (schema?.type === 'number-input') {
          if (typeof value === 'string' && value !== '')
            newConfig[key] = Number.parseFloat(value)
            newConfig[key] = parseFloat(value)
        }
      })
      draft.tool_configurations = newConfig
@@ -164,7 +162,7 @@
  const [inputVarValues, doSetInputVarValues] = useState<Record<string, any>>({})
  const setInputVarValues = (value: Record<string, any>) => {
    doSetInputVarValues(value)
    // eslint-disable-next-line ts/no-use-before-define
    // eslint-disable-next-line @typescript-eslint/no-use-before-define
    setRunInputData(value)
  }
  // fill single run form variable with constant value first time
@@ -256,39 +254,6 @@
    doHandleRun(addMissedVarData)
  }
  const outputSchema = useMemo(() => {
    const res: any[] = []
    if (!output_schema)
      return []
    Object.keys(output_schema.properties).forEach((outputKey) => {
      const output = output_schema.properties[outputKey]
      const type = output.type
      if (type === 'object') {
        res.push({
          name: outputKey,
          value: output,
        })
      }
      else {
        res.push({
          name: outputKey,
          type: output.type === 'array'
            ? `Array[${output.items?.type.slice(0, 1).toLocaleUpperCase()}${output.items?.type.slice(1)}]`
            : `${output.type.slice(0, 1).toLocaleUpperCase()}${output.type.slice(1)}`,
          description: output.description,
        })
      }
    })
    return res
  }, [output_schema])
  const hasObjectOutput = useMemo(() => {
    if (!output_schema)
      return false
    const properties = output_schema.properties
    return Object.keys(properties).some(key => properties[key].type === 'object')
  }, [output_schema])
  return {
    readOnly,
    inputs,
@@ -317,8 +282,6 @@
    handleRun,
    handleStop,
    runResult,
    outputSchema,
    hasObjectOutput,
  }
}