Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

tool.ts 1.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import type {
  2. InputVar,
  3. ToolWithProvider,
  4. } from '../types'
  5. import type { ToolNodeType } from '../nodes/tool/types'
  6. import { CollectionType } from '@/app/components/tools/types'
  7. import { toolParametersToFormSchemas } from '@/app/components/tools/utils/to-form-schema'
  8. import { canFindTool } from '@/utils'
  9. export const getToolCheckParams = (
  10. toolData: ToolNodeType,
  11. buildInTools: ToolWithProvider[],
  12. customTools: ToolWithProvider[],
  13. workflowTools: ToolWithProvider[],
  14. language: string,
  15. ) => {
  16. const { provider_id, provider_type, tool_name } = toolData
  17. const isBuiltIn = provider_type === CollectionType.builtIn
  18. const currentTools = provider_type === CollectionType.builtIn ? buildInTools : provider_type === CollectionType.custom ? customTools : workflowTools
  19. const currCollection = currentTools.find(item => canFindTool(item.id, provider_id))
  20. const currTool = currCollection?.tools.find(tool => tool.name === tool_name)
  21. const formSchemas = currTool ? toolParametersToFormSchemas(currTool.parameters) : []
  22. const toolInputVarSchema = formSchemas.filter(item => item.form === 'llm')
  23. const toolSettingSchema = formSchemas.filter(item => item.form !== 'llm')
  24. return {
  25. toolInputsSchema: (() => {
  26. const formInputs: InputVar[] = []
  27. toolInputVarSchema.forEach((item: any) => {
  28. formInputs.push({
  29. label: item.label[language] || item.label.en_US,
  30. variable: item.variable,
  31. type: item.type,
  32. required: item.required,
  33. })
  34. })
  35. return formInputs
  36. })(),
  37. notAuthed: isBuiltIn && !!currCollection?.allow_delete && !currCollection?.is_team_authorization,
  38. toolSettingSchema,
  39. language,
  40. }
  41. }