| | |
| | | useFetchToolsData, |
| | | useNodesReadOnly, |
| | | } from '@/app/components/workflow/hooks' |
| | | import { canFindTool } from '@/utils' |
| | | |
| | | const useConfig = (id: string, payload: ToolNodeType) => { |
| | | const { nodesReadOnly: readOnly } = useNodesReadOnly() |
| | |
| | | /* |
| | | * 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) |
| | |
| | | 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 |
| | |
| | | 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 |
| | |
| | | |
| | | if (schema?.type === 'number-input') { |
| | | if (typeof value === 'string' && value !== '') |
| | | newConfig[key] = Number.parseFloat(value) |
| | | newConfig[key] = parseFloat(value) |
| | | } |
| | | }) |
| | | draft.tool_configurations = newConfig |
| | |
| | | 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 |
| | |
| | | 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, |
| | |
| | | handleRun, |
| | | handleStop, |
| | | runResult, |
| | | outputSchema, |
| | | hasObjectOutput, |
| | | } |
| | | } |
| | | |