@gooddata/sdk-ui-gen-ai 11.48.0-alpha.2 → 11.48.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/esm/components/GenAIChatContextIndicator.d.ts.map +1 -1
  2. package/esm/components/GenAIChatContextIndicator.js +11 -11
  3. package/esm/components/GenAIChatDialogConnected.d.ts +3 -1
  4. package/esm/components/GenAIChatDialogConnected.d.ts.map +1 -1
  5. package/esm/components/GenAIChatDialogConnected.js +25 -11
  6. package/esm/components/GenAiChatContextChooser.d.ts +1 -1
  7. package/esm/components/GenAiChatContextChooser.d.ts.map +1 -1
  8. package/esm/components/GenAiChatContextChooser.js +8 -8
  9. package/esm/components/hooks/useContextItems.d.ts +2 -2
  10. package/esm/components/hooks/useContextItems.d.ts.map +1 -1
  11. package/esm/components/hooks/useContextItems.js +5 -5
  12. package/esm/components/utils/icons.d.ts +2 -2
  13. package/esm/components/utils/icons.d.ts.map +1 -1
  14. package/esm/components/utils/icons.js +1 -0
  15. package/esm/context/addContextReference.d.ts +3 -2
  16. package/esm/context/addContextReference.d.ts.map +1 -1
  17. package/esm/context/addContextReference.js +62 -7
  18. package/esm/context/build.d.ts +2 -2
  19. package/esm/context/build.d.ts.map +1 -1
  20. package/esm/context/build.js +35 -4
  21. package/esm/context/collectContextReferences.d.ts +4 -10
  22. package/esm/context/collectContextReferences.d.ts.map +1 -1
  23. package/esm/context/collectContextReferences.js +96 -8
  24. package/esm/context/dashboard.d.ts.map +1 -1
  25. package/esm/context/dashboard.js +10 -4
  26. package/esm/context/removeContextReference.d.ts +2 -1
  27. package/esm/context/removeContextReference.d.ts.map +1 -1
  28. package/esm/context/removeContextReference.js +31 -2
  29. package/esm/store/chatWindow/chatWindowSelectors.d.ts +1 -8
  30. package/esm/store/chatWindow/chatWindowSelectors.d.ts.map +1 -1
  31. package/esm/store/chatWindow/chatWindowSelectors.js +1 -13
  32. package/esm/store/chatWindow/chatWindowSlice.d.ts +5 -3
  33. package/esm/store/chatWindow/chatWindowSlice.d.ts.map +1 -1
  34. package/esm/store/chatWindow/chatWindowSlice.js +15 -17
  35. package/esm/store/sideEffects/onUserMessage.d.ts.map +1 -1
  36. package/esm/store/sideEffects/onUserMessage.js +3 -12
  37. package/esm/types.d.ts +15 -10
  38. package/esm/types.d.ts.map +1 -1
  39. package/esm/utils.d.ts +4 -1
  40. package/esm/utils.d.ts.map +1 -1
  41. package/esm/utils.js +28 -0
  42. package/package.json +20 -20
  43. package/styles/css/main.css +31 -9
  44. package/styles/css/main.css.map +1 -1
  45. package/styles/scss/main.scss +1 -0
@@ -1 +1 @@
1
- {"version":3,"file":"GenAIChatContextIndicator.d.ts","sourceRoot":"","sources":["../../src/components/GenAIChatContextIndicator.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAe,MAAM,OAAO,CAAC;AAY7C,KAAK,iCAAiC,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAoDF,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,iCAAiC,CAG5C,CAAC"}
1
+ {"version":3,"file":"GenAIChatContextIndicator.d.ts","sourceRoot":"","sources":["../../src/components/GenAIChatContextIndicator.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAe,MAAM,OAAO,CAAC;AAa7C,KAAK,iCAAiC,GAAG;IACrC,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACzB,CAAC;AAuDF,eAAO,MAAM,yBAAyB,EAAE,EAAE,CAAC,iCAAiC,CAG5C,CAAC"}
@@ -4,8 +4,8 @@ import { useCallback } from "react";
4
4
  import { connect, useSelector } from "react-redux";
5
5
  import { UiChip } from "@gooddata/sdk-ui-kit";
6
6
  import { collectContextReferences } from "../context/collectContextReferences.js";
7
- import { effectiveContextSelector } from "../store/chatWindow/chatWindowSelectors.js";
8
- import { removeAmbientUserContextAction } from "../store/chatWindow/chatWindowSlice.js";
7
+ import { userContextSelector } from "../store/chatWindow/chatWindowSelectors.js";
8
+ import { removeContextReferenceAction } from "../store/chatWindow/chatWindowSlice.js";
9
9
  import { getIconByType } from "./utils/icons.js";
10
10
  /**
11
11
  * Shows what ambient context the assistant is answering about — the open dashboard and its live
@@ -15,21 +15,21 @@ import { getIconByType } from "./utils/icons.js";
15
15
  *
16
16
  * @internal
17
17
  */
18
- function GenAIChatContextIndicatorCore({ removeAmbientUserContext, onDelete, }) {
19
- const { ambient } = useSelector(effectiveContextSelector);
20
- const ambientReferences = collectContextReferences(ambient, "ambient");
21
- const onAmbientDelete = useCallback(() => {
18
+ function GenAIChatContextIndicatorCore({ removeContextReference, onDelete, }) {
19
+ const context = useSelector(userContextSelector);
20
+ const references = collectContextReferences(context);
21
+ const onDeleteHandler = useCallback((reference) => {
22
22
  return () => {
23
- removeAmbientUserContext();
23
+ removeContextReference({ object: reference });
24
24
  onDelete?.();
25
25
  };
26
- }, [removeAmbientUserContext, onDelete]);
27
- if (ambientReferences.length === 0) {
26
+ }, [removeContextReference, onDelete]);
27
+ if (references.length === 0) {
28
28
  return null;
29
29
  }
30
- return (_jsx("div", { className: "gd-gen-ai-chat__context-indicator", "aria-live": "polite", children: ambientReferences.map((reference, index) => (_jsx(UiChip, { ...getIconByType(reference.type), label: reference.title, isExpandable: false, isDeletable: true, onDelete: onAmbientDelete() }, index))) }));
30
+ return (_jsx("div", { className: "gd-gen-ai-chat__context-indicator", "aria-live": "polite", children: references.map((reference, index) => (_jsx(UiChip, { ...getIconByType(reference.type), label: reference.title, isExpandable: false, isDeletable: true, onDelete: onDeleteHandler(reference) }, index))) }));
31
31
  }
32
32
  const mapDispatchToProps = {
33
- removeAmbientUserContext: removeAmbientUserContextAction,
33
+ removeContextReference: removeContextReferenceAction,
34
34
  };
35
35
  export const GenAIChatContextIndicator = connect(null, mapDispatchToProps)(GenAIChatContextIndicatorCore);
@@ -81,6 +81,8 @@ export interface IGenAIChatDialogConnectedProps {
81
81
  ambientUserContext?: IGenAIUserContext;
82
82
  /** When true, the seeded question is appended to the existing thread instead of clearing it first. */
83
83
  appendToChat?: boolean;
84
+ /** When true, the user context is replaced instead of merged with the existing one. */
85
+ replaceUserContext?: boolean;
84
86
  /** Object-search tag scope reflecting the caller's current view. */
85
87
  includeTags?: string[];
86
88
  excludeTags?: string[];
@@ -111,5 +113,5 @@ export interface IGenAIChatDialogConnectedProps {
111
113
  *
112
114
  * @internal
113
115
  */
114
- export declare function GenAIChatDialogConnected({ backend, workspace, locale, canManage, canAnalyze, canFullControl, settings, isOpen, onOpen, onClose, askedQuestion, askSeq, userContext, ambientUserContext, appendToChat, includeTags, excludeTags, objectTypes: objectTypesOverride, onEvent, onAnyEvent, dialogPosition, className, colorPalette, allowNativeLinks, onLinkClick, returnFocusTo }: IGenAIChatDialogConnectedProps): import("react/jsx-runtime").JSX.Element;
116
+ export declare function GenAIChatDialogConnected({ backend, workspace, locale, canManage, canAnalyze, canFullControl, settings, isOpen, onOpen, onClose, askedQuestion, askSeq, userContext, ambientUserContext, appendToChat, replaceUserContext, includeTags, excludeTags, objectTypes: objectTypesOverride, onEvent, onAnyEvent, dialogPosition, className, colorPalette, allowNativeLinks, onLinkClick, returnFocusTo }: IGenAIChatDialogConnectedProps): import("react/jsx-runtime").JSX.Element;
115
117
  //# sourceMappingURL=GenAIChatDialogConnected.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenAIChatDialogConnected.d.ts","sourceRoot":"","sources":["../../src/components/GenAIChatDialogConnected.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAI7F,OAAO,EACH,KAAK,yBAAyB,EAC9B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W,GAAG,IAAI,CAAC,GAAG,MAAM,CAAC;CAC1D;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,wBAAwB,CAAC,EACrC,OAAO,EACP,SAAS,EACT,MAAM,EACN,SAAS,EACT,UAAU,EACV,cAAc,EACd,QAAQ,EACR,MAAM,EACN,MAAM,EACN,OAAO,EACP,aAAa,EACb,MAAM,EACN,WAAW,EACX,kBAAkB,EAClB,YAAY,EACZ,WAAW,EACX,WAAW,EACX,WAAW,EAAE,mBAAmB,EAChC,OAAO,EACP,UAAU,EACV,cAAc,EACd,SAAS,EACT,YAAY,EACZ,gBAAuB,EACvB,WAAW,EACX,aAAa,EAChB,EAAE,8BAA8B,2CAoIhC"}
1
+ {"version":3,"file":"GenAIChatDialogConnected.d.ts","sourceRoot":"","sources":["../../src/components/GenAIChatDialogConnected.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,SAAS,EAAqD,MAAM,OAAO,CAAC;AAE1F,OAAO,EAAE,KAAK,kBAAkB,EAAE,KAAK,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAI7F,OAAO,EACH,KAAK,yBAAyB,EAC9B,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,SAAS,EACd,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,EACtB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,+BAA+B,EACpC,KAAK,iCAAiC,EACtC,KAAK,oBAAoB,EAW5B,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAG3D;;;;;;;;;GASG;AACH,MAAM,MAAM,uBAAuB,GAC7B;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,eAAe,CAAA;CAAE,GAC5C;IAAE,IAAI,EAAE,QAAQ,CAAC;IA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gBAAuB,EACvB,WAAW,EACX,aAAa,EAChB,EAAE,8BAA8B,2CAmJhC"}
@@ -17,7 +17,7 @@ import { GenAIChatDialog } from "./GenAIChatDialog.js";
17
17
  *
18
18
  * @internal
19
19
  */
20
- export function GenAIChatDialogConnected({ backend, workspace, locale, canManage, canAnalyze, canFullControl, settings, isOpen, onOpen, onClose, askedQuestion, askSeq, userContext, ambientUserContext, appendToChat, includeTags, excludeTags, objectTypes: objectTypesOverride, onEvent, onAnyEvent, dialogPosition, className, colorPalette, allowNativeLinks = true, onLinkClick, returnFocusTo, }) {
20
+ export function GenAIChatDialogConnected({ backend, workspace, locale, canManage, canAnalyze, canFullControl, settings, isOpen, onOpen, onClose, askedQuestion, askSeq, userContext, ambientUserContext, appendToChat, replaceUserContext, includeTags, excludeTags, objectTypes: objectTypesOverride, onEvent, onAnyEvent, dialogPosition, className, colorPalette, allowNativeLinks = true, onLinkClick, returnFocusTo, }) {
21
21
  const defaultLinkClick = useCallback(({ itemUrl, newTab, preventDefault }) => {
22
22
  if (itemUrl) {
23
23
  preventDefault();
@@ -100,26 +100,40 @@ export function GenAIChatDialogConnected({ backend, workspace, locale, canManage
100
100
  const lastSeedTokenRef = useRef(null);
101
101
  useEffect(() => {
102
102
  // Only seed while the chat is open, and only once per ask (LX-2544).
103
- if (!isOpen || !chatDispatcher || !askedQuestion || !settings) {
103
+ if (!isOpen || !chatDispatcher || !settings) {
104
104
  return;
105
105
  }
106
- const seedToken = askSeq ?? askedQuestion;
106
+ const seedToken = askSeq ?? askedQuestion ?? JSON.stringify(userContext ?? {});
107
107
  if (lastSeedTokenRef.current === seedToken) {
108
108
  return;
109
109
  }
110
110
  lastSeedTokenRef.current = seedToken;
111
- if (!appendToChat) {
111
+ // Check clean
112
+ const clear = (askedQuestion || userContext) && !appendToChat;
113
+ if (clear) {
112
114
  chatDispatcher(clearThreadAction());
113
115
  }
114
116
  // Always set (and thereby clear when undefined) so a follow-up ask without context does not
115
117
  // inherit the previous ask's user context (LX-2544).
116
- chatDispatcher(setUserContextAction({ userContext }));
117
- if (settings.enableAiAgenticConversations) {
118
- chatDispatcher(newMessageAction(makeUserItem({ type: "text", text: askedQuestion })));
119
- }
120
- else {
121
- chatDispatcher(newMessageAction(makeUserMessage([makeTextContents(askedQuestion, [])])));
118
+ chatDispatcher(setUserContextAction({ userContext, replaceUserContext }));
119
+ // Ask question
120
+ if (askedQuestion) {
121
+ if (settings.enableAiAgenticConversations) {
122
+ chatDispatcher(newMessageAction(makeUserItem({ type: "text", text: askedQuestion })));
123
+ }
124
+ else {
125
+ chatDispatcher(newMessageAction(makeUserMessage([makeTextContents(askedQuestion, [])])));
126
+ }
122
127
  }
123
- }, [isOpen, chatDispatcher, askedQuestion, askSeq, userContext, appendToChat, settings]);
128
+ }, [
129
+ isOpen,
130
+ chatDispatcher,
131
+ askedQuestion,
132
+ askSeq,
133
+ userContext,
134
+ appendToChat,
135
+ settings,
136
+ replaceUserContext,
137
+ ]);
124
138
  return (_jsx(GenAIChatDialog, { isOpen: isOpen, locale: locale, backend: backend, workspace: workspace, canManage: canManage, canAnalyze: canAnalyze, canFullControl: canFullControl, settings: settings, objectTypes: objectTypes, includeTags: includeTags, excludeTags: excludeTags, className: className, dialogPosition: dialogPosition, colorPalette: colorPalette, allowNativeLinks: allowNativeLinks, onLinkClick: onLinkClick ?? defaultLinkClick, onOpen: onOpen, onClose: onClose, eventHandlers: eventHandlers, onDispatcher: onDispatcher, returnFocusTo: returnFocusTo }));
125
139
  }
@@ -1,5 +1,5 @@
1
1
  import { type FC } from "react";
2
- import { type IGenAIContextObject } from "../context/collectContextReferences.js";
2
+ import { type IGenAIContextObject } from "../types.js";
3
3
  type GenAiChatContextChooserOwnProps = {
4
4
  onAddContext?: (context: IGenAIContextObject) => void;
5
5
  };
@@ -1 +1 @@
1
- {"version":3,"file":"GenAiChatContextChooser.d.ts","sourceRoot":"","sources":["../../src/components/GenAiChatContextChooser.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAQhC,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAOlF,KAAK,+BAA+B,GAAG;IACnC,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACzD,CAAC;AA4FF,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,+BAA+B,CAG1C,CAAC"}
1
+ {"version":3,"file":"GenAiChatContextChooser.d.ts","sourceRoot":"","sources":["../../src/components/GenAiChatContextChooser.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,EAAE,MAAM,OAAO,CAAC;AAWhC,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAIvD,KAAK,+BAA+B,GAAG;IACnC,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACzD,CAAC;AA4FF,eAAO,MAAM,uBAAuB,EAAE,EAAE,CAAC,+BAA+B,CAG1C,CAAC"}
@@ -2,7 +2,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { defineMessages, useIntl } from "react-intl";
3
3
  import { connect } from "react-redux";
4
4
  import { Dropdown, UiIconButton, UiMenu, UiSubmenuHeader } from "@gooddata/sdk-ui-kit";
5
- import { ambientContextSelector, effectiveContextSelector } from "../store/chatWindow/chatWindowSelectors.js";
5
+ import { ambientContextSelector, userContextSelector } from "../store/chatWindow/chatWindowSelectors.js";
6
6
  import { addContextReferenceAction } from "../store/chatWindow/chatWindowSlice.js";
7
7
  import { useContextItems } from "./hooks/useContextItems.js";
8
8
  const msgs = defineMessages({
@@ -10,10 +10,10 @@ const msgs = defineMessages({
10
10
  id: "gd.gen-ai.context.add_context",
11
11
  },
12
12
  });
13
- function GenAiChatContextChooserCore({ currentAmbient, selectedAmbient, addContextReference, onAddContext, }) {
13
+ function GenAiChatContextChooserCore({ active, ambient, addContextReference, onAddContext, }) {
14
14
  const intl = useIntl();
15
- const items = useContextItems(currentAmbient, selectedAmbient, "ambient");
16
- if (!currentAmbient) {
15
+ const items = useContextItems(ambient, active);
16
+ if (!ambient) {
17
17
  return null;
18
18
  }
19
19
  return (_jsx("div", { className: "gd-gen-ai-chat__input__context", children: _jsx(Dropdown, { alignPoints: [{ align: "tl bl", offset: { x: 0, y: 0 } }], closeOnEscape: true, fullscreenOnMobile: false, autofocusOnOpen: true, accessibilityConfig: {}, renderButton: ({ isOpen, toggleDropdown, accessibilityConfig }) => (_jsx(UiIconButton, { icon: "plus", variant: "tertiary", size: "small", dataTestId: "choose_context", isActive: isOpen, accessibilityConfig: {
@@ -26,11 +26,11 @@ function GenAiChatContextChooserCore({ currentAmbient, selectedAmbient, addConte
26
26
  } })) }) }));
27
27
  }
28
28
  const mapStateToProps = (state) => {
29
- const currentAmbient = ambientContextSelector(state);
30
- const { ambient } = effectiveContextSelector(state);
29
+ const ambient = ambientContextSelector(state);
30
+ const active = userContextSelector(state);
31
31
  return {
32
- currentAmbient,
33
- selectedAmbient: ambient,
32
+ active,
33
+ ambient,
34
34
  };
35
35
  };
36
36
  const mapDispatchToProps = {
@@ -1,7 +1,7 @@
1
1
  import { type IGenAIUserContext } from "@gooddata/sdk-model";
2
2
  import { type IUiMenuItem } from "@gooddata/sdk-ui-kit";
3
- import { type IGenAIContextObject } from "../../context/collectContextReferences.js";
4
- export declare function useContextItems(current: IGenAIUserContext | undefined, selected: IGenAIUserContext | undefined, type: "ambient" | "user"): IUiMenuItem<{
3
+ import { type IGenAIContextObject } from "../../types.js";
4
+ export declare function useContextItems(ambient: IGenAIUserContext | undefined, active: IGenAIUserContext | undefined): IUiMenuItem<{
5
5
  interactive: IGenAIContextObject;
6
6
  }>[];
7
7
  //# sourceMappingURL=useContextItems.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useContextItems.d.ts","sourceRoot":"","sources":["../../../src/components/hooks/useContextItems.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,KAAK,WAAW,EAAU,MAAM,sBAAsB,CAAC;AAEhE,OAAO,EACH,KAAK,mBAAmB,EAE3B,MAAM,2CAA2C,CAAC;AAGnD,wBAAgB,eAAe,CAC3B,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,QAAQ,EAAE,iBAAiB,GAAG,SAAS,EACvC,IAAI,EAAE,SAAS,GAAG,MAAM,GACzB,WAAW,CAAC;IAAE,WAAW,EAAE,mBAAmB,CAAA;CAAE,CAAC,EAAE,CAgCrD"}
1
+ {"version":3,"file":"useContextItems.d.ts","sourceRoot":"","sources":["../../../src/components/hooks/useContextItems.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,KAAK,WAAW,EAAU,MAAM,sBAAsB,CAAC;AAMhE,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAG1D,wBAAgB,eAAe,CAC3B,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,MAAM,EAAE,iBAAiB,GAAG,SAAS,GACtC,WAAW,CAAC;IAAE,WAAW,EAAE,mBAAmB,CAAA;CAAE,CAAC,EAAE,CAgCrD"}
@@ -2,13 +2,13 @@ import { jsx as _jsx } from "react/jsx-runtime";
2
2
  // (C) 2026 GoodData Corporation
3
3
  import { useMemo } from "react";
4
4
  import { UiIcon } from "@gooddata/sdk-ui-kit";
5
- import { collectContextReferences, } from "../../context/collectContextReferences.js";
5
+ import { collectAvailableReferences, collectContextReferences, } from "../../context/collectContextReferences.js";
6
6
  import { getIconByType } from "../utils/icons.js";
7
- export function useContextItems(current, selected, type) {
7
+ export function useContextItems(ambient, active) {
8
8
  return useMemo(() => {
9
9
  const items = [];
10
- const currentReferences = collectContextReferences(current, type);
11
- const selectedReferences = collectContextReferences(selected, type);
10
+ const currentReferences = collectAvailableReferences(ambient);
11
+ const selectedReferences = collectContextReferences(active);
12
12
  currentReferences.forEach((reference) => {
13
13
  const isSelected = selectedReferences.some((selectedReference) => selectedReference.id === reference.id && selectedReference.type === reference.type);
14
14
  if (!isSelected) {
@@ -27,5 +27,5 @@ export function useContextItems(current, selected, type) {
27
27
  }
28
28
  });
29
29
  return items;
30
- }, [current, selected, type]);
30
+ }, [active, ambient]);
31
31
  }
@@ -1,6 +1,6 @@
1
- import { type GenAIObjectType } from "@gooddata/sdk-model";
2
1
  import { type IconType, type ThemeColor } from "@gooddata/sdk-ui-kit";
3
- export declare function getIconByType(type: GenAIObjectType): {
2
+ import { type IGenAIContextObject } from "../../types.js";
3
+ export declare function getIconByType(type: IGenAIContextObject["type"]): {
4
4
  iconBefore?: IconType;
5
5
  iconColor?: ThemeColor;
6
6
  };
@@ -1 +1 @@
1
- {"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../../src/components/utils/icons.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEtE,wBAAgB,aAAa,CAAC,IAAI,EAAE,eAAe,GAAG;IAAE,UAAU,CAAC,EAAE,QAAQ,CAAC;IAAC,SAAS,CAAC,EAAE,UAAU,CAAA;CAAE,CActG"}
1
+ {"version":3,"file":"icons.d.ts","sourceRoot":"","sources":["../../../src/components/utils/icons.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,QAAQ,EAAE,KAAK,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEtE,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,wBAAgB,aAAa,CAAC,IAAI,EAAE,mBAAmB,CAAC,MAAM,CAAC,GAAG;IAC9D,UAAU,CAAC,EAAE,QAAQ,CAAC;IACtB,SAAS,CAAC,EAAE,UAAU,CAAC;CAC1B,CAeA"}
@@ -7,6 +7,7 @@ export function getIconByType(type) {
7
7
  iconColor: "complementary-6",
8
8
  };
9
9
  case "visualization":
10
+ case "widget":
10
11
  return {
11
12
  iconBefore: "visualization",
12
13
  };
@@ -1,4 +1,5 @@
1
- import { type StoreContext } from "../types.js";
2
- import type { IGenAIContextObject } from "./collectContextReferences.js";
1
+ import { type IGenAIUserContext } from "@gooddata/sdk-model";
2
+ import { type IGenAIContextObject, type StoreContext } from "../types.js";
3
3
  export declare function addContextReference(context: StoreContext, reference?: IGenAIContextObject): StoreContext;
4
+ export declare function addAmbientContextReferences(context: StoreContext, userContext?: IGenAIUserContext): StoreContext;
4
5
  //# sourceMappingURL=addContextReference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"addContextReference.d.ts","sourceRoot":"","sources":["../../src/context/addContextReference.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,mBAAmB,GAAG,YAAY,CAoBxG"}
1
+ {"version":3,"file":"addContextReference.d.ts","sourceRoot":"","sources":["../../src/context/addContextReference.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,KAAK,iBAAiB,EAEzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,mBAAmB,EAAE,KAAK,YAAY,EAAE,MAAM,aAAa,CAAC;AAM1E,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,YAAY,EAAE,SAAS,CAAC,EAAE,mBAAmB,GAAG,YAAY,CA+DxG;AAED,wBAAgB,2BAA2B,CACvC,OAAO,EAAE,YAAY,EACrB,WAAW,CAAC,EAAE,iBAAiB,GAChC,YAAY,CAgBd"}
@@ -1,19 +1,74 @@
1
1
  // (C) 2026 GoodData Corporation
2
- import { areObjRefsEqual } from "@gooddata/sdk-model";
2
+ import { areObjRefsEqual, } from "@gooddata/sdk-model";
3
+ import { convertGenAiTypeToReferenceType } from "../utils.js";
4
+ import { mergeContexts } from "./build.js";
5
+ import { isReferenceChanged } from "./isReferenceChanged.js";
3
6
  export function addContextReference(context, reference) {
4
- const { ambient } = context;
7
+ const { ambient, active } = context;
5
8
  if (!reference) {
6
9
  return context;
7
10
  }
8
- if (reference.where === "view.dashboard") {
9
- const ambientRef = ambient?.view?.dashboard?.ref;
10
- const ref = reference.ref;
11
- if (areObjRefsEqual(ambientRef, ref)) {
11
+ if (reference.where === "view.dashboard" && ambient?.view?.dashboard) {
12
+ const ambientDashboard = ambient.view.dashboard;
13
+ if (areObjRefsEqual(ambientDashboard.ref, reference.ref)) {
12
14
  return {
13
15
  ...context,
14
- ambientMode: "enabled",
16
+ active: {
17
+ ...active,
18
+ view: {
19
+ dashboard: ambientDashboard,
20
+ },
21
+ },
15
22
  };
16
23
  }
17
24
  }
25
+ if (reference.where === "referencedObjects") {
26
+ const refContext = reference.context;
27
+ const referencedObjects = (active?.referencedObjects ?? []).slice();
28
+ const index = referencedObjects.findIndex((obj) => areObjRefsEqual(obj.context?.ref, refContext?.ref) || obj.context === refContext);
29
+ let group;
30
+ if (index === -1) {
31
+ group = {
32
+ context: refContext,
33
+ objects: [],
34
+ };
35
+ referencedObjects.push(group);
36
+ }
37
+ else {
38
+ const item = referencedObjects[index];
39
+ group = {
40
+ ...item,
41
+ context: item.context,
42
+ objects: item.objects.slice(),
43
+ };
44
+ referencedObjects[index] = group;
45
+ }
46
+ group.objects.push({
47
+ ref: reference.ref,
48
+ title: reference.title,
49
+ type: convertGenAiTypeToReferenceType(reference.type),
50
+ });
51
+ return {
52
+ ...context,
53
+ active: {
54
+ ...active,
55
+ referencedObjects,
56
+ },
57
+ };
58
+ }
18
59
  return context;
19
60
  }
61
+ export function addAmbientContextReferences(context, userContext) {
62
+ const updateActive = Boolean(!context.ambient ||
63
+ context.active?.view?.dashboard ||
64
+ isReferenceChanged(context.ambient, userContext));
65
+ return {
66
+ ...context,
67
+ ambient: userContext,
68
+ ...(updateActive
69
+ ? {
70
+ active: mergeContexts(context.active, userContext),
71
+ }
72
+ : {}),
73
+ };
74
+ }
@@ -1,7 +1,7 @@
1
- import type { IGenAIUserContext } from "@gooddata/sdk-model";
1
+ import { type IGenAIUserContext } from "@gooddata/sdk-model";
2
2
  export declare function buildContext(props: Partial<IGenAIUserContext>): IGenAIUserContext;
3
3
  /**
4
4
  * @internal
5
5
  */
6
- export declare function mergeContexts(...contexts: IGenAIUserContext[]): IGenAIUserContext;
6
+ export declare function mergeContexts(...contexts: (IGenAIUserContext | undefined)[]): IGenAIUserContext | undefined;
7
7
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/context/build.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAIjF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,iBAAiB,EAAE,GAAG,iBAAiB,CAQjF"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../src/context/build.ts"],"names":[],"mappings":"AAEA,OAAO,EAGH,KAAK,iBAAiB,EAEzB,MAAM,qBAAqB,CAAC;AAE7B,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAIjF;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,GAAG,QAAQ,EAAE,CAAC,iBAAiB,GAAG,SAAS,CAAC,EAAE,GAAG,iBAAiB,GAAG,SAAS,CAsB3G"}
@@ -1,4 +1,5 @@
1
1
  // (C) 2026 GoodData Corporation
2
+ import { areObjRefsEqual, } from "@gooddata/sdk-model";
2
3
  export function buildContext(props) {
3
4
  return {
4
5
  ...props,
@@ -8,11 +9,41 @@ export function buildContext(props) {
8
9
  * @internal
9
10
  */
10
11
  export function mergeContexts(...contexts) {
11
- return contexts.reduce((acc, context) => {
12
+ const merged = contexts.reduce((acc, context) => {
13
+ if (!context) {
14
+ return acc;
15
+ }
16
+ const dashboard = mergeDashboard(context.view?.dashboard, acc.view?.dashboard);
17
+ const view = {
18
+ ...(dashboard ? { dashboard } : {}),
19
+ };
20
+ const activeObject = mergeActiveObject(context.activeObject, acc.activeObject);
21
+ const referencedObjects = [...(acc?.referencedObjects ?? []), ...(context?.referencedObjects ?? [])];
12
22
  return {
13
- view: context.view ?? acc.view,
14
- activeObject: context.activeObject ?? acc.activeObject,
15
- referencedObjects: [...(acc?.referencedObjects ?? []), ...(context?.referencedObjects ?? [])],
23
+ ...(Object.keys(view).length > 0 ? { view } : {}),
24
+ ...(activeObject ? { activeObject } : {}),
25
+ ...(referencedObjects.length > 0 ? { referencedObjects } : {}),
16
26
  };
17
27
  }, {});
28
+ return Object.keys(merged).length > 0 ? merged : undefined;
29
+ }
30
+ function mergeDashboard(dashboard, existingDashboard) {
31
+ if (areObjRefsEqual(dashboard?.ref, existingDashboard?.ref)) {
32
+ const merged = {
33
+ ...existingDashboard,
34
+ ...dashboard,
35
+ };
36
+ return Object.keys(merged).length > 0 ? merged : undefined;
37
+ }
38
+ return dashboard ?? existingDashboard;
39
+ }
40
+ function mergeActiveObject(activeObject, existingActiveObject) {
41
+ if (areObjRefsEqual(activeObject?.ref, existingActiveObject?.ref)) {
42
+ const merged = {
43
+ ...existingActiveObject,
44
+ ...activeObject,
45
+ };
46
+ return Object.keys(merged).length > 0 ? merged : undefined;
47
+ }
48
+ return activeObject ?? existingActiveObject;
18
49
  }
@@ -1,11 +1,5 @@
1
- import { type GenAIObjectType, type IGenAIUserContext, type ObjRef } from "@gooddata/sdk-model";
2
- export interface IGenAIContextObject {
3
- id: string;
4
- ref: ObjRef;
5
- title: string;
6
- type: GenAIObjectType;
7
- where: "view.dashboard";
8
- nesting: number;
9
- }
10
- export declare function collectContextReferences(context: IGenAIUserContext | undefined, type: "ambient" | "user"): IGenAIContextObject[];
1
+ import { type IGenAIUserContext } from "@gooddata/sdk-model";
2
+ import { type IGenAIContextObject } from "../types.js";
3
+ export declare function collectContextReferences(context: IGenAIUserContext | undefined): IGenAIContextObject[];
4
+ export declare function collectAvailableReferences(context: IGenAIUserContext | undefined): IGenAIContextObject[];
11
5
  //# sourceMappingURL=collectContextReferences.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"collectContextReferences.d.ts","sourceRoot":"","sources":["../../src/context/collectContextReferences.ts"],"names":[],"mappings":"AAEA,OAAO,EACH,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,MAAM,EAEd,MAAM,qBAAqB,CAAC;AAE7B,MAAM,WAAW,mBAAmB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,eAAe,CAAC;IACtB,KAAK,EAAE,gBAAgB,CAAC;IACxB,OAAO,EAAE,MAAM,CAAC;CACnB;AAED,wBAAgB,wBAAwB,CACpC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,IAAI,EAAE,SAAS,GAAG,MAAM,GACzB,mBAAmB,EAAE,CA6BvB"}
1
+ {"version":3,"file":"collectContextReferences.d.ts","sourceRoot":"","sources":["../../src/context/collectContextReferences.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,KAAK,iBAAiB,EAGzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,mBAAmB,EAAE,CAwCtG;AAED,wBAAgB,0BAA0B,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,mBAAmB,EAAE,CAiFxG"}
@@ -1,6 +1,7 @@
1
1
  // (C) 2026 GoodData Corporation
2
- import { isIdentifierRef, } from "@gooddata/sdk-model";
3
- export function collectContextReferences(context, type) {
2
+ import { isIdentifierRef, serializeObjRef, } from "@gooddata/sdk-model";
3
+ import { convertReferenceTypeToGenAiType } from "../utils.js";
4
+ export function collectContextReferences(context) {
4
5
  if (!context) {
5
6
  return [];
6
7
  }
@@ -19,11 +20,98 @@ export function collectContextReferences(context, type) {
19
20
  nesting: 0,
20
21
  });
21
22
  }
22
- //NOTE: For ambient we need to return only one object with
23
- // most deep nesting level.
24
- if (type === "ambient") {
25
- return references.sort((a, b) => b.nesting - a.nesting).slice(0, 1);
23
+ // references
24
+ context.referencedObjects?.forEach((obj) => {
25
+ obj.objects.forEach((item) => {
26
+ const ref = item.ref;
27
+ const id = isIdentifierRef(ref) ? ref.identifier : ref.uri;
28
+ references.push({
29
+ id,
30
+ ref,
31
+ nesting: 1,
32
+ where: "referencedObjects",
33
+ title: item.title ?? id,
34
+ type: convertReferenceTypeToGenAiType(item.type),
35
+ });
36
+ });
37
+ });
38
+ return references.sort((a, b) => a.nesting - b.nesting);
39
+ }
40
+ export function collectAvailableReferences(context) {
41
+ if (!context) {
42
+ return [];
43
+ }
44
+ const references = [];
45
+ const used = [];
46
+ // dashboard
47
+ const dashboard = context.view?.dashboard;
48
+ if (dashboard) {
49
+ const dashboardRef = dashboard.ref;
50
+ const dashboardId = isIdentifierRef(dashboardRef) ? dashboardRef.identifier : dashboardRef.uri;
51
+ references.push({
52
+ id: dashboardId,
53
+ ref: dashboardRef,
54
+ type: "dashboard",
55
+ where: "view.dashboard",
56
+ title: dashboard.title ?? dashboardId,
57
+ nesting: 0,
58
+ });
59
+ used.push(serializeObjRef(dashboardRef));
60
+ const context = {
61
+ ref: dashboardRef,
62
+ type: "DASHBOARD",
63
+ title: dashboard.title ?? dashboardId,
64
+ };
65
+ dashboard.widgets.forEach((widget) => {
66
+ switch (widget.widgetType) {
67
+ case "insight": {
68
+ const ref = widget.widgetRef;
69
+ if (!ref) {
70
+ return;
71
+ }
72
+ const id = isIdentifierRef(ref) ? ref.identifier : ref.uri;
73
+ const key = serializeObjRef(ref);
74
+ if (!used.includes(key)) {
75
+ used.push(key);
76
+ references.push({
77
+ id,
78
+ ref,
79
+ nesting: 1,
80
+ where: "referencedObjects",
81
+ title: widget.title ?? id,
82
+ type: "widget",
83
+ context,
84
+ });
85
+ }
86
+ break;
87
+ }
88
+ case "visualizationSwitcher": {
89
+ widget.visualizations?.forEach((visualization) => {
90
+ const ref = visualization.widgetRef;
91
+ if (!ref) {
92
+ return;
93
+ }
94
+ const id = isIdentifierRef(ref) ? ref.identifier : ref.uri;
95
+ const key = serializeObjRef(ref);
96
+ if (!used.includes(key)) {
97
+ used.push(key);
98
+ references.push({
99
+ id,
100
+ ref,
101
+ nesting: 1,
102
+ where: "referencedObjects",
103
+ title: visualization.title ?? id,
104
+ type: "widget",
105
+ context,
106
+ });
107
+ }
108
+ });
109
+ break;
110
+ }
111
+ default:
112
+ break;
113
+ }
114
+ });
26
115
  }
27
- //NOTE: For user we need to return all objects.
28
- return references;
116
+ return references.sort((a, b) => a.nesting - b.nesting);
29
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"dashboard.d.ts","sourceRoot":"","sources":["../../src/context/dashboard.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,mCAAmC,EACxC,KAAK,sBAAsB,EAC3B,KAAK,qBAAqB,EAC1B,KAAK,iBAAiB,EAEtB,KAAK,sBAAsB,EAC3B,KAAK,OAAO,EACZ,KAAK,MAAM,EASd,MAAM,qBAAqB,CAAC;AAM7B;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,sBAAsB,GAAG,iBAAiB,CAM1F;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAC9B,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EACjB,UAAU,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AK,CAAC,EAAE,OAAO,CAAC,IAAI,CAAC,sBAAsB,EAAE,OAAO,GAAG,WAAW,GAAG,YAAY,CAAC,CAAC,GACpF,sBAAsB,CAOxB;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,OAAO,EAAE,iBAAiB,EAAE,EAC5B,YAAY,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,mCAAmC,CAAC,EAAE,KAAK,CAAC,GAC7E,sBAAsB,EAAE,CA2E1B;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAC/B,UAAU,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC,EACxD,YAAY,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAC,GACvE;IAAE,OAAO,EAAE,sBAAsB,EAAE,CAAC;IAAC,iBAAiB,EAAE,qBAAqB,EAAE,CAAA;CAAE,CA+DnF"}
@@ -109,21 +109,27 @@ export function buildWidgetsContext(widgetsMap, resultsIdMap) {
109
109
  insightRef: widget.insight,
110
110
  resultId: resultsIdMap?.get(serializeObjRef(widget.ref)),
111
111
  }));
112
- referencedObjects.push({ type: "WIDGET", ref: widget.ref });
112
+ referencedObjects.push({ type: "WIDGET", ref: widget.ref, title: widget.title });
113
113
  }
114
114
  }
115
115
  if (isVisualizationSwitcherWidget(widget)) {
116
116
  const activeVisualization = widget.visualizations[0];
117
- widgets.push(buildWidgetContext(widget.title, widget.ref, "visualizationSwitcher", {
117
+ widgets.push(buildWidgetContext(widget.title || activeVisualization?.title, widget.ref, "visualizationSwitcher", {
118
118
  insightRef: activeVisualization?.insight,
119
119
  resultId: activeVisualization
120
120
  ? resultsIdMap?.get(serializeObjRef(activeVisualization.ref))
121
121
  : undefined,
122
122
  // All child insights, so the BE can execute the non-active children
123
123
  // (which have no cached result).
124
- visualizationRefs: widget.visualizations.map((v) => v.insight),
124
+ visualizations: widget.visualizations.map((v) => buildWidgetContext(v.title, v.ref, "insight", {
125
+ insightRef: v.insight,
126
+ })),
125
127
  }));
126
- referencedObjects.push({ type: "WIDGET", ref: widget.ref });
128
+ referencedObjects.push({
129
+ type: "WIDGET",
130
+ ref: widget.ref,
131
+ title: widget.title || activeVisualization?.title,
132
+ });
127
133
  }
128
134
  if (isRichTextWidget(widget)) {
129
135
  widgets.push(buildWidgetContext(widget.title, widget.ref, "richText", {
@@ -1,4 +1,5 @@
1
1
  import { type IGenAIUserContext } from "@gooddata/sdk-model";
2
- import type { IGenAIContextObject } from "./collectContextReferences.js";
2
+ import { type IGenAIContextObject } from "../types.js";
3
3
  export declare function removeContextReference(context: IGenAIUserContext | undefined, reference?: IGenAIContextObject): IGenAIUserContext | undefined;
4
+ export declare function removeUserContextReferences(context: IGenAIUserContext | undefined): IGenAIUserContext | undefined;
4
5
  //# sourceMappingURL=removeContextReference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"removeContextReference.d.ts","sourceRoot":"","sources":["../../src/context/removeContextReference.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAEzE,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,SAAS,CAAC,EAAE,mBAAmB,GAChC,iBAAiB,GAAG,SAAS,CA6B/B"}
1
+ {"version":3,"file":"removeContextReference.d.ts","sourceRoot":"","sources":["../../src/context/removeContextReference.ts"],"names":[],"mappings":"AAEA,OAAO,EAEH,KAAK,iBAAiB,EAEzB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD,wBAAgB,sBAAsB,CAClC,OAAO,EAAE,iBAAiB,GAAG,SAAS,EACtC,SAAS,CAAC,EAAE,mBAAmB,GAChC,iBAAiB,GAAG,SAAS,CAgD/B;AAED,wBAAgB,2BAA2B,CACvC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GACvC,iBAAiB,GAAG,SAAS,CAY/B"}