AI Assistant custom element
Embed the AI Assistant with gd-ai-assistant, set its workspace and locale, subscribe to its chat events, and compose the chat from several elements.
gd-ai-assistant embeds the GoodData AI Assistant. It renders the GenAIAssistant component:
<!-- minimal setup -->
<gd-ai-assistant></gd-ai-assistant>
Supported attributes
<!-- all supported attributes -->
<gd-ai-assistant
workspace="my-workspace-id"
locale="en-US"
objectTypes='["dashboard","visualization"]'
dashboard-source="my-dashboard-dom-id"
></gd-ai-assistant>
workspace- optional, the ID of the workspace for this AI Assistant. By default, it’s taken from the context, for example from the script URL.locale- optional, defaults toen-US. The localization of the AI Assistant interface. For all available languages, see the full list of available localizations.objectTypes- optional, a JSON array of metadata object types that the assistant searches and suggests, for example'["dashboard","visualization"]'. Valid values aredataset,attribute,label,fact,date,metric,visualization, anddashboard(seeGenAIObjectType). If omitted, the assistant uses its default set of object types.dashboard-source- optional, the DOMidof agd-dashboard-embedelement. The assistant uses the dashboard in that element as its context. See Dashboard context.
You can also set the workspace ID once on the context instead of passing it to every element. See the code example in Web Components authentication.
Supported events
gd-ai-assistant emits linkClick and forwards every chat event of the GenAIAssistant component (see ChatEvent) as a DOM event named after the event type. The most common ones are:
linkClick- when a user clicks on a link in the chat.chatOpened/chatClosed- when the chat is opened or closed.chatReset- when the chat is reset.chatUserMessage- when a user message is added to the chat.chatAssistantMessage- when an assistant message is added to the chat.chatFeedback- when a user provides feedback on the assistant message.chatVisualizationError- when an error occurs while rendering the visualization in the chat.chatSaveVisualizationSuccess/chatSaveVisualizationError- when saving a visualization from the chat succeeds or fails.chatCopyToClipboard- when a user copies content to the clipboard.
Events do not bubble and are not cancelable. Here is how you can subscribe to one from your code:
<gd-ai-assistant id="some-dom-id"></gd-ai-assistant>
<script>
const chatEl = document.getElementById("some-dom-id");
chatEl.addEventListener("linkClick", (event) => {
// See what's in the event payload
console.log(event.detail);
});
</script>
Dashboard context
To let the assistant know which dashboard the user is looking at, give the gd-dashboard-embed element an id and name it in the dashboard-source attribute of gd-ai-assistant or gd-ai-chat:
<gd-dashboard-embed id="active-dashboard" dashboard="my-dashboard-id"></gd-dashboard-embed>
<gd-ai-assistant dashboard-source="active-dashboard"></gd-ai-assistant>
The assistant then derives its ambient context from the dashboard: the dashboard and its title, the filters and their current values, the widgets, the active tab, and the results of the executed visualizations. It follows the dashboard as the user changes it. The two elements don’t have to share a parent, and you don’t wire any events or properties between them.
| Situation | Dashboard context |
|---|---|
No dashboard-source attribute | Not managed by the element. |
No connected gd-dashboard-embed has the id, or its dashboard isn’t loaded yet | Cleared. |
| The dashboard is loaded | Set, and updated when something the assistant reads changes. |
| The dashboard element is removed | Cleared. |
A new gd-dashboard-embed with the same id connects, for example after a drill to another dashboard | Set from the new dashboard. If two connected elements have the same id, the most recently connected one is used. |
| You change or remove the attribute | The assistant links to the newly named dashboard, or stops managing the context. |
Keep in mind:
- The assistant uses the dashboard context only when context setup is enabled for your organization (the
enableAiContextSetupsetting). Without it, the attribute has no visible effect. - The assistant sees everything the dashboard loaded. If your application hides parts of the dashboard on its own, the assistant can still refer to them.
- Only
gd-dashboard-embedcan be a source, not the legacygd-dashboard. Dashboards whose engine is loaded from the backend together with dashboard plugins aren’t supported as a source. - Don’t link two assistants that share one
gd-ai-providerto different dashboards. They share one context, so the dashboard that changed last wins. gd-ai-conversationsandgd-ai-providerignore the attribute.
Compose the chat from several elements
The library registers three more elements that share the AI Assistant’s code:
| Element | Renders | Use it to |
|---|---|---|
gd-ai-chat | The same GenAIAssistant component as gd-ai-assistant | Alias of gd-ai-assistant; the two tags behave identically. |
gd-ai-conversations | The GenAIConversations component: the list of the user’s conversations | Show the conversation list separately from the chat. Selecting a conversation makes it the current one in the shared store. |
gd-ai-provider | Nothing visible; it owns the chat store | Make the gd-ai-assistant, gd-ai-chat, and gd-ai-conversations elements placed inside it share one conversation state. |
gd-ai-chat and gd-ai-conversations support the same workspace, locale, and objectTypes attributes as gd-ai-assistant and emit the same events. gd-ai-chat also supports dashboard-source.
Share one store with gd-ai-provider
Wrap the chat and the conversation list in gd-ai-provider. When the provider connects and the shared context is available, it creates the chat store, and every gd-ai-assistant, gd-ai-chat, or gd-ai-conversations element inside it connects to that store instead of creating its own:
<gd-ai-provider workspace="my-workspace-id">
<aside><gd-ai-conversations></gd-ai-conversations></aside>
<main><gd-ai-assistant></gd-ai-assistant></main>
</gd-ai-provider>
| Attribute | Description |
|---|---|
workspace, locale, objectTypes | Applied to the shared store. Same values as on gd-ai-assistant. |
store | Optional ID of the store. The provider generates one when the attribute is absent. Child elements look up the nearest ancestor with a store attribute, so the provider doesn’t have to be their direct parent. |
The provider reads its attributes once, when it connects; changing them later has no effect. Set isLinkEnabled during initialization, before connecting the element. Listen for chat events on the gd-ai-assistant and gd-ai-conversations elements, not the provider.
JavaScript properties and methods
gd-ai-assistant, gd-ai-chat, gd-ai-conversations, and gd-ai-provider expose these JavaScript properties. Assign them after the element is defined, for example after await customElements.whenDefined("gd-ai-provider").
| Property or method | Description |
|---|---|
isLinkEnabled | Optional (type: GenAIObjectType) => boolean predicate controlling which object references are interactive. On the provider, it applies to the shared store and its child elements. See Object-link policy. |
onLinkClick | Callback invoked when the user clicks a link in the chat, with a CustomEvent whose detail is the linkClick payload described below. The element always suppresses the chat’s own navigation and dispatches the linkClick event before it calls the callback. |
onDispatcher | Callback that receives the store’s dispatch function once the store exists. Use it to dispatch the actions exported by @gooddata/sdk-ui-gen-ai. |
startNewConversationAction() | Dispatches the start-new-conversation action to the store. The method is attached asynchronously after the element connects, so guard early calls with ?.. |
On gd-ai-provider, assigning onLinkClick or onDispatcher forwards the callback to the shared store, and startNewConversationAction() acts on the shared store.
<gd-ai-provider id="provider" workspace="my-workspace-id">
<gd-ai-conversations></gd-ai-conversations>
<gd-ai-assistant></gd-ai-assistant>
</gd-ai-provider>
<button id="new-conversation">New conversation</button>
<script type="module">
await customElements.whenDefined("gd-ai-provider");
const providerEl = document.getElementById("provider");
providerEl.onLinkClick = (event) => {
console.log("link clicked", event.detail.itemUrl);
};
document.getElementById("new-conversation").addEventListener("click", () => {
providerEl.startNewConversationAction?.();
});
</script>
The linkClick event detail carries type (the linked object type, "setting", or "report"), id, workspaceId, itemUrl, newTab, and action ("open" or "copy"), and, depending on the link, section, dashboard, insights, dashboardStatus, visualization, and visualizationStatus.
Object-link policy
Assign isLinkEnabled as a JavaScript property on gd-ai-assistant, gd-ai-chat, gd-ai-conversations, or gd-ai-provider during initialization, before connecting the element to the DOM. It is not an HTML attribute, and changing the policy during the element’s lifetime is not supported. The predicate receives a GenAIObjectType; built-in answer references and search results use metric, visualization, dashboard, and document.
For example, allow only dashboard links throughout a shared chat:
<script type="module">
await customElements.whenDefined("gd-ai-provider");
const providerEl = document.createElement("gd-ai-provider");
providerEl.setAttribute("workspace", "my-workspace-id");
providerEl.isLinkEnabled = (type) => type === "dashboard";
providerEl.innerHTML = `
<gd-ai-conversations></gd-ai-conversations>
<gd-ai-assistant></gd-ai-assistant>
`;
document.body.append(providerEl);
</script>
Returning false renders answer references as plain text and makes search-result rows non-clickable with no Open/Edit actions. Disabled references do not navigate or invoke onLinkClick / linkClick through mouse or keyboard activation. Results remain visible, and expansion, hover details, and keyboard navigation remain available. Related destinations are evaluated independently.
A child element inherits the nearest provider’s policy unless it supplies its own predicate, which replaces the inherited policy. With no policy, or a predicate returning true, links behave as before.
The policy does not filter search results (objectTypes does), grant permissions, or replace onLinkClick handling for enabled links. It applies only to built-in answer references and search results, not settings links, visualization action menus, or custom renderers. Legacy report references are evaluated as document; linkClick payloads retain type: "report". See the React Object-link policy for the full behavior.
Related
Components, events, slots, actions, and dashboard copilot integration of the AI Assistant chat in @gooddata/sdk-ui-gen-ai.
Understand what the Web Components library is, when to choose it over an iframe or the React library, how it loads, and what limits it has.
Embed a dashboard or a saved visualization with gd-dashboard-embed and gd-insight-embed, and drive them through properties, methods, and events.
Authenticate Web Components against GoodData using the auth=sso script parameter for automatic SSO or setContext for a programmatic flow.
Embed GoodData dashboards, visualizations, and the AI Assistant in a Vue app with the Web Components library, the Vite custom-element setting, and event listeners.