Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Obs AI Assistant] fix knowledge base installation state #206130

Merged
merged 12 commits into from
Jan 15, 2025
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@ export function WelcomeMessageKnowledgeBase({
const [isPopoverOpen, setIsPopoverOpen] = useState(false);
const handleClosePopover = () => setIsPopoverOpen(false);

const [checkForInstallStatus, setCheckForInstallStatus] = useState(false);
const [pollKnowledgeBaseStatus, setPollKnowledgeBaseStatus] = useState(false);

// When the knowledge base is installed, show a success message for 3 seconds
// installing state when the inference endpoint is being created and the model is being deployed
const isInstalling =
knowledgeBase.isInstalling ||
(knowledgeBase.status.value?.endpoint && knowledgeBase.status.value?.ready === false);

// start polling kb status if inference endpoint is being created or has been created but model isn't ready
useEffect(() => {
if (isInstalling) {
setPollKnowledgeBaseStatus(true);
}
}, [isInstalling]);

// When the knowledge base is installed and ready, show a success message for 3 seconds
useEffect(() => {
if (previouslyNotInstalled && knowledgeBase.status.value?.ready) {
setTimeoutTime(3000);
Expand All @@ -51,33 +63,30 @@ export function WelcomeMessageKnowledgeBase({
}
}, [knowledgeBase.status.value?.ready, previouslyNotInstalled, reset]);

// When the knowledge base is installed, stop checking for install status
// When the knowledge base is ready, stop polling for status
useEffect(() => {
if (!checkForInstallStatus && knowledgeBase.status.value?.ready) {
setCheckForInstallStatus(false);
if (knowledgeBase.status.value?.ready) {
setPollKnowledgeBaseStatus(false);
}
}, [checkForInstallStatus, knowledgeBase.status.value?.ready]);
}, [pollKnowledgeBaseStatus, knowledgeBase.status.value?.ready]);

// Check for install status every 5 seconds
// poll for knowledge base status every 5 seconds
useInterval(
() => {
knowledgeBase.status.refresh();
},
checkForInstallStatus ? 5000 : null
pollKnowledgeBaseStatus ? 5000 : null
);

const handleRetryInstall = async () => {
setCheckForInstallStatus(true);
// gets called if there was an error previously during install or user has a preconfigured connector
// and is first time installing
const handleInstall = async () => {
setIsPopoverOpen(false);

await knowledgeBase.install().then(() => {
setCheckForInstallStatus(false);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't stop checking kb status after /setup has returned. model may not be ready.

});
await knowledgeBase.install();
};

return knowledgeBase.status.value?.ready !== undefined ? (
<>
{knowledgeBase.isInstalling ? (
{isInstalling ? (
<>
<EuiText color="subdued" size="s">
{i18n.translate('xpack.aiAssistant.welcomeMessage.weAreSettingUpTextLabel', {
Expand All @@ -100,69 +109,70 @@ export function WelcomeMessageKnowledgeBase({
</>
) : null}

{connectors.connectors?.length ? (
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved check to parent. what case would we want to mount this component before setting up a connector? can't think of one.

(!knowledgeBase.isInstalling && knowledgeBase.installError) ||
(!knowledgeBase.isInstalling &&
knowledgeBase.status.loading === false &&
knowledgeBase.status.value.ready === false) ? (
<>
<EuiText color="subdued" size="s">
{i18n.translate(
'xpack.aiAssistant.welcomeMessageKnowledgeBase.yourKnowledgeBaseIsNotSetUpCorrectlyLabel',
{ defaultMessage: `Your Knowledge base hasn't been set up.` }
)}
</EuiText>

<EuiSpacer size="m" />

<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<div>
<EuiButton
color="primary"
data-test-subj="observabilityAiAssistantWelcomeMessageSetUpKnowledgeBaseButton"
fill
isLoading={checkForInstallStatus}
iconType="importAction"
onClick={handleRetryInstall}
>
{i18n.translate('xpack.aiAssistant.welcomeMessage.retryButtonLabel', {
defaultMessage: 'Install Knowledge base',
})}
</EuiButton>
</div>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiPopover
button={
<EuiButtonEmpty
data-test-subj="observabilityAiAssistantWelcomeMessageInspectErrorsButton"
iconType="inspect"
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
{
// already has a connector and kb is not installing
// and has an install error (timeout, etc) or inference endpoint has not been created
neptunian marked this conversation as resolved.
Show resolved Hide resolved
connectors.connectors?.length && !isInstalling ? (
knowledgeBase.installError || !knowledgeBase.status.value.endpoint ? (
<>
<EuiText color="subdued" size="s">
{i18n.translate(
'xpack.aiAssistant.welcomeMessageKnowledgeBase.yourKnowledgeBaseIsNotSetUpCorrectlyLabel',
{ defaultMessage: `Your Knowledge base hasn't been set up.` }
)}
</EuiText>

<EuiSpacer size="m" />

<EuiFlexGroup justifyContent="center">
<EuiFlexItem grow={false}>
<div>
<EuiButton
color="primary"
data-test-subj="observabilityAiAssistantWelcomeMessageSetUpKnowledgeBaseButton"
fill
isLoading={false}
iconType="importAction"
onClick={handleInstall}
>
{i18n.translate(
'xpack.aiAssistant.welcomeMessage.inspectErrorsButtonEmptyLabel',
{ defaultMessage: 'Inspect issues' }
)}
</EuiButtonEmpty>
}
isOpen={isPopoverOpen}
panelPaddingSize="none"
closePopover={handleClosePopover}
>
<WelcomeMessageKnowledgeBaseSetupErrorPanel
knowledgeBase={knowledgeBase}
onRetryInstall={handleRetryInstall}
/>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer size="m" />
</>
{i18n.translate('xpack.aiAssistant.welcomeMessage.retryButtonLabel', {
defaultMessage: 'Install Knowledge base',
})}
</EuiButton>
</div>
</EuiFlexItem>

<EuiFlexItem grow={false}>
<EuiPopover
button={
<EuiButtonEmpty
data-test-subj="observabilityAiAssistantWelcomeMessageInspectErrorsButton"
iconType="inspect"
onClick={() => setIsPopoverOpen(!isPopoverOpen)}
>
{i18n.translate(
'xpack.aiAssistant.welcomeMessage.inspectErrorsButtonEmptyLabel',
{ defaultMessage: 'Inspect issues' }
)}
</EuiButtonEmpty>
}
isOpen={isPopoverOpen}
panelPaddingSize="none"
closePopover={handleClosePopover}
>
<WelcomeMessageKnowledgeBaseSetupErrorPanel
knowledgeBase={knowledgeBase}
onRetryInstall={handleInstall}
/>
</EuiPopover>
</EuiFlexItem>
</EuiFlexGroup>

<EuiSpacer size="m" />
</>
) : null
) : null
) : null}
}

{showHasBeenInstalled ? (
<div>
Expand Down