@cognizant-ai-lab/ui-common 1.8.0 → 1.10.0

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 (59) hide show
  1. package/README.md +3 -3
  2. package/dist/components/AgentChat/ChatCommon/ChatCommon.d.ts +9 -3
  3. package/dist/components/AgentChat/ChatCommon/ChatCommon.js +94 -27
  4. package/dist/components/AgentChat/ChatCommon/ChatHistory.d.ts +7 -0
  5. package/dist/components/AgentChat/ChatCommon/ChatHistory.js +1 -1
  6. package/dist/components/AgentChat/ChatCommon/ControlButtons.d.ts +4 -2
  7. package/dist/components/AgentChat/ChatCommon/ControlButtons.js +8 -2
  8. package/dist/components/AgentChat/ChatCommon/ConversationTurn.d.ts +5 -5
  9. package/dist/components/AgentChat/ChatCommon/ConversationTurn.js +1 -0
  10. package/dist/components/AgentChat/ChatCommon/Thinking.js +2 -2
  11. package/dist/components/AgentChat/Common/Utils.d.ts +0 -7
  12. package/dist/components/AgentChat/Common/Utils.js +0 -12
  13. package/dist/components/Common/Breadcrumbs.js +1 -1
  14. package/dist/components/Common/Footer.js +4 -0
  15. package/dist/components/Common/notification.d.ts +4 -4
  16. package/dist/components/MultiAgentAccelerator/{AgentFlow.d.ts → AgentFlow/AgentFlow.d.ts} +15 -5
  17. package/dist/components/MultiAgentAccelerator/{AgentFlow.js → AgentFlow/AgentFlow.js} +99 -58
  18. package/dist/components/MultiAgentAccelerator/{AgentNode.d.ts → AgentFlow/AgentNode.d.ts} +1 -1
  19. package/dist/components/MultiAgentAccelerator/{AgentNode.js → AgentFlow/AgentNode.js} +11 -9
  20. package/dist/components/MultiAgentAccelerator/{GraphLayouts.d.ts → AgentFlow/GraphLayouts.d.ts} +4 -4
  21. package/dist/components/MultiAgentAccelerator/{GraphLayouts.js → AgentFlow/GraphLayouts.js} +15 -41
  22. package/dist/components/MultiAgentAccelerator/AgentFlow/GraphStructure.d.ts +21 -0
  23. package/dist/components/MultiAgentAccelerator/AgentFlow/GraphStructure.js +27 -0
  24. package/dist/components/MultiAgentAccelerator/AgentFlow/PlasmaEdge.d.ts +7 -0
  25. package/dist/components/MultiAgentAccelerator/{PlasmaEdge.js → AgentFlow/PlasmaEdge.js} +13 -8
  26. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.js +74 -83
  27. package/dist/components/MultiAgentAccelerator/Schema/SlyData.d.ts +17 -0
  28. package/dist/components/MultiAgentAccelerator/Schema/SlyData.js +23 -0
  29. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.d.ts +2 -0
  30. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.js +22 -25
  31. package/dist/components/MultiAgentAccelerator/Sidebar/Sidebar.js +16 -22
  32. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.d.ts +1 -0
  33. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.js +27 -7
  34. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.d.ts +8 -0
  35. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.js +61 -13
  36. package/dist/components/MultiAgentAccelerator/{ThoughtBubbleEdge.d.ts → ThoughtBubbles/ThoughtBubbleEdge.d.ts} +1 -1
  37. package/dist/components/MultiAgentAccelerator/{ThoughtBubbleOverlay.js → ThoughtBubbles/ThoughtBubbleOverlay.js} +1 -1
  38. package/dist/components/MultiAgentAccelerator/Tour/MainTourSteps.js +7 -2
  39. package/dist/components/MultiAgentAccelerator/const.d.ts +11 -10
  40. package/dist/components/MultiAgentAccelerator/const.js +22 -20
  41. package/dist/components/Settings/SettingsDialog.js +26 -10
  42. package/dist/controller/agent/Agent.d.ts +14 -6
  43. package/dist/controller/agent/Agent.js +18 -14
  44. package/dist/index.d.ts +1 -1
  45. package/dist/index.js +1 -1
  46. package/dist/state/Settings.d.ts +81 -4
  47. package/dist/state/Settings.js +87 -7
  48. package/dist/state/TemporaryNetworks.js +12 -21
  49. package/dist/tsconfig.build.tsbuildinfo +1 -1
  50. package/dist/utils/AgentName.d.ts +17 -0
  51. package/dist/utils/AgentName.js +46 -0
  52. package/dist/utils/BrowserNavigation.js +2 -0
  53. package/dist/utils/File.d.ts +4 -1
  54. package/dist/utils/File.js +4 -9
  55. package/dist/utils/text.js +3 -7
  56. package/package.json +9 -10
  57. package/dist/components/MultiAgentAccelerator/PlasmaEdge.d.ts +0 -3
  58. /package/dist/components/MultiAgentAccelerator/{ThoughtBubbleEdge.js → ThoughtBubbles/ThoughtBubbleEdge.js} +0 -0
  59. /package/dist/components/MultiAgentAccelerator/{ThoughtBubbleOverlay.d.ts → ThoughtBubbles/ThoughtBubbleOverlay.d.ts} +0 -0
@@ -17,6 +17,13 @@ import { merge } from "lodash-es";
17
17
  import { create } from "zustand";
18
18
  import { persist } from "zustand/middleware";
19
19
  import { PALETTES } from "../Theme/Palettes.js";
20
+ //#endregion Interfaces and Types
21
+ //#region Constants
22
+ // Mapping of LLM providers to their corresponding API key field names in the settings store.
23
+ export const LLM_PROVIDER_API_KEY_FIELD = {
24
+ OpenAI: "openai_api_key",
25
+ Anthropic: "anthropic_api_key",
26
+ };
20
27
  /**
21
28
  * Default settings, used on first load and on reset
22
29
  */
@@ -47,22 +54,95 @@ export const DEFAULT_SETTINGS = {
47
54
  neuroSanUrl: null,
48
55
  },
49
56
  };
57
+ // Name for key where main app settings are saved
58
+ export const APP_SETTINGS_STORAGE_KEY = "app-settings";
59
+ // Name for key where API keys are saved in sessionStorage.
60
+ export const SESSION_API_KEYS_STORAGE_KEY = "app-settings-api-keys";
61
+ // TTL for API keys in sessionStorage. After this time, the keys will be cleared from sessionStorage.
62
+ // This is a backstop for cases where users rarely close their browser or tabs
63
+ export const API_KEYS_TTL_MS = 2 * 24 * 60 * 60 * 1000; // 2 days
64
+ //#endregion Constants
65
+ const hasPersistedSettings = (state) => typeof state === "object" &&
66
+ state !== null &&
67
+ "settings" in state &&
68
+ typeof state.settings === "object" &&
69
+ state.settings !== null;
70
+ /**
71
+ * Purges any persisted API keys from localStorage. This cleans up from previous versions of the cdoe.
72
+ * Once we are "reasonably sure" that no users are on old versions, we can remove this function.
73
+ */
74
+ const purgePersistedApiKeys = () => {
75
+ const persisted = JSON.parse(localStorage.getItem(APP_SETTINGS_STORAGE_KEY) ?? "{}");
76
+ if (persisted.state?.settings) {
77
+ delete persisted.state.settings.apiKeys;
78
+ localStorage.setItem(APP_SETTINGS_STORAGE_KEY, JSON.stringify(persisted));
79
+ }
80
+ };
81
+ /**
82
+ * Function to determine if an API key entry is valid (i.e., exists and is not expired).
83
+ * @param entry The API key entry to validate
84
+ * @returns True if the entry exists and is not expired, false otherwise
85
+ */
86
+ const isApiKeyValid = (entry) => Boolean(entry) && entry.expiresAt > Date.now();
87
+ /**
88
+ * Returns the API key for the given provider if it exists and is not expired, otherwise returns undefined.
89
+ * This helper should be used to retrieve API keys from the settings store, rather than accessing the store directly,
90
+ * to ensure that expired keys are not returned.
91
+ * @param apiKeys Set of API keys stored in the settings store
92
+ * @param provider The LLM provider for which to retrieve the API key
93
+ */
94
+ export const getApiKey = (apiKeys, provider) => {
95
+ const entry = apiKeys[provider];
96
+ return isApiKeyValid(entry) ? entry.value : undefined;
97
+ };
50
98
  /**
51
99
  * The hook that lets apps use the store
52
100
  */
53
101
  export const useSettingsStore = create()(persist((set) => ({
54
102
  settings: DEFAULT_SETTINGS,
55
- updateSettings: (updates) => set((state) => ({
56
- settings: merge({}, state.settings, updates),
57
- })),
58
- resetSettings: () => set({ settings: DEFAULT_SETTINGS }),
103
+ updateSettings: (updates) => set((state) => {
104
+ const nextSettings = merge({}, state.settings, updates);
105
+ // Side effect: persist API keys in sessionStorage, unlike other Settings items which are persisted
106
+ // to localStorage (zustand default)
107
+ // Timestamp the API keys so we can purge them after a TTL.
108
+ if (updates.apiKeys) {
109
+ sessionStorage.setItem(SESSION_API_KEYS_STORAGE_KEY, JSON.stringify(nextSettings.apiKeys));
110
+ }
111
+ return {
112
+ settings: nextSettings,
113
+ };
114
+ }),
115
+ resetSettings: () => {
116
+ sessionStorage.removeItem(SESSION_API_KEYS_STORAGE_KEY);
117
+ set({ settings: DEFAULT_SETTINGS });
118
+ },
59
119
  }), {
60
- name: "app-settings",
120
+ name: APP_SETTINGS_STORAGE_KEY,
121
+ // We don't want to persist API keys in localStorage, so we remove them before saving the state.
122
+ partialize: (state) => {
123
+ const { apiKeys: _apiKeys, ...settingsWithoutApiKeys } = state.settings;
124
+ return {
125
+ ...state,
126
+ settings: settingsWithoutApiKeys,
127
+ };
128
+ },
61
129
  merge: (persistedState, currentState) => {
62
- // Merge persisted settings with defaults to fill in any missing fields
130
+ // This is the hook that runs when the store is rehydrated from localStorage.
131
+ // We use it to purge any persisted API keys from previous versions of the code.
132
+ purgePersistedApiKeys();
133
+ // Now we can read the API keys from sessionStorage and filter out any expired keys.
134
+ const storedApiKeys = JSON.parse(sessionStorage.getItem(SESSION_API_KEYS_STORAGE_KEY) ?? "{}");
135
+ const sessionApiKeys = Object.fromEntries(Object.entries(storedApiKeys).filter(([, entry]) => isApiKeyValid(entry)));
136
+ sessionStorage.setItem(SESSION_API_KEYS_STORAGE_KEY, JSON.stringify(sessionApiKeys));
137
+ const persistedSettings = hasPersistedSettings(persistedState) ? persistedState.settings : {};
138
+ // Merge persisted settings with defaults to fill in any missing fields,
139
+ // then explicitly replace apiKeys with sessionStorage-backed keys.
63
140
  return {
64
141
  ...currentState,
65
- settings: merge({}, DEFAULT_SETTINGS, persistedState.settings),
142
+ settings: {
143
+ ...merge({}, DEFAULT_SETTINGS, persistedSettings),
144
+ apiKeys: sessionApiKeys,
145
+ },
66
146
  };
67
147
  },
68
148
  }));
@@ -13,6 +13,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
13
  See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
+ import { keyBy } from "lodash-es";
16
17
  import { create } from "zustand";
17
18
  import { persist } from "zustand/middleware";
18
19
  /**
@@ -22,29 +23,19 @@ export const useTempNetworksStore = create()(persist((set) => ({
22
23
  tempNetworks: [],
23
24
  setTempNetworks: (tempNetworks) => set({ tempNetworks }),
24
25
  upsertTempNetworks: (incomingNetworks) => {
25
- set((state) => {
26
- const updated = [...state.tempNetworks];
27
- for (const incomingNetwork of incomingNetworks) {
28
- const existingIndex = updated.findIndex((network) => network.agentNetworkName === incomingNetwork.agentNetworkName);
29
- if (existingIndex >= 0) {
30
- updated[existingIndex] = incomingNetwork; // replace the existing entry in-place
31
- }
32
- else {
33
- updated.push(incomingNetwork); // no existing entry — add as new
34
- }
35
- }
36
- return { tempNetworks: updated };
37
- });
26
+ set((state) => ({
27
+ // Key both sides by name and let incoming win; existing entries keep their position,
28
+ // new ones are appended.
29
+ tempNetworks: Object.values({
30
+ ...keyBy(state.tempNetworks, "agentNetworkName"),
31
+ ...keyBy(incomingNetworks, "agentNetworkName"),
32
+ }),
33
+ }));
38
34
  return incomingNetworks;
39
35
  },
40
- updateTempNetworkDefinition: (networkName, agentNetworkDefinition) => set((state) => {
41
- const updated = [...state.tempNetworks];
42
- const existingIndex = updated.findIndex((network) => network.agentInfo.agent_name === networkName);
43
- if (existingIndex >= 0) {
44
- updated[existingIndex] = { ...updated[existingIndex], agentNetworkDefinition };
45
- }
46
- return { tempNetworks: updated };
47
- }),
36
+ updateTempNetworkDefinition: (networkName, agentNetworkDefinition) => set(({ tempNetworks }) => ({
37
+ tempNetworks: tempNetworks.map((network) => network.agentInfo.agent_name === networkName ? { ...network, agentNetworkDefinition } : network),
38
+ })),
48
39
  }), {
49
40
  name: "temp-networks",
50
41
  }));