import { useEffect, useState } from 'react'; import { useForm, FormProvider } from 'react-hook-form'; import { AuthTypeEnum, AuthorizationTypeEnum, TokenExchangeMethodEnum, } from 'librechat-data-provider'; import type { AssistantPanelProps, ActionAuthForm } from '~/common'; import { Dialog, DialogTrigger } from '~/components/ui'; import { useDeleteAction } from '~/data-provider'; import { NewTrashIcon } from '~/components/svg'; import ActionsInput from './ActionsInput'; import ActionsAuth from './ActionsAuth'; import { Panel } from '~/common'; export default function ActionsPanel({ // activePanel, action, setAction, setActivePanel, assistant_id, }: AssistantPanelProps) { const [openAuthDialog, setOpenAuthDialog] = useState(false); const deleteAction = useDeleteAction({ onSuccess: () => { setActivePanel(Panel.builder); setAction(undefined); }, }); const methods = useForm({ defaultValues: { /* General */ type: AuthTypeEnum.None, saved_auth_fields: false, /* API key */ api_key: '', authorization_type: AuthorizationTypeEnum.Basic, custom_auth_header: '', /* OAuth */ oauth_client_id: '', oauth_client_secret: '', authorization_url: '', client_url: '', scope: '', token_exchange_method: TokenExchangeMethodEnum.DefaultPost, }, }); const { reset, watch } = methods; const type = watch('type'); useEffect(() => { if (action?.metadata?.auth) { reset({ type: action.metadata.auth.type || AuthTypeEnum.None, saved_auth_fields: false, api_key: action.metadata.api_key ?? '', authorization_type: action.metadata.auth.authorization_type || AuthorizationTypeEnum.Basic, oauth_client_id: action.metadata.oauth_client_id ?? '', oauth_client_secret: action.metadata.oauth_client_secret ?? '', authorization_url: action.metadata.auth.authorization_url ?? '', client_url: action.metadata.auth.client_url ?? '', scope: action.metadata.auth.scope ?? '', token_exchange_method: action.metadata.auth.token_exchange_method ?? TokenExchangeMethodEnum.DefaultPost, }); } }, [action, reset]); return (
{!!action && (
)}
{(action ? 'Edit' : 'Add') + ' ' + 'actions'}
{/* TODO: use App title */} Let your Assistant retrieve information or take actions outside of LibreChat.
{/* */}
{type}
); }