@cognizant-ai-lab/ui-common 1.9.0 → 1.11.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 (70) hide show
  1. package/dist/components/AgentChat/ChatCommon/ChatCommon.js +32 -10
  2. package/dist/components/AgentChat/ChatCommon/Const.d.ts +1 -0
  3. package/dist/components/AgentChat/ChatCommon/Const.js +2 -0
  4. package/dist/components/AgentChat/ChatCommon/SlyDataDialog.d.ts +29 -0
  5. package/dist/components/AgentChat/ChatCommon/SlyDataDialog.js +150 -0
  6. package/dist/components/AgentChat/ChatCommon/Thinking.js +2 -2
  7. package/dist/components/AgentChat/Common/LlmChatButton.d.ts +4 -6
  8. package/dist/components/AgentChat/Common/LlmChatButton.js +0 -2
  9. package/dist/components/AgentChat/Common/Utils.d.ts +0 -11
  10. package/dist/components/AgentChat/Common/Utils.js +0 -16
  11. package/dist/components/Common/ConfirmationModal.d.ts +3 -2
  12. package/dist/components/Common/Footer.js +4 -0
  13. package/dist/components/Common/Navbar.d.ts +2 -1
  14. package/dist/components/Common/Navbar.js +3 -3
  15. package/dist/components/ErrorPage/ErrorPage.js +4 -4
  16. package/dist/components/MultiAgentAccelerator/AgentFlow/AgentFlow.d.ts +7 -7
  17. package/dist/components/MultiAgentAccelerator/AgentFlow/AgentFlow.js +161 -376
  18. package/dist/components/MultiAgentAccelerator/AgentFlow/AgentNode.js +7 -5
  19. package/dist/components/MultiAgentAccelerator/AgentFlow/GraphLayouts.js +10 -7
  20. package/dist/components/MultiAgentAccelerator/AgentFlow/GraphStructure.d.ts +1 -1
  21. package/dist/components/MultiAgentAccelerator/Editor/AgentNodeEditor.d.ts +24 -0
  22. package/dist/components/MultiAgentAccelerator/Editor/AgentNodeEditor.js +128 -0
  23. package/dist/components/MultiAgentAccelerator/Editor/NetworkEditorDock.d.ts +21 -0
  24. package/dist/components/MultiAgentAccelerator/Editor/NetworkEditorDock.js +305 -0
  25. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.js +112 -116
  26. package/dist/components/MultiAgentAccelerator/NeuroSanStudioCallout.d.ts +2 -0
  27. package/dist/components/MultiAgentAccelerator/NeuroSanStudioCallout.js +38 -0
  28. package/dist/components/MultiAgentAccelerator/PanelSeparator.d.ts +5 -0
  29. package/dist/components/MultiAgentAccelerator/PanelSeparator.js +46 -0
  30. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.d.ts +2 -0
  31. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.js +23 -31
  32. package/dist/components/MultiAgentAccelerator/Sidebar/Sidebar.d.ts +0 -2
  33. package/dist/components/MultiAgentAccelerator/Sidebar/Sidebar.js +11 -9
  34. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.d.ts +2 -2
  35. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.js +13 -13
  36. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.d.ts +3 -17
  37. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.js +17 -40
  38. package/dist/components/MultiAgentAccelerator/Tour/MainTourSteps.js +10 -8
  39. package/dist/components/MultiAgentAccelerator/const.d.ts +12 -11
  40. package/dist/components/MultiAgentAccelerator/const.js +24 -22
  41. package/dist/components/Settings/ApiKeyErrorBanner.d.ts +22 -0
  42. package/dist/components/Settings/ApiKeyErrorBanner.js +26 -0
  43. package/dist/components/Settings/ApiKeyInput.d.ts +5 -2
  44. package/dist/components/Settings/ApiKeyInput.js +10 -4
  45. package/dist/components/Settings/SettingsDialog.js +22 -5
  46. package/dist/const.d.ts +0 -1
  47. package/dist/const.js +0 -1
  48. package/dist/controller/llm/Providers.d.ts +19 -2
  49. package/dist/controller/llm/Providers.js +45 -31
  50. package/dist/state/Announcements.d.ts +24 -0
  51. package/dist/state/Announcements.js +29 -0
  52. package/dist/state/ChatHistory.d.ts +10 -1
  53. package/dist/state/ChatHistory.js +8 -0
  54. package/dist/state/Environment.d.ts +2 -0
  55. package/dist/state/Environment.js +2 -0
  56. package/dist/state/Settings.d.ts +14 -0
  57. package/dist/state/Settings.js +6 -2
  58. package/dist/state/TemporaryNetworks.js +12 -21
  59. package/dist/tsconfig.build.tsbuildinfo +1 -1
  60. package/dist/utils/AgentName.d.ts +17 -0
  61. package/dist/utils/AgentName.js +46 -0
  62. package/dist/utils/Authentication.d.ts +7 -0
  63. package/dist/utils/Authentication.js +19 -5
  64. package/dist/utils/SlyData.d.ts +56 -0
  65. package/dist/utils/SlyData.js +106 -0
  66. package/package.json +7 -6
  67. package/dist/components/MultiAgentAccelerator/AgentNodePopup.d.ts +0 -30
  68. package/dist/components/MultiAgentAccelerator/AgentNodePopup.js +0 -80
  69. package/dist/components/MultiAgentAccelerator/Sidebar/ImportNetworkModal.d.ts +0 -67
  70. package/dist/components/MultiAgentAccelerator/Sidebar/ImportNetworkModal.js +0 -585
@@ -16,76 +16,35 @@ limitations under the License.
16
16
  */
17
17
  import AdjustRoundedIcon from "@mui/icons-material/AdjustRounded";
18
18
  import ChatBubbleOutlinedIcon from "@mui/icons-material/ChatBubbleOutlined";
19
- import CloseIcon from "@mui/icons-material/Close";
20
19
  import EditIcon from "@mui/icons-material/Edit";
21
20
  import HubOutlinedIcon from "@mui/icons-material/HubOutlined";
22
21
  import ScatterPlotOutlinedIcon from "@mui/icons-material/ScatterPlotOutlined";
23
- import Backdrop from "@mui/material/Backdrop";
24
22
  import Box from "@mui/material/Box";
25
23
  import Button from "@mui/material/Button";
26
- import CircularProgress from "@mui/material/CircularProgress";
27
- import IconButton from "@mui/material/IconButton";
28
- import Paper from "@mui/material/Paper";
29
24
  import { alpha, useTheme } from "@mui/material/styles";
30
- import TextField from "@mui/material/TextField";
31
25
  import ToggleButton from "@mui/material/ToggleButton";
32
26
  import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
33
27
  import Tooltip from "@mui/material/Tooltip";
34
28
  import Typography from "@mui/material/Typography";
35
29
  import { applyNodeChanges, Background, ConnectionMode, ControlButton, Controls, ReactFlow, useReactFlow, useStore, } from "@xyflow/react";
36
- import { useCallback, useEffect, useMemo, useRef, useState } from "react";
30
+ import { useCallback, useEffect, useMemo, useRef, useState, } from "react";
37
31
  import { AgentNode, NODE_HEIGHT, NODE_WIDTH } from "./AgentNode.js";
38
- import { AGENT_NETWORK_DEFINITION_KEY, AGENT_NETWORK_DESIGNER_ID, AGENT_NETWORK_NAME_KEY, BASE_RADIUS, DEFAULT_FRONTMAN_X_POS, DEFAULT_FRONTMAN_Y_POS, LEVEL_SPACING, } from "../const.js";
32
+ import { BASE_RADIUS, DEFAULT_FRONTMAN_X_POS, DEFAULT_FRONTMAN_Y_POS, LEVEL_SPACING, } from "../const.js";
39
33
  import { addThoughtBubbleEdge, layoutLinear, layoutRadial } from "./GraphLayouts.js";
40
34
  import { PlasmaEdge } from "./PlasmaEdge.js";
41
- import { sendChatQuery } from "../../../controller/agent/Agent.js";
42
- import { StreamingUnit } from "../../../controller/llm/LlmChat.js";
43
- import { useAgentChatHistoryStore } from "../../../state/ChatHistory.js";
44
35
  import { usePalette, useSettingsStore } from "../../../state/Settings.js";
45
36
  import { useTempNetworksStore } from "../../../state/TemporaryNetworks.js";
46
37
  import { getZIndex } from "../../../utils/zIndexLayers.js";
47
- import { chatMessageFromChunk } from "../../AgentChat/Common/Utils.js";
48
- import { MUIAlert } from "../../Common/MUIAlert.js";
49
- import { NotificationType, sendNotification } from "../../Common/notification.js";
50
- import { AgentNodePopup } from "../AgentNodePopup.js";
51
- import { convertReservationsToNetworks, extractNetworkHocon, extractReservations, isEditableAgent, mergeNetworks, } from "../TemporaryNetworks.js";
38
+ import { AgentNodeEditor } from "../Editor/AgentNodeEditor.js";
39
+ import { NetworkEditorDock } from "../Editor/NetworkEditorDock.js";
40
+ import { isEditableAgent } from "../TemporaryNetworks.js";
52
41
  import { ThoughtBubbleEdge } from "../ThoughtBubbles/ThoughtBubbleEdge.js";
53
42
  import { ThoughtBubbleOverlay } from "../ThoughtBubbles/ThoughtBubbleOverlay.js";
54
43
  //#endregion: Types
55
44
  //#region: Constants
56
- // Timeout for thought bubbles is set to 10 seconds
57
45
  const THOUGHT_BUBBLE_TIMEOUT_MS = 10_000;
58
- // How long the dock's status banner stays visible before auto-dismissing. Error banners persist until dismissed.
59
- // Exported for tests.
60
- export const DOCK_BANNER_AUTO_DISMISS_MS = 5_000;
61
- const DOCK_PROMPT_PLACEHOLDER = "Describe a change to the network";
62
46
  //#endregion: Constants
63
47
  //#region: Helpers
64
- /**
65
- * Streams the Agent Network Designer endpoint with a natural-language prompt and the current
66
- * network definition, collecting any returned reservations.
67
- */
68
- const streamNetworkDesignerPrompt = async (neuroSanURL, signal, userPrompt, currentDefinition, agentNetworkName, currentUser) => {
69
- let newNetworks = [];
70
- await sendChatQuery(neuroSanURL, signal, userPrompt, AGENT_NETWORK_DESIGNER_ID, (chunk) => {
71
- const chatMessage = chatMessageFromChunk(chunk);
72
- if (!chatMessage)
73
- return;
74
- const reservations = extractReservations(chatMessage);
75
- if (reservations.length === 0)
76
- return;
77
- const networkHocon = extractNetworkHocon(chatMessage);
78
- const agentNetworkNameFromMessage = chatMessage.sly_data?.[AGENT_NETWORK_NAME_KEY];
79
- const networkName = agentNetworkName ?? agentNetworkNameFromMessage;
80
- const definitionFromMessage = chatMessage.sly_data?.[AGENT_NETWORK_DEFINITION_KEY];
81
- const converted = convertReservationsToNetworks(reservations, networkHocon, definitionFromMessage ?? currentDefinition, networkName);
82
- newNetworks = mergeNetworks(newNetworks, converted);
83
- }, null, {
84
- [AGENT_NETWORK_DEFINITION_KEY]: currentDefinition,
85
- ...(agentNetworkName ? { [AGENT_NETWORK_NAME_KEY]: agentNetworkName } : {}),
86
- }, currentUser, StreamingUnit.Line);
87
- return newNetworks;
88
- };
89
48
  /**
90
49
  * Filters node events based on the current mode. Don't allow any topological-modifying events (adding, deleting nodes)
91
50
  * and in Agent Network Designer mode, don't allow dragging nodes (position changes) either.
@@ -102,23 +61,81 @@ export const filterNodeEvents = (change, isAgentNetworkDesignerMode) => {
102
61
  return !(change.type === "position" && isAgentNetworkDesignerMode);
103
62
  };
104
63
  //#endregion: Helpers
105
- export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork, currentConversations, currentUser, id, isAgentNetworkDesignerMode, isAwaitingLlm, isEditMode, isStreaming, isSelectedNetworkTemporary: isTemporaryNetwork, networkDisplayName, networkId, neuroSanURL, onEnterEditMode, onNetworkReplaced, onExitEditMode, onSaveAgent, thoughtBubbleEdges, setThoughtBubbleEdges, }) => {
64
+ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork, currentConversations, currentUser, id, isAgentNetworkDesignerMode, isAwaitingLlm, isEditingNetwork, isStreaming, isTemporaryNetwork, networkDisplayName, networkId, neuroSanURL, onSaveAgent, thoughtBubbleEdges, setIsEditingNetwork, setSelectedNetwork, setThoughtBubbleEdges, }) => {
106
65
  const theme = useTheme();
107
66
  const { fitView } = useReactFlow();
108
- const handleResize = useCallback(() => {
109
- void fitView(); // Adjusts the view to fit after resizing
67
+ const flowWrapperRef = useRef(null);
68
+ const fitViewFrameRef = useRef(null);
69
+ const scheduleFitView = useCallback(() => {
70
+ if (fitViewFrameRef.current !== null) {
71
+ window.cancelAnimationFrame(fitViewFrameRef.current);
72
+ }
73
+ fitViewFrameRef.current = window.requestAnimationFrame(() => {
74
+ fitViewFrameRef.current = null;
75
+ void fitView();
76
+ });
110
77
  }, [fitView]);
111
78
  useEffect(() => {
112
- window.addEventListener("resize", handleResize);
113
- return () => window.removeEventListener("resize", handleResize);
114
- }, [handleResize]);
115
- const [layout, setLayout] = useState("radial");
116
- const [coloringOption, setColoringOption] = useState("depth");
117
- const [enableRadialGuides, setEnableRadialGuides] = useState(true);
118
- const [showThoughtBubbles, setShowThoughtBubbles] = useState(true);
79
+ return () => {
80
+ if (fitViewFrameRef.current !== null) {
81
+ window.cancelAnimationFrame(fitViewFrameRef.current);
82
+ fitViewFrameRef.current = null;
83
+ }
84
+ };
85
+ }, []);
86
+ /**
87
+ * Effect to observe the flow wrapper's size and trigger fitView when it changes.
88
+ * This ensures that the flow view adjusts to the container size. If the user resizes that window itself,
89
+ * that will also cause the container size to change so this event will catch it.
90
+ */
91
+ useEffect(() => {
92
+ if (!flowWrapperRef.current)
93
+ return undefined;
94
+ const resizeObserver = new ResizeObserver(([entry]) => {
95
+ if (entry.contentRect.width > 0 && entry.contentRect.height > 0) {
96
+ scheduleFitView();
97
+ }
98
+ });
99
+ resizeObserver.observe(flowWrapperRef.current);
100
+ return () => {
101
+ resizeObserver.disconnect();
102
+ };
103
+ }, [scheduleFitView]);
104
+ const updateSettings = useSettingsStore((state) => state.updateSettings);
105
+ const layout = useSettingsStore((state) => state.settings.appearance.layout);
106
+ const setLayout = (newLayout) => {
107
+ updateSettings({
108
+ appearance: {
109
+ layout: newLayout,
110
+ },
111
+ });
112
+ };
113
+ const graphColoringOption = useSettingsStore((state) => state.settings.appearance.graphColoringOption);
114
+ const setGraphColoringOption = (newValue) => {
115
+ updateSettings({
116
+ appearance: {
117
+ graphColoringOption: newValue,
118
+ },
119
+ });
120
+ };
121
+ const showRadialGuides = useSettingsStore((state) => state.settings.appearance.showRadialGuides);
122
+ const setShowRadialGuides = (newValue) => {
123
+ updateSettings({
124
+ appearance: {
125
+ showRadialGuides: newValue,
126
+ },
127
+ });
128
+ };
129
+ const showThoughtBubbles = useSettingsStore((state) => state.settings.appearance.showThoughtBubbles);
130
+ const setShowThoughtBubbles = (newValue) => {
131
+ updateSettings({
132
+ appearance: {
133
+ showThoughtBubbles: newValue,
134
+ },
135
+ });
136
+ };
119
137
  // Read temporary networks to find agent_network_definition for the currently selected network.
120
138
  const tempNetworks = useTempNetworksStore((state) => state.tempNetworks);
121
- const updateTempNetworkDefinition = useTempNetworksStore((state) => state.updateTempNetworkDefinition);
122
139
  // Track conversation IDs we've already processed to prevent re-adding after expiry
123
140
  const processedConversationIdsRef = useRef(new Set());
124
141
  // Track which bubble is currently being hovered
@@ -204,7 +221,7 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
204
221
  }, 1000);
205
222
  return () => clearInterval(cleanupInterval);
206
223
  }, [setThoughtBubbleEdges]); // mount/unmount only
207
- const isHeatmap = coloringOption === "heatmap";
224
+ const isHeatmap = graphColoringOption === "heatmap";
208
225
  const palette = usePalette();
209
226
  // Merge agents from active thought bubbles with agentsInNetwork for layout
210
227
  // This ensures bubble edges persist even when agents disappear from the network
@@ -229,29 +246,36 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
229
246
  }, [agentsInNetwork, bubbleAgentIds]);
230
247
  // Create the flow layout depending on user preference
231
248
  // Memoize layoutResult so it only recalculates when relevant data changes
232
- const layoutResult = useMemo(() => layout === "linear"
233
- ? layoutLinear({
234
- agentCounts: isHeatmap ? agentCounts : undefined,
235
- agentIconSuggestions,
236
- agentsInNetwork: mergedAgentsInNetwork,
237
- currentConversations,
238
- isAgentNetworkDesignerMode,
239
- isAwaitingLlm,
240
- isTemporaryNetwork,
241
- thoughtBubbleEdges,
242
- useNativeNames,
243
- })
244
- : layoutRadial({
245
- agentCounts: isHeatmap ? agentCounts : undefined,
246
- agentIconSuggestions,
247
- agentsInNetwork: mergedAgentsInNetwork,
248
- currentConversations,
249
- isAgentNetworkDesignerMode,
250
- isAwaitingLlm,
251
- isTemporaryNetwork,
252
- thoughtBubbleEdges,
253
- useNativeNames,
254
- }), [
249
+ const layoutResult = useMemo(() => {
250
+ if (mergedAgentsInNetwork.length > 0) {
251
+ return layout === "linear"
252
+ ? layoutLinear({
253
+ agentCounts: isHeatmap ? agentCounts : undefined,
254
+ agentIconSuggestions,
255
+ agentsInNetwork: mergedAgentsInNetwork,
256
+ currentConversations,
257
+ isAgentNetworkDesignerMode,
258
+ isAwaitingLlm,
259
+ isTemporaryNetwork,
260
+ thoughtBubbleEdges,
261
+ useNativeNames,
262
+ })
263
+ : layoutRadial({
264
+ agentCounts: isHeatmap ? agentCounts : undefined,
265
+ agentIconSuggestions,
266
+ agentsInNetwork: mergedAgentsInNetwork,
267
+ currentConversations,
268
+ isAgentNetworkDesignerMode,
269
+ isAwaitingLlm,
270
+ isTemporaryNetwork,
271
+ thoughtBubbleEdges,
272
+ useNativeNames,
273
+ });
274
+ }
275
+ else {
276
+ return { nodes: [], edges: [] };
277
+ }
278
+ }, [
255
279
  agentCounts,
256
280
  agentIconSuggestions,
257
281
  currentConversations,
@@ -272,214 +296,46 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
272
296
  // Track which node the user clicked on so we can open the popup
273
297
  const [selectedAgent, setSelectedAgent] = useState(null);
274
298
  const [isPopupOpen, setIsPopupOpen] = useState(false);
275
- // True, while the agent-edit request is in-flight so we can disable the Save button.
276
- const [isSavingAgent, setIsSavingAgent] = useState(false);
277
- // AbortController for the in-flight save request — stored in a ref so handlePopupClose can cancel it.
278
- const saveAbortControllerRef = useRef(null);
279
- // Dock (edit-mode prompt bar) state
280
- const [dockPrompt, setDockPrompt] = useState("");
281
- const [isDockStreaming, setIsDockStreaming] = useState(false);
282
- const dockAbortControllerRef = useRef(null);
283
- // Stop-confirm overlay state: null = not shown, "confirming" = abort dialog open.
284
- const [stopState, setStopState] = useState(null);
285
- // Inline status banner shown above the dock header after an "apply" succeeds, is canceled, or fails.
286
- const [dockBanner, setDockBanner] = useState(null);
287
- const bannerTimeoutRef = useRef(null);
288
- // Clear the banner auto-dismiss timer on unmount.
289
- useEffect(() => {
290
- return () => {
291
- clearTimeout(bannerTimeoutRef.current);
292
- };
293
- }, []);
294
- const handleDismissBanner = useCallback(() => {
295
- clearTimeout(bannerTimeoutRef.current);
296
- setDockBanner(null);
297
- }, []);
298
- // Show a dock banner. Success/cancel banners auto-dismiss; error banners persist until dismissed.
299
- const showDockBanner = useCallback((banner) => {
300
- clearTimeout(bannerTimeoutRef.current);
301
- setDockBanner(banner);
302
- if (banner.severity !== "error") {
303
- bannerTimeoutRef.current = setTimeout(() => setDockBanner(null), DOCK_BANNER_AUTO_DISMISS_MS);
304
- }
305
- }, []);
306
- const handleStopClick = useCallback(() => {
307
- setStopState("confirming");
308
- }, []);
309
- const handleKeepApplying = useCallback(() => {
310
- setStopState(null);
311
- }, []);
312
- const handleStopAndDiscard = useCallback(() => {
313
- dockAbortControllerRef.current?.abort();
314
- dockAbortControllerRef.current = null;
315
- setStopState(null);
316
- showDockBanner({
317
- severity: "info",
318
- title: "Applying cancelled.",
319
- detail: "Nothing was changed. Your prompt is restored below.",
320
- });
321
- }, [showDockBanner]);
322
- const handleNodeClick = useCallback((_event, node) => {
299
+ const openNodeEditor = useCallback((node) => {
323
300
  // Popup is only available for temporary networks.
324
301
  if (!isTemporaryNetwork)
325
302
  return;
326
303
  // Only llm_agent nodes support instructions/description editing.
327
304
  if (!isEditableAgent(node.data.displayAs))
328
305
  return;
329
- // Find the clicked agent's existing instructions and description from the temp network definition.
306
+ // Find the agent's existing instructions and description from the temp network definition.
330
307
  const currentTempNetwork = networkId
331
308
  ? tempNetworks.find((n) => n.agentInfo.agent_name === networkId)
332
309
  : undefined;
333
- const found = (currentTempNetwork?.agentNetworkDefinition ?? []).find((e) => e.origin === node.id);
310
+ const currentAgentDefinition = currentTempNetwork?.agentNetworkDefinition?.find((e) => e.origin === node.id);
334
311
  setSelectedAgent({
335
312
  agentId: node.id,
336
313
  agentName: node.data.agentName,
337
- initialInstructions: found?.instructions ?? "",
338
- initialDescription: found?.description ?? "",
314
+ initialInstructions: currentAgentDefinition?.instructions ?? "",
315
+ initialDescription: currentAgentDefinition?.description ?? "",
339
316
  });
340
317
  setIsPopupOpen(true);
341
318
  }, [tempNetworks, isTemporaryNetwork, networkId]);
342
- const handlePopupClose = useCallback(() => {
343
- // If a save is in-flight, abort it immediately so the stream doesn't hang.
344
- saveAbortControllerRef.current?.abort();
345
- saveAbortControllerRef.current = null;
346
- setIsPopupOpen(false);
347
- setIsSavingAgent(false);
348
- }, []);
349
- /**
350
- * Applies the networks returned by the designer: upserts them and triggers navigation if needed.
351
- * Returns true when a matching reservation was applied, false (and surfaces an error banner) otherwise.
352
- */
353
- const applyNetworkSaveResult = useCallback((newNetworksFromSave, currentAgentNetworkName) => {
354
- if (newNetworksFromSave.length === 0) {
355
- showDockBanner({
356
- severity: "error",
357
- title: "Failed to apply network change.",
358
- detail: "The network designer did not return a reservation. Please try again.",
359
- });
360
- return false;
361
- }
362
- const replacement = newNetworksFromSave.find((n) => n.agentNetworkName === currentAgentNetworkName);
363
- if (replacement) {
364
- useTempNetworksStore.getState().upsertTempNetworks(newNetworksFromSave);
365
- if (networkId && onNetworkReplaced) {
366
- useAgentChatHistoryStore.getState().copyHistory(networkId, replacement.agentInfo.agent_name);
367
- onNetworkReplaced(networkId, replacement.agentInfo.agent_name);
368
- }
369
- return true;
370
- }
371
- // Reservations came back, but none matched the current network — surface this in the dock banner.
372
- showDockBanner({
373
- severity: "error",
374
- title: "Failed to apply network change.",
375
- detail: "A reservation was returned but did not match the current network. Please try again.",
376
- });
377
- return false;
378
- }, [networkId, onNetworkReplaced, showDockBanner]);
379
- const handleDockApply = useCallback(async () => {
380
- if (!dockPrompt.trim() || !neuroSanURL || !currentUser)
381
- return;
382
- const currentTempNetwork = networkId
383
- ? tempNetworks.find((n) => n.agentInfo.agent_name === networkId)
384
- : undefined;
385
- const currentDefinition = currentTempNetwork?.agentNetworkDefinition ?? [];
386
- setIsDockStreaming(true);
387
- const controller = new AbortController();
388
- dockAbortControllerRef.current = controller;
389
- let hasTimedOut = false;
390
- const timeoutId = setTimeout(() => {
391
- hasTimedOut = true;
392
- controller.abort();
393
- }, 120_000); // 2 min timeout
394
- try {
395
- const newNetworks = await streamNetworkDesignerPrompt(neuroSanURL, controller.signal, dockPrompt, currentDefinition, currentTempNetwork?.agentNetworkName, currentUser);
396
- const applied = applyNetworkSaveResult(newNetworks, currentTempNetwork?.agentNetworkName);
397
- if (applied) {
398
- setDockPrompt("");
399
- showDockBanner({
400
- severity: "success",
401
- title: "Changes applied.",
402
- detail: "Your network has been updated.",
403
- });
404
- }
405
- }
406
- catch (e) {
407
- const isAbort = e instanceof DOMException && e.name === "AbortError";
408
- if (isAbort) {
409
- if (hasTimedOut) {
410
- showDockBanner({
411
- severity: "error",
412
- title: "Failed to apply network change.",
413
- detail: "The request timed out. Please try again.",
414
- });
415
- }
416
- }
417
- else {
418
- showDockBanner({ severity: "error", title: "Failed to apply network change.", detail: String(e) });
419
- }
420
- }
421
- finally {
422
- clearTimeout(timeoutId);
423
- dockAbortControllerRef.current = null;
424
- setIsDockStreaming(false);
425
- }
426
- }, [applyNetworkSaveResult, currentUser, dockPrompt, networkId, neuroSanURL, showDockBanner, tempNetworks]);
427
- const handleExitEditMode = useCallback(() => {
428
- if (isDockStreaming) {
429
- dockAbortControllerRef.current?.abort();
430
- dockAbortControllerRef.current = null;
431
- setIsDockStreaming(false);
432
- }
433
- onExitEditMode?.();
434
- }, [isDockStreaming, onExitEditMode]);
435
- const handlePopupSave = useCallback(async (agentName, instructionsText, descriptionText) => {
436
- if (!selectedAgent)
319
+ const handleNodeClick = useCallback((_event, node) => openNodeEditor(node), [openNodeEditor]);
320
+ // ReactFlow makes nodes focusable and selects them on Enter, but it never fires onNodeClick from the keyboard.
321
+ // Route Enter on a focused node to the editor so keyboard users can open a node the same way a click does.
322
+ const handleNodeKeyDown = useCallback((event) => {
323
+ if (event.key !== "Enter")
437
324
  return;
438
- // Find the temp network entry for the currently selected network.
439
- const currentTempNetwork = networkId
440
- ? tempNetworks.find((n) => n.agentInfo.agent_name === networkId)
441
- : undefined;
442
- // Produce a new array with the saved agent's fields updated; all other entries pass through unchanged.
443
- const currentDefinitions = currentTempNetwork?.agentNetworkDefinition ?? [];
444
- const updated = currentDefinitions.map((entry) => entry.origin === selectedAgent.agentId
445
- ? { ...entry, instructions: instructionsText, description: descriptionText }
446
- : entry);
447
- if (networkId) {
448
- updateTempNetworkDefinition(networkId, updated);
449
- }
450
- if (!onSaveAgent) {
451
- setIsPopupOpen(false);
325
+ const target = event.target;
326
+ if (!(target instanceof HTMLElement))
452
327
  return;
453
- }
454
- setIsSavingAgent(true);
455
- const saveController = new AbortController();
456
- saveAbortControllerRef.current = saveController;
457
- const saveTimeoutId = setTimeout(() => saveController.abort(new DOMException("Save timed out", "TimeoutError")), 60_000 // 1 min timeout
458
- );
459
- try {
460
- await onSaveAgent(agentName, updated, currentTempNetwork?.agentNetworkName, saveController.signal);
461
- }
462
- catch (e) {
463
- console.error(`Error saving network ${agentName}. See onSaveAgent implementation for details.`, e);
464
- sendNotification(NotificationType.error, `Failed to save agent "${agentName}".`, String(e), undefined, null // show indefinitely until the user dismisses
465
- );
466
- }
467
- finally {
468
- clearTimeout(saveTimeoutId);
469
- saveAbortControllerRef.current = null;
470
- setIsSavingAgent(false);
471
- setIsPopupOpen(false);
472
- }
473
- }, [selectedAgent, tempNetworks, updateTempNetworkDefinition, networkId, onSaveAgent]);
328
+ const nodeId = target.closest(".react-flow__node")?.dataset["id"];
329
+ const node = nodeId ? nodes.find((n) => n.id === nodeId) : undefined;
330
+ if (node)
331
+ openNodeEditor(node);
332
+ }, [nodes, openNodeEditor]);
474
333
  const edges = layoutResult.edges;
475
334
  // Make sure to extract only thought bubble edges for the overlay.
476
335
  const thoughtBubbleEdgesForOverlay = useMemo(() => edges.filter((e) => e.type === "thoughtBubbleEdge"), [edges]);
477
336
  useEffect(() => {
478
- // Schedule a fitView after the layout is set to ensure the view is adjusted correctly
479
- setTimeout(() => {
480
- void fitView();
481
- }, 50);
482
- }, [agentsInNetwork, fitView, layout]);
337
+ scheduleFitView();
338
+ }, [agentsInNetwork, layout, scheduleFitView]);
483
339
  const onNodesChange = useCallback((changes) => {
484
340
  setNodes((currentNodes) => applyNodeChanges(changes.filter((change) => filterNodeEvents(change, isAgentNetworkDesignerMode)), currentNodes));
485
341
  }, [isAgentNetworkDesignerMode]);
@@ -534,9 +390,9 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
534
390
  justifyContent: "center",
535
391
  marginLeft: theme.spacing(0.75),
536
392
  width: "15px",
537
- }, children: i }, i))), _jsxs(ToggleButtonGroup, { id: `${id}-coloring-toggle`, value: coloringOption, exclusive: true, onChange: (_, newValue) => {
393
+ }, children: i }, i))), _jsxs(ToggleButtonGroup, { id: `${id}-coloring-toggle`, value: graphColoringOption, exclusive: true, onChange: (_, newValue) => {
538
394
  if (newValue !== null) {
539
- setColoringOption(newValue);
395
+ setGraphColoringOption(newValue);
540
396
  }
541
397
  }, size: "small", sx: {
542
398
  marginLeft: theme.spacing(2),
@@ -570,7 +426,7 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
570
426
  return isActive ? theme.palette.action.selected : undefined;
571
427
  };
572
428
  // Only show radial guides if radial layout is selected, radial guides are enabled, and it's not just Frontman
573
- const shouldShowRadialGuides = enableRadialGuides && layout === "radial" && maxDepth > 1;
429
+ const shouldShowRadialGuides = showRadialGuides && layout === "radial" && maxDepth > 1;
574
430
  // Generate the control bar for the flow, including layout and radial guides toggles
575
431
  const getControls = () => {
576
432
  return (_jsxs(Controls, { position: "top-left", style: {
@@ -583,44 +439,46 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
583
439
  backgroundColor: getControlButtonBackgroundColor(layout === "radial"),
584
440
  }, children: _jsx(HubOutlinedIcon, { id: "radial-layout-icon" }) }) }) }), _jsx(Tooltip, { id: "linear-layout-tooltip", title: "Linear layout", placement: "right", children: _jsx("span", { id: "linear-layout-span", children: _jsx(ControlButton, { id: "linear-layout-button", onClick: () => setLayout("linear"), style: {
585
441
  backgroundColor: getControlButtonBackgroundColor(layout === "linear"),
586
- }, children: _jsx(ScatterPlotOutlinedIcon, { id: "linear-layout-icon" }) }) }) }), _jsx(Tooltip, { id: "radial-guides-tooltip", title: `Enable/disable radial guides${layout === "radial" ? "" : " (only available in radial layout)"}`, placement: "right", children: _jsx("span", { id: "radial-guides-span", children: _jsx(ControlButton, { id: "radial-guides-button", onClick: () => setEnableRadialGuides(!enableRadialGuides), style: {
587
- backgroundColor: getControlButtonBackgroundColor(enableRadialGuides),
442
+ }, children: _jsx(ScatterPlotOutlinedIcon, { id: "linear-layout-icon" }) }) }) }), _jsx(Tooltip, { id: "radial-guides-tooltip", title: `Enable/disable radial guides${layout === "radial" ? "" : " (only available in radial layout)"}`, placement: "right", children: _jsx("span", { id: "radial-guides-span", children: _jsx(ControlButton, { id: "radial-guides-button", onClick: () => setShowRadialGuides(!showRadialGuides), style: {
443
+ backgroundColor: getControlButtonBackgroundColor(showRadialGuides),
588
444
  }, disabled: layout !== "radial", children: _jsx(AdjustRoundedIcon, { id: "radial-guides-icon" }) }) }) }), _jsx(Tooltip, { id: "thought-bubble-tooltip", title: `Toggle thought bubbles ${showThoughtBubbles ? "off" : "on"}`, placement: "right", children: _jsx("span", { id: "thought-bubble-span", children: _jsx(ControlButton, { id: "thought-bubble-button", onClick: () => setShowThoughtBubbles(!showThoughtBubbles), style: {
589
445
  backgroundColor: getControlButtonBackgroundColor(showThoughtBubbles),
590
446
  }, children: _jsx(ChatBubbleOutlinedIcon, { id: "thought-bubble-icon" }) }) }) })] }));
591
447
  };
592
- const titleBackgroundColor = alpha(theme.palette.background.paper, 0.75);
593
448
  const getTitle = () => {
594
- return (networkDisplayName && (_jsxs(Box, { id: `${id}-network-title-bar`, sx: {
449
+ if (!networkDisplayName)
450
+ return null;
451
+ return (_jsxs(Box, { id: `${id}-network-title-bar`, sx: {
595
452
  alignItems: "center",
596
453
  display: "flex",
597
454
  gap: 1,
598
455
  left: "50%",
599
456
  pointerEvents: "none",
600
457
  position: "absolute",
601
- top: 0,
458
+ top: theme.spacing(1),
602
459
  transform: "translateX(-50%)",
603
460
  zIndex: getZIndex(2, theme),
604
- }, children: [_jsx(Tooltip, { title: networkDisplayName, placement: "top", children: _jsx(Box, { sx: { pointerEvents: "auto" }, children: _jsx(Typography, { id: `${id}-network-title`, variant: "subtitle1", sx: {
605
- backdropFilter: "blur(6px)",
606
- backgroundColor: titleBackgroundColor,
607
- border: `1px solid ${alpha(theme.palette.divider, 0.75)}`,
608
- borderRadius: 2,
609
- boxShadow: theme.shadows[6],
610
- color: theme.palette.text.primary,
611
- fontWeight: 600,
612
- letterSpacing: "0.01em",
613
- lineHeight: 1.35,
614
- maxWidth: 400,
615
- overflow: "hidden",
616
- px: 2,
617
- py: 0.45,
618
- textOverflow: "ellipsis",
619
- whiteSpace: "nowrap",
620
- }, children: networkDisplayName }) }) }), isTemporaryNetwork && !isEditMode && !isAwaitingLlm && onEnterEditMode && (_jsx(Button, { id: `${id}-enter-edit-mode-btn`, variant: "contained", size: "small", onClick: onEnterEditMode, startIcon: _jsx(EditIcon, {}), sx: {
461
+ }, children: [_jsx(Tooltip, { title: networkDisplayName, placement: "top", children: _jsx(Typography, { id: `${id}-network-title`, variant: "subtitle1", sx: {
462
+ backdropFilter: "blur(6px)",
463
+ backgroundColor: alpha(theme.palette.background.paper, 0.75),
464
+ border: `1px solid ${alpha(theme.palette.divider, 0.75)}`,
465
+ borderRadius: 2,
466
+ boxShadow: theme.shadows[6],
467
+ color: theme.palette.text.primary,
468
+ fontWeight: 600,
469
+ letterSpacing: "0.01em",
470
+ lineHeight: 1.35,
471
+ maxWidth: 400,
472
+ overflow: "hidden",
473
+ pointerEvents: "auto",
474
+ px: 2,
475
+ py: 0.45,
476
+ textOverflow: "ellipsis",
477
+ whiteSpace: "nowrap",
478
+ }, children: networkDisplayName }) }), isTemporaryNetwork && !isEditingNetwork && !isAwaitingLlm && (_jsx(Button, { id: `${id}-enter-edit-mode-btn`, variant: "contained", size: "small", onClick: () => setIsEditingNetwork(true), startIcon: _jsx(EditIcon, {}), sx: {
621
479
  pointerEvents: "auto",
622
480
  "&:hover": { backgroundColor: theme.palette.primary.main },
623
- }, children: "Edit" }))] })));
481
+ }, children: "Edit" }))] }));
624
482
  };
625
483
  return (_jsxs(Box, { id: `${id}-outer-box`, sx: {
626
484
  display: "flex",
@@ -643,87 +501,14 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
643
501
  borderBottom: "1px solid divider",
644
502
  fill: theme.palette.text.primary,
645
503
  },
646
- }, children: [_jsxs(Box, { id: `${id}-react-flow-wrapper`, sx: { position: "relative", flex: 1, minHeight: 0 }, children: [networkDisplayName ? _jsx(Box, { sx: { marginBottom: "1rem" }, children: getTitle() }) : null, _jsx(ReactFlow, { connectionMode: ConnectionMode.Loose, edgeTypes: edgeTypes, edges: edges, fitView: true, id: `${id}-react-flow`, nodeTypes: nodeTypes, nodes: nodes, nodesDraggable: !isAgentNetworkDesignerMode, onNodeClick: handleNodeClick, onNodesChange: onNodesChange, children: !isAwaitingLlm && (_jsxs(_Fragment, { children: [agentsInNetwork?.length && !isAgentNetworkDesignerMode && !isEditMode ? getLegend() : null, _jsx(Background, { id: `${id}-background` }), !isAgentNetworkDesignerMode && !isEditMode && getControls(), shouldShowRadialGuides ? getRadialGuides() : null] })) }), _jsx(ThoughtBubbleOverlay, { nodes: nodes, edges: thoughtBubbleEdgesForOverlay, showThoughtBubbles: showThoughtBubbles, isStreaming: isStreaming, onBubbleHoverChange: handleBubbleHoverChange })] }), isEditMode && isTemporaryNetwork && !isAwaitingLlm && (_jsxs(Box, { sx: {
647
- backdropFilter: "blur(8px)",
648
- backgroundColor: alpha(theme.palette.background.paper, 0.2),
649
- borderTop: `2px solid ${theme.palette.primary.main}`,
650
- flexShrink: 0,
504
+ }, children: [_jsxs(Box, { id: `${id}-react-flow-wrapper`, ref: flowWrapperRef, sx: {
505
+ display: "flex",
506
+ flex: 1,
507
+ flexDirection: "column",
508
+ minHeight: 0,
651
509
  position: "relative",
652
- zIndex: getZIndex(2, theme),
653
- }, children: [dockBanner && (_jsx(MUIAlert, { closeable: true, id: `${id}-dock-banner`, onClose: handleDismissBanner, severity: dockBanner.severity, sx: {
654
- borderRadius: 0,
655
- // Override MUIAlert's default 1rem bottom margin so the banner sits flush
656
- // against the dock header below it.
657
- marginBottom: 0,
658
- py: 0,
659
- // Match the dock header's right padding so the banner's close X lines up
660
- // vertically with the header's close X below it.
661
- paddingRight: 0.5,
662
- alignItems: "center",
663
- // Frost the banner like the dock header, so the graph doesn't show through the
664
- // app's translucent paper background; keep a tinted, mostly opaque severity wash.
665
- "& .MuiAlert-action": {
666
- alignItems: "center",
667
- marginRight: 0,
668
- paddingTop: 0,
669
- },
670
- }, children: _jsxs(Typography, { variant: "caption", component: "span", children: [_jsx("strong", { children: dockBanner.title }), ` ${dockBanner.detail}`] }) })), _jsxs(Box, { sx: {
671
- backdropFilter: "blur(6px)",
672
- borderBottom: "1px solid divider",
673
- display: "flex",
674
- alignItems: "center",
675
- justifyContent: "space-between",
676
- paddingLeft: 1.25,
677
- paddingRight: 0.25,
678
- }, children: [_jsx(Typography, { variant: "overline", sx: { fontWeight: "bold", letterSpacing: 1, lineHeight: 1.8 }, children: "Network Editor" }), _jsx(IconButton, { size: "small", "aria-label": "close edit mode", onClick: handleExitEditMode, children: _jsx(CloseIcon, { fontSize: "small" }) })] }), _jsxs(Box, { sx: {
679
- display: "flex",
680
- gap: 1,
681
- px: 1,
682
- py: 0.5,
683
- alignItems: "center",
684
- }, children: [_jsx(TextField, { fullWidth: true, placeholder: DOCK_PROMPT_PLACEHOLDER, variant: "outlined", size: "small", value: dockPrompt, onChange: (e) => setDockPrompt(e.target.value), onKeyDown: (e) => {
685
- if (e.key === "Enter" && !e.shiftKey) {
686
- e.preventDefault();
687
- void handleDockApply();
688
- }
689
- }, disabled: isDockStreaming, slotProps: { htmlInput: { style: { fontSize: "0.75rem" } } } }), _jsx(Button, { variant: "contained", onClick: () => void handleDockApply(), disabled: isDockStreaming || !dockPrompt.trim(), sx: {
690
- fontSize: 16,
691
- marginBottom: "1px",
692
- marginRight: 0,
693
- minWidth: 110,
694
- paddingTop: 0.3,
695
- paddingBottom: 0.3,
696
- whiteSpace: "nowrap",
697
- }, startIcon: isDockStreaming ? (_jsx(CircularProgress, { size: 16, color: "inherit" })) : undefined, children: isDockStreaming ? "Applying..." : "Apply" })] })] })), selectedAgent && !isAwaitingLlm && (_jsx(AgentNodePopup, { agentName: selectedAgent.agentName, initialInstructions: selectedAgent.initialInstructions, initialDescription: selectedAgent.initialDescription, isOpen: isPopupOpen, isSaving: isSavingAgent, onClose: handlePopupClose, onSave: handlePopupSave })), _jsx(Backdrop, { open: isDockStreaming, sx: { zIndex: (t) => t.zIndex.modal + 1 }, children: stopState === "confirming" ? (_jsxs(Paper, { elevation: 6, sx: {
698
- display: "flex",
699
- flexDirection: "column",
700
- gap: 2,
701
- px: 4,
702
- py: 3,
703
- borderRadius: 2,
704
- maxWidth: 420,
705
- }, children: [_jsx(Typography, { variant: "body1", sx: { fontWeight: "bold" }, children: "Abort changes?" }), _jsx(Typography, { variant: "body2", color: "text.secondary", children: "The in-progress update will be cancelled and discarded. Your network will not be modified." }), _jsxs(Box, { sx: {
706
- display: "flex",
707
- gap: 1.5,
708
- justifyContent: "flex-end",
709
- }, children: [_jsx(Button, { variant: "outlined", onClick: handleKeepApplying, children: "Keep applying" }), _jsx(Button, { variant: "contained", color: "error", startIcon: _jsx("span", { style: { fontSize: "0.7rem" }, children: "\u25A0" }), onClick: handleStopAndDiscard, children: "Stop & discard" })] })] })) : (_jsxs(Paper, { elevation: 6, sx: {
710
- display: "flex",
711
- alignItems: "center",
712
- gap: 2,
713
- px: 4,
714
- py: 2.5,
715
- borderRadius: 2,
716
- maxWidth: 480,
717
- }, children: [_jsx(CircularProgress, { size: 24 }), _jsxs(Box, { sx: { flex: 1 }, children: [_jsx(Typography, { variant: "body1", sx: { fontWeight: "bold" }, children: "Applying changes to network" }), dockPrompt && (_jsx(Typography, { variant: "body2", color: "text.secondary", sx: { mt: 0.25 }, children: dockPrompt }))] }), _jsx(Button, { variant: "outlined", size: "small", startIcon: _jsx("span", { style: { fontSize: "0.65rem" }, children: "\u25A0" }), onClick: handleStopClick, sx: {
718
- whiteSpace: "nowrap",
719
- flexShrink: 0,
720
- color: theme.palette.common.white,
721
- borderColor: theme.palette.common.white,
722
- fontWeight: "bold",
723
- "&:hover": {
724
- borderColor: theme.palette.error.main,
725
- color: theme.palette.error.main,
726
- backgroundColor: alpha(theme.palette.error.main, 0.08),
727
- },
728
- }, children: "Stop" })] })) })] }));
510
+ pt: theme.spacing(4),
511
+ }, 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
512
+ ? getLegend()
513
+ : 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 }))] }));
729
514
  };