({ show, dialogProps, onCancel })
| 85 | } |
| 86 | |
| 87 | const APICodeDialog = ({ show, dialogProps, onCancel }) => { |
| 88 | const portalElement = document.getElementById('portal') |
| 89 | const navigate = useNavigate() |
| 90 | const dispatch = useDispatch() |
| 91 | const theme = useTheme() |
| 92 | const chatflow = useSelector((state) => state.canvas.chatflow) |
| 93 | const apiConfig = chatflow?.apiConfig ? JSON.parse(chatflow.apiConfig) : {} |
| 94 | const overrideConfigStatus = apiConfig?.overrideConfig?.status !== undefined ? apiConfig.overrideConfig.status : false |
| 95 | |
| 96 | const startNodeInputs = useMemo(() => { |
| 97 | if (!chatflow?.flowData) return null |
| 98 | try { |
| 99 | const parsed = JSON.parse(chatflow.flowData) |
| 100 | const startNode = (parsed.nodes || []).find((n) => n?.data?.name === 'startAgentflow') |
| 101 | return startNode?.data?.inputs ?? null |
| 102 | } catch { |
| 103 | return null |
| 104 | } |
| 105 | }, [chatflow?.flowData]) |
| 106 | |
| 107 | const startInputType = startNodeInputs?.startInputType |
| 108 | const isWebhookFlow = startInputType === 'webhookTrigger' |
| 109 | const isScheduleFlow = startInputType === 'scheduleInput' |
| 110 | const webhookMethod = (startNodeInputs?.webhookMethod || 'POST').toUpperCase() |
| 111 | const webhookContentType = startNodeInputs?.webhookContentType || 'application/json' |
| 112 | const webhookEnableAuth = startNodeInputs?.webhookEnableAuth === true |
| 113 | const webhookSignatureHeader = startNodeInputs?.webhookSignatureHeader || 'x-webhook-signature' |
| 114 | const webhookResponseMode = startNodeInputs?.webhookResponseMode || 'sync' |
| 115 | |
| 116 | const codes = useMemo(() => { |
| 117 | if (isWebhookFlow || isScheduleFlow) return ['Python', 'JavaScript', 'cURL'] |
| 118 | return ['Embed', 'Python', 'JavaScript', 'cURL', 'Share Chatbot'] |
| 119 | }, [isWebhookFlow, isScheduleFlow]) |
| 120 | const [value, setValue] = useState(0) |
| 121 | const [apiKeys, setAPIKeys] = useState([]) |
| 122 | const [chatflowApiKeyId, setChatflowApiKeyId] = useState('') |
| 123 | const [selectedApiKey, setSelectedApiKey] = useState({}) |
| 124 | const [checkboxVal, setCheckbox] = useState(false) |
| 125 | const [nodeConfig, setNodeConfig] = useState({}) |
| 126 | const [nodeConfigExpanded, setNodeConfigExpanded] = useState({}) |
| 127 | const [nodeOverrides, setNodeOverrides] = useState(apiConfig?.overrideConfig?.nodes ?? null) |
| 128 | const [variableOverrides, setVariableOverrides] = useState(apiConfig?.overrideConfig?.variables ?? []) |
| 129 | |
| 130 | const getAllAPIKeysApi = useApi(apiKeyApi.getAllAPIKeys) |
| 131 | const updateChatflowApi = useApi(chatflowsApi.updateChatflow) |
| 132 | const getIsChatflowStreamingApi = useApi(chatflowsApi.getIsChatflowStreaming) |
| 133 | const getConfigApi = useApi(configApi.getConfig) |
| 134 | const getAllVariablesApi = useApi(variablesApi.getAllVariables) |
| 135 | const isGlobal = useSelector((state) => state.auth.isGlobal) |
| 136 | const { hasPermission } = useAuth() |
| 137 | |
| 138 | // Memoize keyOptions to prevent recreation on hover |
| 139 | const keyOptions = useMemo(() => { |
| 140 | if (!getAllAPIKeysApi.data) return [] |
| 141 | |
| 142 | const options = [ |
| 143 | { |
| 144 | label: 'No Authorization', |
nothing calls this directly
no test coverage detected