Skip to content

Commit

Permalink
more
Browse files Browse the repository at this point in the history
  • Loading branch information
stephmilovic committed Sep 9, 2024
1 parent 5edede7 commit b5fba86
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,15 @@ export const useAssistantOverlay = (
async (showOverlay: boolean, shouldCreateConversation: boolean = false) => {
if (promptContextId != null) {
if (shouldCreateConversation) {
console.log('test 2', conversations);
let conversation;
if (!isLoading) {
console.log('test 4');
conversation = conversationTitle
? Object.values(conversations).find((conv) => conv.title === conversationTitle)
: undefined;
}
console.log('condtions:', {
full: isAssistantEnabled && !conversation && defaultConnector && !isLoading,
isAssistantEnabled,
conversationMissing: !conversation,
defaultConnector,
isLoading,
});

if (isAssistantEnabled && !conversation && defaultConnector && !isLoading) {
try {
console.log('test 3');
await createConversation({
apiConfig: {
...apiConfig,
Expand All @@ -168,13 +158,11 @@ export const useAssistantOverlay = (
}
}
}
console.log('test 1', assistantContextShowOverlay);
assistantContextShowOverlay({
showOverlay,
promptContextId,
conversationTitle: conversationTitle ?? undefined,
});
console.log('test 1b');
}
},
[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import { useViewInAiAssistant } from './use_view_in_ai_assistant';
jest.mock('@kbn/elastic-assistant');
jest.mock('../../../assistant/use_assistant_availability');
jest.mock('../../get_attack_discovery_markdown/get_attack_discovery_markdown');

const mockUseAssistantOverlay = useAssistantOverlay as jest.Mock;
describe('useViewInAiAssistant', () => {
beforeEach(() => {
jest.clearAllMocks();

(useAssistantOverlay as jest.Mock).mockReturnValue({
mockUseAssistantOverlay.mockReturnValue({
promptContextId: 'prompt-context-id',
showAssistantOverlay: jest.fn(),
});
Expand Down Expand Up @@ -83,4 +83,16 @@ describe('useViewInAiAssistant', () => {

expect(result.current.disabled).toBe(true);
});

it('uses the title + last 5 of the attack discovery id as the conversation title', () => {
renderHook(() =>
useViewInAiAssistant({
attackDiscovery: mockAttackDiscovery,
})
);

expect(mockUseAssistantOverlay.mock.calls[0][1]).toEqual(
'Malware Attack With Credential Theft Attempt - b72b1'
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,13 @@ export const useViewInAiAssistant = ({
}),
[attackDiscovery]
);

const lastFive = attackDiscovery.id
? ` - ${attackDiscovery.id.substr(attackDiscovery.id.length - 5)}`
: '';
const { promptContextId, showAssistantOverlay: showOverlay } = useAssistantOverlay(
category,
attackDiscovery.title, // conversation title
attackDiscovery.title + lastFive, // conversation title
attackDiscovery.title, // description used in context pill
getPromptContext,
attackDiscovery.id ?? null, // accept the UUID default for this prompt context
Expand Down

0 comments on commit b5fba86

Please sign in to comment.