Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ describe('AIAssistantHeaderButton', () => {

beforeEach(() => {
jest.clearAllMocks();
getIsAiAgentsEnabled.mockResolvedValue(true);
getIsAiAgentsEnabled.mockReturnValue(true);
mockCoreStart.settings.client.set.mockResolvedValue(true);
mockCoreStart.application.capabilities = {
...mockCoreStart.application.capabilities,
agentBuilder: { show: true },
agentBuilder: { show: true, manageAgents: true },
};
});

Expand Down Expand Up @@ -144,7 +144,11 @@ describe('AIAssistantHeaderButton', () => {
});

describe('AI Agent Card - Disabled State', () => {
it('should be enabled when at least Security assistant is enabled', async () => {
it('should be disabled when manageAgents is false', async () => {
mockCoreStart.application.capabilities = {
...mockCoreStart.application.capabilities,
agentBuilder: { show: true, manageAgents: false },
};
renderComponent({
isSecurityAIAssistantEnabled: true,
isObservabilityAIAssistantEnabled: false,
Expand All @@ -157,10 +161,14 @@ describe('AIAssistantHeaderButton', () => {
});

const agentCard = screen.getByTestId('aiAssistantAgentCard');
expect(agentCard.querySelector('[disabled]')).toBeFalsy();
expect(agentCard.querySelector('[disabled]')).toBeTruthy();
});

it('should be enabled when at least Observability assistant is enabled', async () => {
it('should be disabled when security AI assistant is disabled', async () => {
mockCoreStart.application.capabilities = {
...mockCoreStart.application.capabilities,
agentBuilder: { show: true, manageAgents: false },
};
renderComponent({
isSecurityAIAssistantEnabled: false,
isObservabilityAIAssistantEnabled: true,
Expand All @@ -172,6 +180,23 @@ describe('AIAssistantHeaderButton', () => {
expect(screen.getByTestId('aiAssistantAgentCard')).toBeInTheDocument();
});

const agentCard = screen.getByTestId('aiAssistantAgentCard');
expect(agentCard.querySelector('[disabled]')).toBeTruthy();
});

it('should be enabled when manageAgents is true', async () => {
mockCoreStart.application.capabilities = {
...mockCoreStart.application.capabilities,
agentBuilder: { show: true, manageAgents: true },
};
renderComponent();

fireEvent.click(screen.getByTestId('aiAssistantHeaderButton'));

await waitFor(() => {
expect(screen.getByTestId('aiAssistantAgentCard')).toBeInTheDocument();
});

const agentCard = screen.getByTestId('aiAssistantAgentCard');
expect(agentCard.querySelector('[disabled]')).toBeFalsy();
});
Expand All @@ -195,9 +220,12 @@ describe('AIAssistantHeaderButton', () => {
fireEvent.click(screen.getByTestId('aiAssistantAgentCard'));
fireEvent.click(screen.getByTestId('aiAssistantApplyButton'));

await waitFor(() => {
expect(screen.getByText('Switch to AI Agent')).toBeInTheDocument();
});
await waitFor(
() => {
expect(screen.getByText(/Switch to AI Agent/i)).toBeInTheDocument();
},
{ timeout: 5000 }
);
});

it('should not open confirmation modal for Classic AI Assistant selections', () => {
Expand All @@ -215,9 +243,12 @@ describe('AIAssistantHeaderButton', () => {
fireEvent.click(screen.getByTestId('aiAssistantAgentCard'));
fireEvent.click(screen.getByTestId('aiAssistantApplyButton'));

await waitFor(() => {
expect(screen.getByText('Switch to AI Agent')).toBeInTheDocument();
});
await waitFor(
() => {
expect(screen.getByText(/Switch to AI Agent/i)).toBeInTheDocument();
},
{ timeout: 5000 }
);

// Find and click Confirm button in confirmation modal
const confirmButtons = screen.getAllByText('Confirm');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export const AIAssistantHeaderButton: React.FC<AIAssistantHeaderButtonProps> = (
const { getUrlForApp } = coreStart.application;
const { toasts } = coreStart.notifications;

const hasAgentBuilder = coreStart.application.capabilities.agentBuilder?.show === true;
const hasAgentBuilder = coreStart.application.capabilities.agentBuilder?.manageAgents === true;
const isAiAgentsEnabled = getIsAiAgentsEnabled(coreStart.featureFlags);

const [selectedType, setSelectedType] = useState<AIExperienceSelection>(AIAssistantType.Default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export const GenAiSettingsApp: React.FC<GenAiSettingsAppProps> = ({ setBreadcrum
</EuiSplitPanel.Inner>
</EuiSplitPanel.Outer>

{isAgentExperience && (
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for this fix @KodeRad! This fixes the corner case where the user enables the FF, then the Agent experience, then removes the feature flag, at which point the app would return to the default chat experience but this UI would still show.

{isAgentExperience && showChatExperienceSetting && (
<>
<EuiSpacer size="l" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,12 @@ export const EnabledFeaturesContextProvider: FC<PropsWithChildren<Props>> = ({
children,
config,
}) => {
const { services } = useKibana();
const spaces = services?.spaces ?? undefined;
const {
services: {
spaces,
application: { capabilities },
},
} = useKibana();

const activeSpace$ = React.useMemo(
() => spaces?.getActiveSpace$?.() ?? of<Space | undefined>(undefined),
Expand All @@ -52,14 +56,22 @@ export const EnabledFeaturesContextProvider: FC<PropsWithChildren<Props>> = ({
const showAiAssistantsVisibilitySetting =
config.showAiAssistantsVisibilitySetting === false ? false : !isSolutionView;

const hasObservabilityAssistant = capabilities.observabilityAIAssistant?.show === true;
const hasSecurityAssistant = capabilities.securitySolutionAssistant?.['ai-assistant'] === true;
const hasAgent = capabilities.agentBuilder?.manageAgents === true;
const hasAgentAndAnyAssistant = (hasObservabilityAssistant || hasSecurityAssistant) && hasAgent;

const showChatExperienceSetting =
config.showChatExperienceSetting === false ? false : hasAgentAndAnyAssistant;

return {
showSpacesIntegration: config.showSpacesIntegration,
showAiBreadcrumb: config.showAiBreadcrumb,
isPermissionsBased: isSolutionView,
showAiAssistantsVisibilitySetting,
showChatExperienceSetting: config.showChatExperienceSetting,
showChatExperienceSetting,
};
}, [config, activeSpace]);
}, [config, activeSpace, capabilities]);

return (
<EnabledFeaturesContext.Provider value={contextFeatures}>
Expand Down