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

Add assistant capabilities to control rendering components #267

Merged
merged 14 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Add experimental feature to support text to visualization ([#218](https://github.com/opensearch-project/dashboards-assistant/pull/218))
- Be compatible with ML configuration index mapping change ([#239](https://github.com/opensearch-project/dashboards-assistant/pull/239))
- Support context aware alert analysis by reusing incontext insight component([#215](https://github.com/opensearch-project/dashboards-assistant/pull/215))
- Use smaller and compressed variants of buttons and form components ([#250](https://github.com/opensearch-project/dashboards-assistant/pull/250))
- Use smaller and compressed variants of buttons and form components ([#250](https://github.com/opensearch-project/dashboards-assistant/pull/250))
- Export assistant feature flags and add assistant isSubscriptionActive capabilities to control rendering component([#267](https://github.com/opensearch-project/dashboards-assistant/pull/267))
12 changes: 10 additions & 2 deletions common/types/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import { schema, TypeOf } from '@osd/config-schema';

export const configSchema = schema.object({
// TODO: add here to prevent this plugin from being loaded
// enabled: schema.boolean({ defaultValue: true }),
enabled: schema.boolean({ defaultValue: true }),
Copy link
Collaborator

Choose a reason for hiding this comment

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

enable this will allow whole dashboard assistant been disabled, is this expected?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I think it's upon agreement. Is it true? @ruanyl

Copy link
Member

Choose a reason for hiding this comment

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

I think so, this flag allows us to turnoff the entire plugin

chat: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
Expand All @@ -17,6 +16,15 @@ export const configSchema = schema.object({
next: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
text2viz: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
alertInsight: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
smartAnomalyDetector: schema.object({
enabled: schema.boolean({ defaultValue: false }),
}),
});

export type ConfigSchema = TypeOf<typeof configSchema>;
87 changes: 58 additions & 29 deletions public/plugin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,43 @@ export class AssistantPlugin
dataSourceManagement: setupDeps.dataSourceManagement,
});

if (this.config.next.enabled) {
setupDeps.visualizations.registerAlias({
name: 'text2viz',
aliasPath: '#/',
aliasApp: 'text2viz',
title: i18n.translate('dashboardAssistant.feature.text2viz.title', {
defaultMessage: 'Natural language',
}),
description: i18n.translate('dashboardAssistant.feature.text2viz.description', {
defaultMessage: 'Generate visualization with a natural language question.',
}),
icon: 'chatRight',
stage: 'experimental',
promotion: {
buttonText: i18n.translate('dashboardAssistant.feature.text2viz.promotion.buttonText', {
defaultMessage: 'Natural language previewer',
}),
description: i18n.translate('dashboardAssistant.feature.text2viz.promotion.description', {
defaultMessage:
'Not sure which visualization to choose? Generate visualization previews with a natural language question.',
}),
},
});
if (this.config.text2viz.enabled) {
const checkSubscriptionAndRegisterText2VizButton = async () => {
const [coreStart] = await core.getStartServices();
const isSubscriptionActive =
coreStart.application.capabilities?.assistant?.isSubscriptionActive === true;
if (isSubscriptionActive) {
setupDeps.visualizations.registerAlias({
name: 'text2viz',
aliasPath: '#/',
aliasApp: 'text2viz',
title: i18n.translate('dashboardAssistant.feature.text2viz.title', {
defaultMessage: 'Natural language',
}),
description: i18n.translate('dashboardAssistant.feature.text2viz.description', {
defaultMessage: 'Generate visualization with a natural language question.',
}),
icon: 'chatRight',
stage: 'experimental',
promotion: {
buttonText: i18n.translate(
'dashboardAssistant.feature.text2viz.promotion.buttonText',
{
defaultMessage: 'Natural language previewer',
}
),
description: i18n.translate(
'dashboardAssistant.feature.text2viz.promotion.description',
{
defaultMessage:
'Not sure which visualization to choose? Generate visualization previews with a natural language question.',
}
),
},
});
}
};
checkSubscriptionAndRegisterText2VizButton();

core.application.register({
id: TEXT2VIZ_APP_ID,
Expand All @@ -146,12 +160,18 @@ export class AssistantPlugin
navLinkStatus: AppNavLinkStatus.hidden,
mount: async (params: AppMountParameters) => {
const [coreStart, pluginsStart] = await core.getStartServices();
const { renderText2VizApp } = await import('./text2viz');
return renderText2VizApp(params, {
...coreStart,
...pluginsStart,
setHeaderActionMenu: params.setHeaderActionMenu,
});
const isSubscriptionActive =
coreStart.application.capabilities?.assistant?.isSubscriptionActive === true;
if (isSubscriptionActive) {
const { renderText2VizApp } = await import('./text2viz');
return renderText2VizApp(params, {
...coreStart,
...pluginsStart,
setHeaderActionMenu: params.setHeaderActionMenu,
});
} else {
return () => {};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to render some tips or instructions to direct user to active the subscription?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add a default "Application Not Activated" danger tips now

},
});
}
Expand Down Expand Up @@ -222,6 +242,15 @@ export class AssistantPlugin
},
chatEnabled: () => this.config.chat.enabled,
nextEnabled: () => this.config.next.enabled,
getFeatureStatus: () => {
return {
chat: this.config.chat.enabled,
next: this.config.next.enabled,
text2viz: this.config.text2viz.enabled,
alertInsight: this.config.alertInsight.enabled,
smartAnomalyDetector: this.config.smartAnomalyDetector.enabled,
};
},
assistantActions,
assistantTriggers: {
AI_ASSISTANT_QUERY_EDITOR_TRIGGER,
Expand Down
7 changes: 7 additions & 0 deletions public/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ export interface AssistantSetup {
* Returns true if contextual assistant is enabled.
*/
nextEnabled: () => boolean;
getFeatureStatus: () => {
chat: boolean;
next: boolean;
text2viz: boolean;
alertInsight: boolean;
smartAnomalyDetector: boolean;
};
assistantActions: Omit<AssistantActions, 'executeAction'>;
assistantTriggers: { AI_ASSISTANT_QUERY_EDITOR_TRIGGER: string };
registerIncontextInsight: IncontextInsightRegistry['register'];
Expand Down
24 changes: 24 additions & 0 deletions server/capabilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright OpenSearch Contributors
* SPDX-License-Identifier: Apache-2.0
*/

import { CapabilitiesSwitcher } from '../../../src/core/server';

export const capabilitiesProvider = () => ({
observability: {
show: true,
},
assistant: {
isSubscriptionActive: true,
},
});

// Users can customize the logic of flipping assistant feature UI capabilities here
export const capabilitiesSwitcher: CapabilitiesSwitcher = (request, capabilities) => {
return {
assistant: {
isSubscriptionActive: true,
},
};
};
3 changes: 3 additions & 0 deletions server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ export const config: PluginConfigDescriptor<ConfigSchema> = {
chat: true,
incontextInsight: true,
next: true,
text2viz: true,
alertInsight: true,
smartAnomalyDetector: true,
},
schema: configSchema,
};
Expand Down
10 changes: 4 additions & 6 deletions server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { registerChatRoutes } from './routes/chat_routes';
import { registerText2VizRoutes } from './routes/text2viz_routes';
import { AssistantService } from './services/assistant_service';
import { registerAgentRoutes } from './routes/agent_routes';
import { capabilitiesProvider, capabilitiesSwitcher } from './capabilities';

export class AssistantPlugin implements Plugin<AssistantPluginSetup, AssistantPluginStart> {
private readonly logger: Logger;
Expand Down Expand Up @@ -56,15 +57,12 @@ export class AssistantPlugin implements Plugin<AssistantPluginSetup, AssistantPl
});

// Register router for text to visualization
if (config.next.enabled) {
if (config.text2viz.enabled) {
registerText2VizRoutes(router, assistantServiceSetup);
}

core.capabilities.registerProvider(() => ({
observability: {
show: true,
},
}));
core.capabilities.registerProvider(capabilitiesProvider);
core.capabilities.registerSwitcher(capabilitiesSwitcher);
Copy link
Member

Choose a reason for hiding this comment

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

Do we need this switcher in dashboards-assistant? The default value is true already, maybe just let whoever need to update the value to register the switcher?

Copy link
Contributor Author

@songkant-aws songkant-aws Sep 11, 2024

Choose a reason for hiding this comment

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

Sure, that also makes sense. Developers can register their own switch per requirement. Removed the switcher registration now.


const registerMessageParser = (messageParser: MessageParser) => {
const findItem = this.messageParsers.find((item) => item.id === messageParser.id);
Expand Down
Loading