@cognizant-ai-lab/ui-common 1.13.0 → 1.14.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.
@@ -12,6 +12,10 @@ export interface AgentFlowProps {
12
12
  readonly agentsInNetwork: ConnectivityInfo[];
13
13
  readonly currentConversations?: AgentConversation[] | null;
14
14
  readonly currentUser?: string;
15
+ /**
16
+ * Extra sly_data entries to merge into each outgoing request. For example, API keys for BYOK.
17
+ */
18
+ readonly extraSlyData?: Record<string, unknown>;
15
19
  readonly id: string;
16
20
  readonly isAwaitingLlm?: boolean;
17
21
  readonly isAgentNetworkDesignerMode?: boolean;
@@ -64,7 +64,7 @@ export const filterNodeEvents = (change, isAgentNetworkDesignerMode) => {
64
64
  return !(change.type === "position" && isAgentNetworkDesignerMode);
65
65
  };
66
66
  //#endregion: Helpers
67
- export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork, currentConversations, currentUser, id, isAgentNetworkDesignerMode, isAwaitingLlm, isEditingNetwork, isStreaming, isTemporaryNetwork, networkDisplayName, networkId, neuroSanURL, onSaveAgent, thoughtBubbleEdges, setIsEditingNetwork, setSelectedNetwork, setThoughtBubbleEdges, }) => {
67
+ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork, currentConversations, currentUser, extraSlyData, id, isAgentNetworkDesignerMode, isAwaitingLlm, isEditingNetwork, isStreaming, isTemporaryNetwork, networkDisplayName, networkId, neuroSanURL, onSaveAgent, thoughtBubbleEdges, setIsEditingNetwork, setSelectedNetwork, setThoughtBubbleEdges, }) => {
68
68
  const theme = useTheme();
69
69
  const { fitView } = useReactFlow();
70
70
  const flowWrapperRef = useRef(null);
@@ -517,5 +517,5 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
517
517
  pt: theme.spacing(4),
518
518
  }, children: [getTitle(), _jsx(ReactFlow, { connectionMode: ConnectionMode.Loose, edgeTypes: edgeTypes, edges: edges, fitView: true, id: `${id}-react-flow`, nodeTypes: nodeTypes, nodes: nodes, nodesDraggable: !isAgentNetworkDesignerMode, onKeyDown: handleNodeKeyDown, onNodeClick: handleNodeClick, onNodesChange: onNodesChange, children: !isAwaitingLlm && (_jsxs(_Fragment, { children: [agentsInNetwork?.length && !isAgentNetworkDesignerMode && !isEditingNetwork
519
519
  ? getLegend()
520
- : null, _jsx(Background, { id: `${id}-background` }), !isAgentNetworkDesignerMode && !isEditingNetwork && getControls(), shouldShowRadialGuides ? getRadialGuides() : null] })) }), _jsx(ThoughtBubbleOverlay, { nodes: nodes, edges: thoughtBubbleEdgesForOverlay, showThoughtBubbles: showThoughtBubbles, isStreaming: isStreaming, onBubbleHoverChange: handleBubbleHoverChange })] }), isTemporaryNetwork && !isAwaitingLlm && (_jsx(NetworkEditorDock, { currentUser: currentUser, id: `${id}-network-editor-dock`, isEditingNetwork: isEditingNetwork, networkId: networkId, neuroSanURL: neuroSanURL, setIsEditingNetwork: setIsEditingNetwork, setSelectedNetwork: setSelectedNetwork, tempNetworks: tempNetworks })), selectedAgent && !isAwaitingLlm && (_jsx(AgentNodeEditor, { agentId: selectedAgent.agentId, agentName: selectedAgent.agentName, initialInstructions: selectedAgent.initialInstructions, initialDescription: selectedAgent.initialDescription, isOpen: isPopupOpen, networkId: networkId, onSaveAgent: onSaveAgent, setIsPopupOpen: setIsPopupOpen }))] }));
520
+ : null, _jsx(Background, { id: `${id}-background` }), !isAgentNetworkDesignerMode && !isEditingNetwork && getControls(), shouldShowRadialGuides ? getRadialGuides() : null] })) }), _jsx(ThoughtBubbleOverlay, { nodes: nodes, edges: thoughtBubbleEdgesForOverlay, showThoughtBubbles: showThoughtBubbles, isStreaming: isStreaming, onBubbleHoverChange: handleBubbleHoverChange })] }), isTemporaryNetwork && !isAwaitingLlm && (_jsx(NetworkEditorDock, { currentUser: currentUser, extraSlyData: extraSlyData, id: `${id}-network-editor-dock`, isEditingNetwork: isEditingNetwork, networkId: networkId, neuroSanURL: neuroSanURL, setIsEditingNetwork: setIsEditingNetwork, setSelectedNetwork: setSelectedNetwork, tempNetworks: tempNetworks })), selectedAgent && !isAwaitingLlm && (_jsx(AgentNodeEditor, { agentId: selectedAgent.agentId, agentName: selectedAgent.agentName, initialInstructions: selectedAgent.initialInstructions, initialDescription: selectedAgent.initialDescription, isOpen: isPopupOpen, networkId: networkId, onSaveAgent: onSaveAgent, setIsPopupOpen: setIsPopupOpen }))] }));
521
521
  };
@@ -1,5 +1,5 @@
1
1
  // Timeout in milliseconds for the network designer streaming response.
2
- export const STREAM_TIMEOUT_MS = 3 * 60 * 1000;
2
+ export const STREAM_TIMEOUT_MS = 10 * 60 * 1000;
3
3
  // How long the dock's status banner stays visible before auto-dismissing. Error banners persist until dismissed.
4
4
  // Exported for tests.
5
5
  export const BANNER_AUTO_DISMISS_MS = 5_000;
@@ -2,6 +2,10 @@ import { FC } from "react";
2
2
  import { TemporaryNetwork } from "../../../state/TemporaryNetworks.js";
3
3
  export type NetworkEditorDockProps = {
4
4
  readonly currentUser: string;
5
+ /**
6
+ * Extra sly_data entries to merge into each outgoing request. For example, API keys for BYOK.
7
+ */
8
+ readonly extraSlyData?: Record<string, unknown>;
5
9
  readonly id: string;
6
10
  readonly isEditingNetwork: boolean;
7
11
  readonly networkId: string;
@@ -27,7 +27,7 @@ const PROMPT_PLACEHOLDER = "Describe a change to the network";
27
27
  * Implements the dock that appears at the bottom of the screen when the user is editing a network. Allows user to
28
28
  * enter plain-language instructions for modifying the overall network.
29
29
  */
30
- export const NetworkEditorDock = ({ neuroSanURL, currentUser, id, isEditingNetwork, networkId, setIsEditingNetwork, setSelectedNetwork, tempNetworks, }) => {
30
+ export const NetworkEditorDock = ({ neuroSanURL, currentUser, extraSlyData, id, isEditingNetwork, networkId, setIsEditingNetwork, setSelectedNetwork, tempNetworks, }) => {
31
31
  const theme = useTheme();
32
32
  // Inline status banner shown above the dock header after an "apply" succeeds, is canceled, or fails.
33
33
  const [banner, setBanner] = useState(null);
@@ -141,11 +141,12 @@ export const NetworkEditorDock = ({ neuroSanURL, currentUser, id, isEditingNetwo
141
141
  const converted = convertReservationsToNetworks(reservations, networkHocon, definitionFromMessage ?? currentDefinition, networkName);
142
142
  newNetworks = mergeNetworks(newNetworks, converted);
143
143
  }, null, {
144
+ ...extraSlyData,
144
145
  [AGENT_NETWORK_DEFINITION_KEY]: currentDefinition,
145
146
  ...(agentNetworkName ? { [AGENT_NETWORK_NAME_KEY]: agentNetworkName } : {}),
146
147
  }, currentUser, StreamingUnit.Line);
147
148
  return newNetworks;
148
- }, [currentUser, neuroSanURL]);
149
+ }, [currentUser, extraSlyData, neuroSanURL]);
149
150
  const handleApply = useCallback(async () => {
150
151
  const readyToApplyEdit = Boolean(dockPrompt.trim() && neuroSanURL && currentUser);
151
152
  if (!readyToApplyEdit) {
@@ -178,18 +178,6 @@ export const MultiAgentAccelerator = ({ defaultNeuroSanUrl, username, }) => {
178
178
  const designerTempNetwork = designerNetworkName
179
179
  ? temporaryNetworks.find((n) => n.agentNetworkName === designerNetworkName)
180
180
  : undefined;
181
- /**
182
- * Builds the API keys object to be sent as extraSlyData with each request, based on the LLM providers required
183
- * by the currently selected network. Only includes keys for providers that are required.
184
- */
185
- const getApiKeys = () => ({
186
- llm_config: Object.fromEntries([...supportedByokProviders]
187
- .map((provider) => [
188
- LLM_PROVIDER_API_KEY_FIELD[provider],
189
- getApiKey(apiKeys, provider),
190
- ])
191
- .filter((entry) => Boolean(entry[1]))),
192
- });
193
181
  /**
194
182
  * Builds the extraSlyData object to be sent with each request, including information for Agent Network Designer
195
183
  * and (if required) API keys for LLM providers.
@@ -220,12 +208,26 @@ export const MultiAgentAccelerator = ({ defaultNeuroSanUrl, username, }) => {
220
208
  // Build base extraSlyData
221
209
  const baseExtraSlyData = buildExtraSlyData();
222
210
  // Add API keys to extraSlyData if needed, merging with baseExtraSlyData if it exists
223
- const extraSlyData = anyApiKeysRequired || baseExtraSlyData
224
- ? {
225
- ...baseExtraSlyData,
226
- ...(anyApiKeysRequired ? getApiKeys() : {}),
227
- }
228
- : undefined;
211
+ const extraSlyData = useMemo(() => {
212
+ /**
213
+ * Builds the API keys object to be sent as extraSlyData with each request, based on the LLM providers required
214
+ * by the currently selected network. Only includes keys for providers that are required.
215
+ */
216
+ const apiKeysSlyData = {
217
+ llm_config: Object.fromEntries([...supportedByokProviders]
218
+ .map((provider) => [
219
+ LLM_PROVIDER_API_KEY_FIELD[provider],
220
+ getApiKey(apiKeys, provider),
221
+ ])
222
+ .filter((entry) => Boolean(entry[1]))),
223
+ };
224
+ return anyApiKeysRequired || baseExtraSlyData
225
+ ? {
226
+ ...baseExtraSlyData,
227
+ ...(anyApiKeysRequired ? apiKeysSlyData : {}),
228
+ }
229
+ : undefined;
230
+ }, [anyApiKeysRequired, apiKeys, baseExtraSlyData, supportedByokProviders]);
229
231
  // Handle external stop button click - stops streaming and exits zen mode
230
232
  const handleExternalStop = useCallback(() => {
231
233
  chatRef.current?.handleStop();
@@ -464,7 +466,7 @@ export const MultiAgentAccelerator = ({ defaultNeuroSanUrl, username, }) => {
464
466
  */
465
467
  const onSaveAgent = useCallback(async (agentName, updated, agentNetworkName, signal) => {
466
468
  try {
467
- const newNetworks = await streamNetworkDesignerUpsert(neuroSanURL, signal, agentName, updated, agentNetworkName, username);
469
+ const newNetworks = await streamNetworkDesignerUpsert(neuroSanURL, signal, agentName, updated, agentNetworkName, username, extraSlyData);
468
470
  if (newNetworks.length === 0) {
469
471
  sendNotification(NotificationType.error, `Failed to update network "${agentName}".`, "The network designer did not return a reservation. Please try again.");
470
472
  return;
@@ -486,7 +488,7 @@ export const MultiAgentAccelerator = ({ defaultNeuroSanUrl, username, }) => {
486
488
  catch (e) {
487
489
  notifySaveError(agentName, e);
488
490
  }
489
- }, [neuroSanURL, username, selectedNetwork]);
491
+ }, [neuroSanURL, username, extraSlyData, selectedNetwork]);
490
492
  const onStreamingStarted = useCallback(() => {
491
493
  // Reset agent counts
492
494
  setAgentCounts(new Map());
@@ -586,7 +588,7 @@ export const MultiAgentAccelerator = ({ defaultNeuroSanUrl, username, }) => {
586
588
  width: "100%",
587
589
  height: "100%",
588
590
  margin: "0 auto",
589
- }, children: _jsx(AgentFlow, { agentCounts: agentCounts, agentsInNetwork: agentsInNetwork, agentIconSuggestions: agentIconSuggestions, id: "multi-agent-accelerator-agent-flow", currentConversations: currentConversations, currentUser: username, isAwaitingLlm: isAwaitingLlm, isEditingNetwork: isEditingNetwork, isStreaming: isStreaming, isTemporaryNetwork: isSelectedNetworkTemporary, networkDisplayName: networkDisplayName || "", networkId: isSelectedNetworkTemporary ? selectedNetwork : "", neuroSanURL: neuroSanURL, onSaveAgent: onSaveAgent, setIsEditingNetwork: setIsEditingNetwork, thoughtBubbleEdges: thoughtBubbleEdges, setSelectedNetwork: changeSelectedNetwork, setThoughtBubbleEdges: setThoughtBubbleEdges }, "multi-agent-accelerator-agent-flow") }) }) }));
591
+ }, children: _jsx(AgentFlow, { agentCounts: agentCounts, agentsInNetwork: agentsInNetwork, agentIconSuggestions: agentIconSuggestions, extraSlyData: extraSlyData, id: "multi-agent-accelerator-agent-flow", currentConversations: currentConversations, currentUser: username, isAwaitingLlm: isAwaitingLlm, isEditingNetwork: isEditingNetwork, isStreaming: isStreaming, isTemporaryNetwork: isSelectedNetworkTemporary, networkDisplayName: networkDisplayName || "", networkId: isSelectedNetworkTemporary ? selectedNetwork : "", neuroSanURL: neuroSanURL, onSaveAgent: onSaveAgent, setIsEditingNetwork: setIsEditingNetwork, thoughtBubbleEdges: thoughtBubbleEdges, setSelectedNetwork: changeSelectedNetwork, setThoughtBubbleEdges: setThoughtBubbleEdges }, "multi-agent-accelerator-agent-flow") }) }) }));
590
592
  const getRightPanel = () => (_jsx(Panel, { collapsible: true, defaultSize: "35%", id: "multi-agent-accelerator-right-panel", minSize: "15%", panelRef: rightPanelRef, children: _jsx(ChatCommon, { agentPlaceholders: {
591
593
  [AGENT_NETWORK_DESIGNER_ID]: "Describe in plain language the network you would like to build.",
592
594
  }, currentUser: username, customAgentGreetings: {
@@ -69,4 +69,4 @@ export declare const notifySaveError: (agentName: string, e: unknown) => void;
69
69
  * Returns the single updated network as a one-element list (empty if the designer returned
70
70
  * no reservation).
71
71
  */
72
- export declare const streamNetworkDesignerUpsert: (neuroSanURL: string, signal: AbortSignal, frontman: string, networkDef: AgentNetworkDefinitionEntry[], agentNetworkName: string | undefined, username: string) => Promise<TemporaryNetwork[]>;
72
+ export declare const streamNetworkDesignerUpsert: (neuroSanURL: string, signal: AbortSignal, frontman: string, networkDef: AgentNetworkDefinitionEntry[], agentNetworkName: string | undefined, username: string, extraSlyData?: Record<string, unknown>) => Promise<TemporaryNetwork[]>;
@@ -132,12 +132,12 @@ export const notifySaveError = (agentName, e) => {
132
132
  * Returns the single updated network as a one-element list (empty if the designer returned
133
133
  * no reservation).
134
134
  */
135
- export const streamNetworkDesignerUpsert = async (neuroSanURL, signal, frontman, networkDef, agentNetworkName, username) => {
135
+ export const streamNetworkDesignerUpsert = async (neuroSanURL, signal, frontman, networkDef, agentNetworkName, username, extraSlyData = {}) => {
136
136
  let newNetworks = [];
137
137
  await sendNetworkDesignerRequest(neuroSanURL, signal, frontman, networkDef, agentNetworkName, username, (chunk) => {
138
138
  // There is only one network. The designer echoes it across streamed chunks. Merge by name so the
139
139
  // repeated echoes collapse into that single entry rather than appending duplicates.
140
140
  newNetworks = collectNetworkFromChunk(chunk, networkDef, newNetworks);
141
- });
141
+ }, extraSlyData);
142
142
  return newNetworks;
143
143
  };
@@ -76,4 +76,4 @@ export declare const getAgentFunction: (url: string, agent: string, userId: stri
76
76
  * existing network or adding a fresh one. Calls `onChunk` for each line received; callers are
77
77
  * responsible for parsing reservations / networks out of each chunk.
78
78
  */
79
- export declare const sendNetworkDesignerRequest: (url: string, signal: AbortSignal, agentName: string, updated: AgentNetworkDefinitionEntry[], agentNetworkName: string | undefined, currentUser: string, onChunk: (chunk: string) => void) => Promise<void>;
79
+ export declare const sendNetworkDesignerRequest: (url: string, signal: AbortSignal, agentName: string, updated: AgentNetworkDefinitionEntry[], agentNetworkName: string | undefined, currentUser: string, onChunk: (chunk: string) => void, extraSlyData?: Record<string, unknown>) => Promise<void>;
@@ -188,10 +188,11 @@ export const getAgentFunction = async (url, agent, userId) => {
188
188
  * existing network or adding a fresh one. Calls `onChunk` for each line received; callers are
189
189
  * responsible for parsing reservations / networks out of each chunk.
190
190
  */
191
- export const sendNetworkDesignerRequest = async (url, signal, agentName, updated, agentNetworkName, currentUser, onChunk) => {
191
+ export const sendNetworkDesignerRequest = async (url, signal, agentName, updated, agentNetworkName, currentUser, onChunk, extraSlyData = {}) => {
192
192
  await sendChatQuery(url, signal,
193
193
  // Shouldn't have to pass a user message, but API behaves differently without it
194
194
  `Update instructions for agent "${agentName}"`, AGENT_NETWORK_DESIGNER_ID, onChunk, null, {
195
+ ...extraSlyData,
195
196
  [AGENT_NETWORK_DEFINITION_KEY]: updated,
196
197
  // Use the backend's canonical name, not the local UUID-based key.
197
198
  ...(agentNetworkName ? { [AGENT_NETWORK_NAME_KEY]: agentNetworkName } : {}),
@@ -68,7 +68,7 @@ export const APP_SETTINGS_STORAGE_KEY = "app-settings";
68
68
  export const SESSION_API_KEYS_STORAGE_KEY = "app-settings-api-keys";
69
69
  // TTL for API keys in sessionStorage. After this time, the keys will be cleared from sessionStorage.
70
70
  // This is a backstop for cases where users rarely close their browser or tabs
71
- export const API_KEYS_TTL_MS = 2 * 24 * 60 * 60 * 1000; // 2 days
71
+ export const API_KEYS_TTL_MS = 7 * 24 * 60 * 60 * 1000;
72
72
  //#endregion Constants
73
73
  const hasPersistedSettings = (state) => typeof state === "object" &&
74
74
  state !== null &&