Skip to content

Commit

Permalink
Merge pull request #830 from nimsara66/authConfig
Browse files Browse the repository at this point in the history
Add `unsecured` auth configuration
  • Loading branch information
PasanT9 authored Oct 24, 2024
2 parents 32ed224 + 0ad6e8c commit eecb174
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default function AddEditAiVendor(props) {
const { match: { params: { id } }, history } = props;
const inputSources = ['payload', 'header', 'queryParams'];
const [authSource, setAuthSource] = useState('authHeader');
const authSources = ['authHeader', 'authQueryParameter'];
const authSources = ['unsecured', 'authHeader', 'authQueryParameter'];
const [validating, setValidating] = useState(false);
const [file, setFile] = useState(null);
const [initialState] = useState({
Expand Down Expand Up @@ -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(() => {
Expand All @@ -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 });
Expand All @@ -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) {
Expand All @@ -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',
})}`;
Expand Down Expand Up @@ -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);
Expand All @@ -308,6 +317,20 @@ export default function AddEditAiVendor(props) {
return true;
};

const clearAuthHeader = () => {
dispatch({
field: 'authHeader',
value: '',
});
};

const clearAuthQueryParameter = () => {
dispatch({
field: 'authQueryParameter',
value: '',
});
};

return (
<StyledContentBase
pageStyle='half'
Expand Down Expand Up @@ -336,7 +359,7 @@ export default function AddEditAiVendor(props) {
>
<FormattedMessage
id='AiVendors.AddEditAiVendor.general.details.description'
defaultMessage='Provide name and description of the AI Vendor'
defaultMessage='Provide name and description of the AI/LLM Vendor'
/>
</Typography>
</Grid>
Expand Down Expand Up @@ -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.',
})}
/>
</Grid>
Expand Down Expand Up @@ -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.',
})}
/>
</Box>
Expand Down Expand Up @@ -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.',
})}
/>
</Box>
Expand Down Expand Up @@ -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'
}
/>

<StyledSpan>*</StyledSpan>
Expand Down Expand Up @@ -578,7 +604,7 @@ export default function AddEditAiVendor(props) {
>
<FormattedMessage
id='AiVendors.AddEditAiVendor.apiDefinition.description'
defaultMessage='Upload API Definition of the AI Vendor'
defaultMessage='Upload API Definition of the AI/LLM Vendor'
/>
</Typography>
</Grid>
Expand Down Expand Up @@ -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
Expand All @@ -647,31 +677,35 @@ export default function AddEditAiVendor(props) {
</MenuItem>
))}
</Select>
<TextField
id='Admin.AiVendor.form.llm.auth.select.input'
margin='dense'
name='model.auth.attributeIdentifier'
label={(
<span>
<FormattedMessage
id={
'Admin.AiVendor.form.llm.'
+ 'auth.select.input.message'
}
defaultMessage='Authorization key'
/>
</span>
)}
fullWidth
variant='outlined'
value={authSource === 'authHeader'
? state.configurations.authHeader ?? ''
: state.configurations.authQueryParameter ?? ''}
onChange={(e) => dispatch({
field: authSource,
value: e.target.value,
})}
/>
{authSource !== 'unsecured' && (
<TextField
id='Admin.AiVendor.form.llm.auth.select.input'
margin='dense'
name='model.auth.attributeIdentifier'
label={(
<span>
<FormattedMessage
id={
'Admin.AiVendor.form.llm.'
+ 'auth.select.input.message'
}
defaultMessage={
`${camelCaseToSentence(authSource)} identifier`
}
/>
</span>
)}
fullWidth
variant='outlined'
value={authSource === 'authHeader'
? state.configurations.authHeader ?? ''
: state.configurations.authQueryParameter ?? ''}
onChange={(e) => dispatch({
field: authSource,
value: e.target.value,
})}
/>
)}
</FormControl>
</Box>
</>
Expand All @@ -691,7 +725,7 @@ export default function AddEditAiVendor(props) {
>
<FormattedMessage
id='AiVendors.AddEditAiVendor.connectorType'
defaultMessage='Connector Type for AI Vendor'
defaultMessage='Connector Type for AI/LLM Vendor'
/>
</Typography>
<Typography
Expand All @@ -702,7 +736,7 @@ export default function AddEditAiVendor(props) {
>
<FormattedMessage
id='AiVendors.AddEditAiVendor.connectorType.description'
defaultMessage='Reference to the connector model for the AI vendor'
defaultMessage='Reference to the connector model for the AI/LLM vendor'
/>
</Typography>
</Grid>
Expand Down Expand Up @@ -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',
})}
/>
</Box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function DeleteAiVendor({ updateList, dataRow }) {
.then(() => (
<FormattedMessage
id='AdminPages.AiVendor.Delete.form.delete.successful'
defaultMessage='AI Vendor deleted successfully'
defaultMessage='AI/LLM Vendor deleted successfully'
/>
))
.catch((error) => {
Expand All @@ -53,7 +53,7 @@ function DeleteAiVendor({ updateList, dataRow }) {
<FormDialogBase
title={intl.formatMessage({
id: 'AdminPages.AiVendor.Delete.form.delete.dialog.title',
defaultMessage: 'Delete AI Vendor ?',
defaultMessage: 'Delete AI/LLM Vendor ?',
})}
saveButtonText={intl.formatMessage({
id: 'AdminPages.AiVendor.Delete.form.delete.dialog.btn',
Expand All @@ -70,7 +70,7 @@ function DeleteAiVendor({ updateList, dataRow }) {
<DialogContentText>
<FormattedMessage
id='AdminPages.AiVendor.Delete.form.delete.confirmation.message'
defaultMessage='Are you sure you want to delete this AI Vendor ?'
defaultMessage='Are you sure you want to delete this AI/LLM Vendor ?'
/>
</DialogContentText>
</FormDialogBase>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export default function ListAiVendors() {
>
{intl.formatMessage({
id: 'AiVendors.ListAiVendors.addNewAiVendor',
defaultMessage: 'Add AI Vendor',
defaultMessage: 'Add AI/LLM Vendor',
})}
</Button>
);
Expand All @@ -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) => {
Expand Down Expand Up @@ -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 (
Expand All @@ -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',
}),
};

Expand All @@ -255,7 +255,7 @@ export default function ListAiVendors() {
>
<FormattedMessage
id='AdminPages.AiVendors.List.empty.content.Aivendors'
defaultMessage='It is possible to register an AI Vendor.'
defaultMessage='It is possible to register an AI/LLM Vendor.'
/>
</Typography>
),
Expand All @@ -268,7 +268,7 @@ export default function ListAiVendors() {
>
<FormattedMessage
id='AiVendors.ListAiVendors.empty.title'
defaultMessage='AI Vendors'
defaultMessage='AI/LLM Vendors'
/>
</Typography>
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -249,15 +249,15 @@ 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',
},
{
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/(.*?)$',
},
Expand Down

0 comments on commit eecb174

Please sign in to comment.