From 1270edfffe91b056f76f78d4fca1c6fb2d19f5d6 Mon Sep 17 00:00:00 2001 From: Nimsara Fernando Date: Thu, 24 Oct 2024 14:46:50 +0530 Subject: [PATCH 1/2] Add `unsecured` Auth configuration --- .../components/AiVendors/AddEditAiVendor.jsx | 120 +++++++++++------- 1 file changed, 77 insertions(+), 43 deletions(-) diff --git a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx index e5d22a35b38..4e34c17f9ad 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx @@ -105,8 +105,8 @@ export default function AddEditAiVendor(props) { const [saving, setSaving] = useState(false); const { match: { params: { id } }, history } = props; const inputSources = ['payload', 'header', 'queryParams']; - const [authSource, setAuthSource] = useState('authHeader'); - const authSources = ['authHeader', 'authQueryParameter']; + const [authSource, setAuthSource] = useState('unsecured'); + const authSources = ['unsecured', 'authHeader', 'authQueryParameter']; const [validating, setValidating] = useState(false); const [file, setFile] = useState(null); const [initialState] = useState({ @@ -147,10 +147,10 @@ export default function AddEditAiVendor(props) { const pageTitle = id ? `${intl.formatMessage({ id: 'AiVendors.AddEditAiVendor.title.edit', - defaultMessage: 'AI Vendor - Edit ', + defaultMessage: 'AI/LLM Vendor - Edit ', })} ${state.name}` : intl.formatMessage({ id: 'AiVendors.AddEditAiVendor.title.new', - defaultMessage: 'AI Vendor - Create new', + defaultMessage: 'AI/LLM Vendor - Create new', }); useEffect(() => { @@ -170,8 +170,10 @@ export default function AddEditAiVendor(props) { if (newState.configurations.authQueryParameter) { setAuthSource('authQueryParameter'); - } else { + } else if (newState.configurations.authHeader) { setAuthSource('authHeader'); + } else { + setAuthSource('unsecured'); } dispatch({ field: 'all', value: newState }); @@ -190,6 +192,13 @@ export default function AddEditAiVendor(props) { .replace(/^./, (str) => str.toUpperCase()); }; + const camelCaseToSentence = (camelCaseStr) => { + return camelCaseStr + .replace(/([A-Z])/g, ' $1') + .replace(/^./, (str) => str.toUpperCase()) + .replace(/\b(?!^)\w+/g, (str) => str.toLowerCase()); + }; + const hasErrors = (fieldName, fieldValue, validatingActive) => { let error = false; if (!validatingActive) { @@ -198,7 +207,7 @@ export default function AddEditAiVendor(props) { switch (fieldName) { case 'name': if (fieldValue.trim() === '') { - error = `AI Vendor name ${intl.formatMessage({ + error = `AI/LLM Vendor name ${intl.formatMessage({ id: 'AiVendors.AddEditAiVendor.is.empty.error', defaultMessage: ' is empty', })}`; @@ -285,13 +294,13 @@ export default function AddEditAiVendor(props) { await new API().updateAiVendor(id, { ...newState, apiDefinition: file }); Alert.success(`${state.name} ${intl.formatMessage({ id: 'AiVendor.edit.success', - defaultMessage: ' - AI Vendor edited successfully.', + defaultMessage: ' - AI/LLM Vendor edited successfully.', })}`); } else { await new API().addAiVendor({ ...newState, apiDefinition: file }); Alert.success(`${state.name} ${intl.formatMessage({ id: 'AiVendor.add.success.msg', - defaultMessage: ' - AI Vendor added successfully.', + defaultMessage: ' - AI/LLM Vendor added successfully.', })}`); } setSaving(false); @@ -308,6 +317,20 @@ export default function AddEditAiVendor(props) { return true; }; + const clearAuthHeader = () => { + dispatch({ + field: 'authHeader', + value: '', + }); + }; + + const clearAuthQueryParameter = () => { + dispatch({ + field: 'authQueryParameter', + value: '', + }); + }; + return ( @@ -370,7 +393,7 @@ export default function AddEditAiVendor(props) { error={hasErrors('name', state.name, validating)} helperText={hasErrors('name', state.name, validating) || intl.formatMessage({ id: 'AiVendors.AddEditAiVendor.form.name.help', - defaultMessage: 'Name of the AI Vendor.', + defaultMessage: 'Name of the AI/LLM Vendor.', })} /> @@ -401,7 +424,7 @@ export default function AddEditAiVendor(props) { helperText={hasErrors('apiVersion', state.apiVersion, validating) || intl.formatMessage({ id: 'AiVendors.AddEditAiVendor.form.displayName.help', - defaultMessage: 'API Version of the AI Vendor.', + defaultMessage: 'API Version of the AI/LLM Vendor.', })} /> @@ -430,7 +453,7 @@ export default function AddEditAiVendor(props) { })} helperText={intl.formatMessage({ id: 'AiVendors.AddEditAiVendor.form.description.help', - defaultMessage: 'Description of the AI Vendor.', + defaultMessage: 'Description of the AI/LLM Vendor.', })} /> @@ -526,7 +549,10 @@ export default function AddEditAiVendor(props) { 'Admin.AiVendor.form.llm.' + `${metadata.attributeName}.select.input.message` } - defaultMessage={`Path to ${metadata.attributeName}`} + defaultMessage={ + `${camelCaseToSentence(metadata.attributeName)}` + + ' identifier' + } /> * @@ -578,7 +604,7 @@ export default function AddEditAiVendor(props) { > @@ -637,7 +663,11 @@ export default function AddEditAiVendor(props) { id='Admin.AiVendor.form.llm.auth.select' name='authSource' value={authSource} - onChange={(e) => setAuthSource(e.target.value)} + onChange={(e) => { + clearAuthHeader(); + clearAuthQueryParameter(); + setAuthSource(e.target.value); + }} data-testid='ai-vendor-llm-auth-select' > {authSources @@ -647,31 +677,35 @@ export default function AddEditAiVendor(props) { ))} - - - - )} - fullWidth - variant='outlined' - value={authSource === 'authHeader' - ? state.configurations.authHeader ?? '' - : state.configurations.authQueryParameter ?? ''} - onChange={(e) => dispatch({ - field: authSource, - value: e.target.value, - })} - /> + {authSource !== 'unsecured' && ( + + + + )} + fullWidth + variant='outlined' + value={authSource === 'authHeader' + ? state.configurations.authHeader ?? '' + : state.configurations.authQueryParameter ?? ''} + onChange={(e) => dispatch({ + field: authSource, + value: e.target.value, + })} + /> + )} @@ -691,7 +725,7 @@ export default function AddEditAiVendor(props) { > @@ -737,7 +771,7 @@ export default function AddEditAiVendor(props) { validating, ) || intl.formatMessage({ id: 'AiVendors.AddEditAiVendor.form.name.help', - defaultMessage: 'Connector Type for AI Vendor', + defaultMessage: 'Connector Type for AI/LLM Vendor', })} /> From 0ad6e8c202adee0eb9c45b104e29f037e8a6a8fa Mon Sep 17 00:00:00 2001 From: Nimsara Fernando Date: Thu, 24 Oct 2024 16:21:05 +0530 Subject: [PATCH 2/2] Change default auth type to `authHeader` --- .../src/app/components/AiVendors/AddEditAiVendor.jsx | 2 +- .../src/app/components/AiVendors/DeleteAiVendor.jsx | 6 +++--- .../src/app/components/AiVendors/ListAiVendors.jsx | 12 ++++++------ .../src/app/components/Base/RouteMenuMapping.jsx | 6 +++--- 4 files changed, 13 insertions(+), 13 deletions(-) diff --git a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx index 4e34c17f9ad..6ac150d0f31 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/AddEditAiVendor.jsx @@ -105,7 +105,7 @@ export default function AddEditAiVendor(props) { const [saving, setSaving] = useState(false); const { match: { params: { id } }, history } = props; const inputSources = ['payload', 'header', 'queryParams']; - const [authSource, setAuthSource] = useState('unsecured'); + const [authSource, setAuthSource] = useState('authHeader'); const authSources = ['unsecured', 'authHeader', 'authQueryParameter']; const [validating, setValidating] = useState(false); const [file, setFile] = useState(null); diff --git a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/DeleteAiVendor.jsx b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/DeleteAiVendor.jsx index 3b06b3feae0..73a7d21d2f0 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/DeleteAiVendor.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/DeleteAiVendor.jsx @@ -38,7 +38,7 @@ function DeleteAiVendor({ updateList, dataRow }) { .then(() => ( )) .catch((error) => { @@ -53,7 +53,7 @@ function DeleteAiVendor({ updateList, dataRow }) { diff --git a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/ListAiVendors.jsx b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/ListAiVendors.jsx index d3917779cd5..29b4a5b4123 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/AiVendors/ListAiVendors.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/AiVendors/ListAiVendors.jsx @@ -108,7 +108,7 @@ export default function ListAiVendors() { > {intl.formatMessage({ id: 'AiVendors.ListAiVendors.addNewAiVendor', - defaultMessage: 'Add AI Vendor', + defaultMessage: 'Add AI/LLM Vendor', })} ); @@ -119,7 +119,7 @@ export default function ListAiVendors() { name: 'name', label: intl.formatMessage({ id: 'AiVendors.ListAiVendors.table.header.label.aiVendorName', - defaultMessage: 'AI Vendor Name', + defaultMessage: 'AI/LLM Vendor Name', }), options: { customBodyRender: (value, tableMeta) => { @@ -214,7 +214,7 @@ export default function ListAiVendors() { if (dataRow.builtInSupport) { tooltipTitle = intl.formatMessage({ id: 'AiVendors.ListAiVendors.table.is.used.delete.tooltip', - defaultMessage: 'Default AI Vendors cannot be deleted', + defaultMessage: 'Default AI/LLM Vendors cannot be deleted', }); } return ( @@ -241,7 +241,7 @@ export default function ListAiVendors() { pageStyle: 'paperLess', title: intl.formatMessage({ id: 'AiVendors.ListAiVendors.List.title', - defaultMessage: 'AI Vendors', + defaultMessage: 'AI/LLM Vendors', }), }; @@ -255,7 +255,7 @@ export default function ListAiVendors() { > ), @@ -268,7 +268,7 @@ export default function ListAiVendors() { > ), diff --git a/portals/admin/src/main/webapp/source/src/app/components/Base/RouteMenuMapping.jsx b/portals/admin/src/main/webapp/source/src/app/components/Base/RouteMenuMapping.jsx index 6c69380a75c..a17c8856969 100644 --- a/portals/admin/src/main/webapp/source/src/app/components/Base/RouteMenuMapping.jsx +++ b/portals/admin/src/main/webapp/source/src/app/components/Base/RouteMenuMapping.jsx @@ -239,7 +239,7 @@ const RouteMenuMapping = (intl) => [ id: 'Ai Vendors', displayText: intl.formatMessage({ id: 'Base.RouteMenuMapping.aivendors', - defaultMessage: 'AI Vendors', + defaultMessage: 'AI/LLM Vendors', }), path: '/settings/ai-vendors', component: AiVendors, @@ -249,7 +249,7 @@ const RouteMenuMapping = (intl) => [ id: 'Add AI Vendor', displayText: intl.formatMessage({ id: 'Base.RouteMenuMapping.aivendors.items.Adding', - defaultMessage: 'Add AI Vendor', + defaultMessage: 'Add AI/LLM Vendor', }), path: '/settings/ai-vendors/create', }, @@ -257,7 +257,7 @@ const RouteMenuMapping = (intl) => [ id: 'Edit AI Vendor', displayText: intl.formatMessage({ id: 'Base.RouteMenuMapping.aivendors.items.Editing', - defaultMessage: 'Edit AI Vendor', + defaultMessage: 'Edit AI/LLM Vendor', }), path: '/settings/ai-vendors/(.*?)$', },