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

[AUTO] Increment version to 2.17.0.0 #289

Closed
wants to merge 8 commits into from
Closed
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
4 changes: 4 additions & 0 deletions common/constants/llm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export const TEXT2VIZ_API = {
TEXT2VEGA: `${API_BASE}/text2vega`,
};

export const AGENT_API = {
EXECUTE: `${API_BASE}/agent/_execute`,
};

export const NOTEBOOK_API = {
CREATE_NOTEBOOK: `${NOTEBOOK_PREFIX}/note`,
SET_PARAGRAPH: `${NOTEBOOK_PREFIX}/set_paragraphs/`,
Expand Down
3 changes: 3 additions & 0 deletions common/types/chat_saved_object_attributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,11 @@ export interface IInput {
content: string;
context?: {
appId?: string;
content?: string;
datasourceId?: string;
};
messageId?: string;
promptPrefix?: string;
}
export interface IOutput {
type: 'output';
Expand Down
3 changes: 2 additions & 1 deletion opensearch_dashboards.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"opensearchDashboardsReact",
"opensearchDashboardsUtils",
"visualizations",
"savedObjects"
"savedObjects",
"uiActions"
],
"optionalPlugins": [
"dataSource",
Expand Down
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,9 @@
"eslintIgnore": [
"node_modules/*",
"target/*"
]
],
"resolutions": {
"braces": "^3.0.3",
"micromatch": "^4.0.8"
}
}
15 changes: 15 additions & 0 deletions public/assets/assistant_trigger.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 27 additions & 4 deletions public/chat_header_button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,23 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
}, []);

useEffect(() => {
const handleSuggestion = (event: { suggestion: string }) => {
const handleSuggestion = (event: {
suggestion: string;
contextContent: string;
datasourceId?: string;
}) => {
if (!flyoutVisible) {
// open chat window
setFlyoutVisible(true);
// start a new chat
props.assistantActions.loadChat();
}
// start a new chat
props.assistantActions.loadChat();
// send message
props.assistantActions.send({
type: 'input',
contentType: 'text',
content: event.suggestion,
context: { appId },
context: { appId, content: event.contextContent, datasourceId: event.datasourceId },
});
};
registry.on('onSuggestion', handleSuggestion);
Expand All @@ -191,6 +195,25 @@ export const HeaderChatButton = (props: HeaderChatButtonProps) => {
};
}, [appId, flyoutVisible, props.assistantActions, registry]);

useEffect(() => {
const handleChatContinuation = (event: {
conversationId?: string;
contextContent: string;
datasourceId?: string;
}) => {
if (!flyoutVisible) {
// open chat window
setFlyoutVisible(true);
}
// continue chat with current conversationId
props.assistantActions.loadChat(event.conversationId);
};
registry.on('onChatContinuation', handleChatContinuation);
return () => {
registry.off('onChatContinuation', handleChatContinuation);
};
}, [appId, flyoutVisible, props.assistantActions, registry]);

return (
<>
<div className={classNames('llm-chat-header-icon-wrapper')}>
Expand Down
199 changes: 199 additions & 0 deletions public/components/incontext_insight/generate_popover_body.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,199 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import React from 'react';
import { render, cleanup, fireEvent, waitFor } from '@testing-library/react';
import { getConfigSchema, getNotifications } from '../../services';
import { GeneratePopoverBody } from './generate_popover_body';
import { HttpSetup } from '../../../../../src/core/public';
import { ASSISTANT_API } from '../../../common/constants/llm';

jest.mock('../../services');

const mockToasts = {
addDanger: jest.fn(),
};

beforeEach(() => {
(getNotifications as jest.Mock).mockImplementation(() => ({
toasts: mockToasts,
}));
(getConfigSchema as jest.Mock).mockReturnValue({
chat: { enabled: true },
});
});

afterEach(cleanup);

const mockPost = jest.fn();
const mockHttpSetup: HttpSetup = ({
post: mockPost,
} as unknown) as HttpSetup; // Mocking HttpSetup

describe('GeneratePopoverBody', () => {
const incontextInsightMock = {
contextProvider: jest.fn(),
suggestions: ['Test summarization question'],
datasourceId: 'test-datasource',
key: 'test-key',
};

const closePopoverMock = jest.fn();

it('renders the generate summary button', () => {
const { getByText } = render(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
/>
);

expect(getByText('Generate summary')).toBeInTheDocument();
});

it('calls onGenerateSummary when button is clicked', async () => {
mockPost.mockResolvedValue({
interactions: [{ conversation_id: 'test-conversation' }],
messages: [{ type: 'output', content: 'Generated summary content' }],
});

const { getByText } = render(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
/>
);

const button = getByText('Generate summary');
fireEvent.click(button);

// Wait for loading to complete and summary to render
await waitFor(() => {
expect(getByText('Generated summary content')).toBeInTheDocument();
});

expect(mockPost).toHaveBeenCalledWith(ASSISTANT_API.SEND_MESSAGE, expect.any(Object));
expect(mockToasts.addDanger).not.toHaveBeenCalled();
});

it('shows loading state while generating summary', async () => {
const { getByText } = render(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
/>
);

const button = getByText('Generate summary');
fireEvent.click(button);

// Wait for loading state to appear
expect(getByText('Generating summary...')).toBeInTheDocument();
});

it('handles error during summary generation', async () => {
mockPost.mockRejectedValue(new Error('Network Error'));

const { getByText } = render(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
/>
);

const button = getByText('Generate summary');
fireEvent.click(button);

await waitFor(() => {
expect(mockToasts.addDanger).toHaveBeenCalledWith('Generate summary error');
});
});

it('renders the continue in chat button after summary is generated', async () => {
mockPost.mockResolvedValue({
interactions: [{ conversation_id: 'test-conversation' }],
messages: [{ type: 'output', content: 'Generated summary content' }],
});

const { getByText } = render(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
/>
);

const button = getByText('Generate summary');
fireEvent.click(button);

// Wait for the summary to be displayed
await waitFor(() => {
expect(getByText('Generated summary content')).toBeInTheDocument();
});

// Check for continue in chat button
expect(getByText('Continue in chat')).toBeInTheDocument();
});

it('calls onChatContinuation when continue in chat button is clicked', async () => {
mockPost.mockResolvedValue({
interactions: [{ conversation_id: 'test-conversation' }],
messages: [{ type: 'output', content: 'Generated summary content' }],
});

const { getByText } = render(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
/>
);

const button = getByText('Generate summary');
fireEvent.click(button);

await waitFor(() => {
expect(getByText('Generated summary content')).toBeInTheDocument();
});

const continueButton = getByText('Continue in chat');
fireEvent.click(continueButton);

expect(mockPost).toHaveBeenCalledTimes(1);
expect(closePopoverMock).toHaveBeenCalled();
});

it("continue in chat button doesn't appear when chat is disabled", async () => {
mockPost.mockResolvedValue({
interactions: [{ conversation_id: 'test-conversation' }],
messages: [{ type: 'output', content: 'Generated summary content' }],
});
(getConfigSchema as jest.Mock).mockReturnValue({
chat: { enabled: false },
});

const { getByText, queryByText } = render(
<GeneratePopoverBody
incontextInsight={incontextInsightMock}
httpSetup={mockHttpSetup}
closePopover={closePopoverMock}
/>
);

const button = getByText('Generate summary');
fireEvent.click(button);

await waitFor(() => {
expect(getByText('Generated summary content')).toBeInTheDocument();
});

expect(queryByText('Continue in chat')).toBeNull();
expect(mockPost).toHaveBeenCalledTimes(1);
});
});
Loading
Loading