@cognizant-ai-lab/ui-common 1.8.0 → 1.9.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 (56) 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 +89 -23
  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/Common/Utils.d.ts +4 -0
  11. package/dist/components/AgentChat/Common/Utils.js +5 -1
  12. package/dist/components/Common/Breadcrumbs.js +1 -1
  13. package/dist/components/Common/notification.d.ts +4 -4
  14. package/dist/components/MultiAgentAccelerator/{AgentFlow.d.ts → AgentFlow/AgentFlow.d.ts} +15 -5
  15. package/dist/components/MultiAgentAccelerator/{AgentFlow.js → AgentFlow/AgentFlow.js} +44 -35
  16. package/dist/components/MultiAgentAccelerator/{AgentNode.d.ts → AgentFlow/AgentNode.d.ts} +1 -1
  17. package/dist/components/MultiAgentAccelerator/{AgentNode.js → AgentFlow/AgentNode.js} +4 -4
  18. package/dist/components/MultiAgentAccelerator/{GraphLayouts.d.ts → AgentFlow/GraphLayouts.d.ts} +4 -4
  19. package/dist/components/MultiAgentAccelerator/{GraphLayouts.js → AgentFlow/GraphLayouts.js} +6 -35
  20. package/dist/components/MultiAgentAccelerator/AgentFlow/GraphStructure.d.ts +21 -0
  21. package/dist/components/MultiAgentAccelerator/AgentFlow/GraphStructure.js +27 -0
  22. package/dist/components/MultiAgentAccelerator/AgentFlow/PlasmaEdge.d.ts +7 -0
  23. package/dist/components/MultiAgentAccelerator/{PlasmaEdge.js → AgentFlow/PlasmaEdge.js} +13 -8
  24. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.js +116 -78
  25. package/dist/components/MultiAgentAccelerator/Schema/SlyData.d.ts +17 -0
  26. package/dist/components/MultiAgentAccelerator/Schema/SlyData.js +23 -0
  27. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.js +9 -4
  28. package/dist/components/MultiAgentAccelerator/Sidebar/ImportNetworkModal.d.ts +67 -0
  29. package/dist/components/MultiAgentAccelerator/Sidebar/ImportNetworkModal.js +585 -0
  30. package/dist/components/MultiAgentAccelerator/Sidebar/Sidebar.d.ts +2 -0
  31. package/dist/components/MultiAgentAccelerator/Sidebar/Sidebar.js +19 -26
  32. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.d.ts +2 -1
  33. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.js +24 -4
  34. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.d.ts +22 -0
  35. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.js +74 -3
  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 +5 -0
  39. package/dist/components/MultiAgentAccelerator/const.d.ts +1 -0
  40. package/dist/components/MultiAgentAccelerator/const.js +2 -0
  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/tsconfig.build.tsbuildinfo +1 -1
  49. package/dist/utils/BrowserNavigation.js +2 -0
  50. package/dist/utils/File.d.ts +4 -1
  51. package/dist/utils/File.js +4 -9
  52. package/dist/utils/text.js +3 -7
  53. package/package.json +9 -10
  54. package/dist/components/MultiAgentAccelerator/PlasmaEdge.d.ts +0 -3
  55. /package/dist/components/MultiAgentAccelerator/{ThoughtBubbleEdge.js → ThoughtBubbles/ThoughtBubbleEdge.js} +0 -0
  56. /package/dist/components/MultiAgentAccelerator/{ThoughtBubbleOverlay.d.ts → ThoughtBubbles/ThoughtBubbleOverlay.d.ts} +0 -0
@@ -11,6 +11,13 @@ type DeepPartial<T> = {
11
11
  };
12
12
  export type LLMProvider = "OpenAI" | "Anthropic";
13
13
  export type LogoSource = "none" | "generic" | "auto";
14
+ export type ByokKeyField = (typeof LLM_PROVIDER_API_KEY_FIELD)[LLMProvider];
15
+ interface ApiKeyEntry {
16
+ readonly value: string;
17
+ readonly expiresAt: number;
18
+ }
19
+ type ApiKeys = Partial<Record<LLMProvider, ApiKeyEntry>>;
20
+ export type PaletteKey = keyof typeof PALETTES | "brand";
14
21
  /**
15
22
  * User preference settings
16
23
  */
@@ -35,7 +42,7 @@ interface Settings {
35
42
  readonly behavior: {
36
43
  readonly enableZenMode: boolean;
37
44
  };
38
- readonly apiKeys: Partial<Record<LLMProvider, string>>;
45
+ readonly apiKeys: ApiKeys;
39
46
  readonly externalServices: {
40
47
  neuroSanUrl: string | null;
41
48
  };
@@ -48,25 +55,95 @@ interface SettingsStore {
48
55
  readonly updateSettings: (updates: DeepPartial<Settings>) => void;
49
56
  readonly resetSettings: () => void;
50
57
  }
58
+ export declare const LLM_PROVIDER_API_KEY_FIELD: {
59
+ readonly OpenAI: "openai_api_key";
60
+ readonly Anthropic: "anthropic_api_key";
61
+ };
51
62
  /**
52
63
  * Default settings, used on first load and on reset
53
64
  */
54
65
  export declare const DEFAULT_SETTINGS: Settings;
66
+ export declare const APP_SETTINGS_STORAGE_KEY = "app-settings";
67
+ export declare const SESSION_API_KEYS_STORAGE_KEY = "app-settings-api-keys";
68
+ export declare const API_KEYS_TTL_MS: number;
69
+ /**
70
+ * Returns the API key for the given provider if it exists and is not expired, otherwise returns undefined.
71
+ * This helper should be used to retrieve API keys from the settings store, rather than accessing the store directly,
72
+ * to ensure that expired keys are not returned.
73
+ * @param apiKeys Set of API keys stored in the settings store
74
+ * @param provider The LLM provider for which to retrieve the API key
75
+ */
76
+ export declare const getApiKey: (apiKeys: ApiKeys, provider: LLMProvider) => string;
55
77
  /**
56
78
  * The hook that lets apps use the store
57
79
  */
58
80
  export declare const useSettingsStore: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<SettingsStore>, "persist"> & {
59
81
  persist: {
60
- setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, SettingsStore>>) => void;
82
+ setOptions: (options: Partial<import("zustand/middleware").PersistOptions<SettingsStore, {
83
+ settings: {
84
+ appearance: {
85
+ readonly agentIconColor: string;
86
+ readonly agentNodeColor: string;
87
+ readonly autoAgentIconColor: boolean;
88
+ readonly plasmaColor: string;
89
+ readonly rangePalette: PaletteKey;
90
+ readonly useNativeNames: boolean;
91
+ };
92
+ branding: {
93
+ readonly customer: string | null;
94
+ readonly primary: string | null;
95
+ readonly secondary: string | null;
96
+ readonly background: string | null;
97
+ readonly rangePalette: string[] | null;
98
+ readonly iconSuggestion: string | null;
99
+ readonly logoSource: LogoSource;
100
+ };
101
+ behavior: {
102
+ readonly enableZenMode: boolean;
103
+ };
104
+ externalServices: {
105
+ neuroSanUrl: string | null;
106
+ };
107
+ };
108
+ updateSettings: (updates: DeepPartial<Settings>) => void;
109
+ resetSettings: () => void;
110
+ }>>) => void;
61
111
  clearStorage: () => void;
62
112
  rehydrate: () => Promise<void> | void;
63
113
  hasHydrated: () => boolean;
64
114
  onHydrate: (fn: (state: SettingsStore) => void) => () => void;
65
115
  onFinishHydration: (fn: (state: SettingsStore) => void) => () => void;
66
- getOptions: () => Partial<import("zustand/middleware").PersistOptions<SettingsStore, SettingsStore>>;
116
+ getOptions: () => Partial<import("zustand/middleware").PersistOptions<SettingsStore, {
117
+ settings: {
118
+ appearance: {
119
+ readonly agentIconColor: string;
120
+ readonly agentNodeColor: string;
121
+ readonly autoAgentIconColor: boolean;
122
+ readonly plasmaColor: string;
123
+ readonly rangePalette: PaletteKey;
124
+ readonly useNativeNames: boolean;
125
+ };
126
+ branding: {
127
+ readonly customer: string | null;
128
+ readonly primary: string | null;
129
+ readonly secondary: string | null;
130
+ readonly background: string | null;
131
+ readonly rangePalette: string[] | null;
132
+ readonly iconSuggestion: string | null;
133
+ readonly logoSource: LogoSource;
134
+ };
135
+ behavior: {
136
+ readonly enableZenMode: boolean;
137
+ };
138
+ externalServices: {
139
+ neuroSanUrl: string | null;
140
+ };
141
+ };
142
+ updateSettings: (updates: DeepPartial<Settings>) => void;
143
+ resetSettings: () => void;
144
+ }>>;
67
145
  };
68
146
  }>;
69
- export type PaletteKey = keyof typeof PALETTES | "brand";
70
147
  /**
71
148
  * Custom hook to get the current color palette based on user settings.
72
149
  * If the user has selected custom branding, it will return the palette for that.
@@ -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
  }));