-
Notifications
You must be signed in to change notification settings - Fork 22
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
Changes from 7 commits
02773ae
5304c8b
a71e358
e452288
fcfedf1
4837c64
283af28
20a279e
aa30e87
3217c75
5fe214d
bbfa6a3
ea41d06
adb23a7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 () => {}; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a default "Application Not Activated" danger tips now |
||
}, | ||
}); | ||
} | ||
|
@@ -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, | ||
|
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, | ||
}, | ||
}; | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this switcher in dashboards-assistant? The default value is There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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