@cognizant-ai-lab/ui-common 1.10.0 → 1.12.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/dist/components/AgentChat/ChatCommon/ChatCommon.d.ts +5 -0
  2. package/dist/components/AgentChat/ChatCommon/ChatCommon.js +28 -7
  3. package/dist/components/AgentChat/ChatCommon/Const.d.ts +1 -0
  4. package/dist/components/AgentChat/ChatCommon/Const.js +2 -0
  5. package/dist/components/AgentChat/ChatCommon/SlyDataDialog.d.ts +34 -0
  6. package/dist/components/AgentChat/ChatCommon/SlyDataDialog.js +187 -0
  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/Common/ConfirmationModal.d.ts +3 -2
  10. package/dist/components/Common/GoogleAnalytics.d.ts +16 -0
  11. package/dist/components/Common/GoogleAnalytics.js +32 -0
  12. package/dist/components/Common/Navbar.d.ts +2 -1
  13. package/dist/components/Common/Navbar.js +3 -3
  14. package/dist/components/ErrorPage/ErrorPage.js +4 -4
  15. package/dist/components/MultiAgentAccelerator/AgentFlow/AgentFlow.d.ts +7 -7
  16. package/dist/components/MultiAgentAccelerator/AgentFlow/AgentFlow.js +143 -390
  17. package/dist/components/MultiAgentAccelerator/Editor/AgentNodeEditor.d.ts +24 -0
  18. package/dist/components/MultiAgentAccelerator/Editor/AgentNodeEditor.js +128 -0
  19. package/dist/components/MultiAgentAccelerator/Editor/NetworkEditorDock.d.ts +21 -0
  20. package/dist/components/MultiAgentAccelerator/Editor/NetworkEditorDock.js +305 -0
  21. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.js +109 -62
  22. package/dist/components/MultiAgentAccelerator/NeuroSanStudioCallout.d.ts +2 -0
  23. package/dist/components/MultiAgentAccelerator/NeuroSanStudioCallout.js +38 -0
  24. package/dist/components/MultiAgentAccelerator/PanelSeparator.d.ts +5 -0
  25. package/dist/components/MultiAgentAccelerator/PanelSeparator.js +46 -0
  26. package/dist/components/MultiAgentAccelerator/Sidebar/Sidebar.js +4 -3
  27. package/dist/components/MultiAgentAccelerator/Tour/MainTourSteps.js +8 -6
  28. package/dist/components/MultiAgentAccelerator/const.d.ts +1 -0
  29. package/dist/components/MultiAgentAccelerator/const.js +2 -0
  30. package/dist/components/Settings/ApiKeyErrorBanner.d.ts +22 -0
  31. package/dist/components/Settings/ApiKeyErrorBanner.js +26 -0
  32. package/dist/components/Settings/ApiKeyInput.d.ts +5 -2
  33. package/dist/components/Settings/ApiKeyInput.js +10 -4
  34. package/dist/components/Settings/SettingsDialog.js +22 -5
  35. package/dist/const.d.ts +0 -1
  36. package/dist/const.js +0 -1
  37. package/dist/controller/llm/Providers.d.ts +19 -2
  38. package/dist/controller/llm/Providers.js +45 -31
  39. package/dist/state/Announcements.d.ts +24 -0
  40. package/dist/state/Announcements.js +29 -0
  41. package/dist/state/ChatHistory.d.ts +10 -1
  42. package/dist/state/ChatHistory.js +8 -0
  43. package/dist/state/Environment.d.ts +2 -0
  44. package/dist/state/Environment.js +2 -0
  45. package/dist/state/Settings.d.ts +14 -0
  46. package/dist/state/Settings.js +6 -2
  47. package/dist/tsconfig.build.tsbuildinfo +1 -1
  48. package/dist/utils/Authentication.d.ts +7 -0
  49. package/dist/utils/Authentication.js +19 -5
  50. package/dist/utils/SlyData.d.ts +56 -0
  51. package/dist/utils/SlyData.js +106 -0
  52. package/dist/utils/SlyDataSchema.d.ts +31 -0
  53. package/dist/utils/SlyDataSchema.js +149 -0
  54. package/package.json +9 -8
  55. package/dist/components/MultiAgentAccelerator/AgentNodePopup.d.ts +0 -30
  56. package/dist/components/MultiAgentAccelerator/AgentNodePopup.js +0 -80
@@ -16,18 +16,12 @@ 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";
@@ -35,60 +29,22 @@ import Typography from "@mui/material/Typography";
35
29
  import { applyNodeChanges, Background, ConnectionMode, ControlButton, Controls, ReactFlow, useReactFlow, useStore, } from "@xyflow/react";
36
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
- const AGENT_SAVE_TIMEOUT_MS = 60_000;
57
- const DOCK_STREAM_TIMEOUT_MS = 120_000;
58
45
  const THOUGHT_BUBBLE_TIMEOUT_MS = 10_000;
59
- // How long the dock's status banner stays visible before auto-dismissing. Error banners persist until dismissed.
60
- // Exported for tests.
61
- export const DOCK_BANNER_AUTO_DISMISS_MS = 5_000;
62
- const DOCK_PROMPT_PLACEHOLDER = "Describe a change to the network";
63
46
  //#endregion: Constants
64
47
  //#region: Helpers
65
- /**
66
- * Streams the Agent Network Designer endpoint with a natural-language prompt and the current
67
- * network definition, collecting any returned reservations.
68
- */
69
- const applyNetworkDesignerChanges = async (neuroSanURL, signal, userPrompt, currentDefinition, agentNetworkName, currentUser) => {
70
- let newNetworks = [];
71
- await sendChatQuery(neuroSanURL, signal, userPrompt, AGENT_NETWORK_DESIGNER_ID, (chunk) => {
72
- const chatMessage = chatMessageFromChunk(chunk);
73
- if (!chatMessage) {
74
- return;
75
- }
76
- const reservations = extractReservations(chatMessage);
77
- if (reservations.length === 0) {
78
- return;
79
- }
80
- const networkHocon = extractNetworkHocon(chatMessage);
81
- const agentNetworkNameFromMessage = chatMessage.sly_data?.[AGENT_NETWORK_NAME_KEY];
82
- const networkName = agentNetworkName ?? agentNetworkNameFromMessage;
83
- const definitionFromMessage = chatMessage.sly_data?.[AGENT_NETWORK_DEFINITION_KEY];
84
- const converted = convertReservationsToNetworks(reservations, networkHocon, definitionFromMessage ?? currentDefinition, networkName);
85
- newNetworks = mergeNetworks(newNetworks, converted);
86
- }, null, {
87
- [AGENT_NETWORK_DEFINITION_KEY]: currentDefinition,
88
- ...(agentNetworkName ? { [AGENT_NETWORK_NAME_KEY]: agentNetworkName } : {}),
89
- }, currentUser, StreamingUnit.Line);
90
- return newNetworks;
91
- };
92
48
  /**
93
49
  * Filters node events based on the current mode. Don't allow any topological-modifying events (adding, deleting nodes)
94
50
  * and in Agent Network Designer mode, don't allow dragging nodes (position changes) either.
@@ -105,23 +61,81 @@ export const filterNodeEvents = (change, isAgentNetworkDesignerMode) => {
105
61
  return !(change.type === "position" && isAgentNetworkDesignerMode);
106
62
  };
107
63
  //#endregion: Helpers
108
- 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, }) => {
109
65
  const theme = useTheme();
110
66
  const { fitView } = useReactFlow();
111
- const handleResize = useCallback(() => {
112
- 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
+ });
113
77
  }, [fitView]);
114
78
  useEffect(() => {
115
- window.addEventListener("resize", handleResize);
116
- return () => window.removeEventListener("resize", handleResize);
117
- }, [handleResize]);
118
- const [layout, setLayout] = useState("radial");
119
- const [coloringOption, setColoringOption] = useState("depth");
120
- const [enableRadialGuides, setEnableRadialGuides] = useState(true);
121
- 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
+ };
122
137
  // Read temporary networks to find agent_network_definition for the currently selected network.
123
138
  const tempNetworks = useTempNetworksStore((state) => state.tempNetworks);
124
- const updateTempNetworkDefinition = useTempNetworksStore((state) => state.updateTempNetworkDefinition);
125
139
  // Track conversation IDs we've already processed to prevent re-adding after expiry
126
140
  const processedConversationIdsRef = useRef(new Set());
127
141
  // Track which bubble is currently being hovered
@@ -207,7 +221,7 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
207
221
  }, 1000);
208
222
  return () => clearInterval(cleanupInterval);
209
223
  }, [setThoughtBubbleEdges]); // mount/unmount only
210
- const isHeatmap = coloringOption === "heatmap";
224
+ const isHeatmap = graphColoringOption === "heatmap";
211
225
  const palette = usePalette();
212
226
  // Merge agents from active thought bubbles with agentsInNetwork for layout
213
227
  // This ensures bubble edges persist even when agents disappear from the network
@@ -232,29 +246,36 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
232
246
  }, [agentsInNetwork, bubbleAgentIds]);
233
247
  // Create the flow layout depending on user preference
234
248
  // Memoize layoutResult so it only recalculates when relevant data changes
235
- const layoutResult = useMemo(() => layout === "linear"
236
- ? layoutLinear({
237
- agentCounts: isHeatmap ? agentCounts : undefined,
238
- agentIconSuggestions,
239
- agentsInNetwork: mergedAgentsInNetwork,
240
- currentConversations,
241
- isAgentNetworkDesignerMode,
242
- isAwaitingLlm,
243
- isTemporaryNetwork,
244
- thoughtBubbleEdges,
245
- useNativeNames,
246
- })
247
- : layoutRadial({
248
- agentCounts: isHeatmap ? agentCounts : undefined,
249
- agentIconSuggestions,
250
- agentsInNetwork: mergedAgentsInNetwork,
251
- currentConversations,
252
- isAgentNetworkDesignerMode,
253
- isAwaitingLlm,
254
- isTemporaryNetwork,
255
- thoughtBubbleEdges,
256
- useNativeNames,
257
- }), [
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
+ }, [
258
279
  agentCounts,
259
280
  agentIconSuggestions,
260
281
  currentConversations,
@@ -275,53 +296,6 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
275
296
  // Track which node the user clicked on so we can open the popup
276
297
  const [selectedAgent, setSelectedAgent] = useState(null);
277
298
  const [isPopupOpen, setIsPopupOpen] = useState(false);
278
- // True, while the agent-edit request is in-flight so we can disable the Save button.
279
- const [isSavingAgent, setIsSavingAgent] = useState(false);
280
- // AbortController for the in-flight save request — stored in a ref so handlePopupClose can cancel it.
281
- const saveAbortControllerRef = useRef(null);
282
- // Dock (edit-mode prompt bar) state
283
- const [dockPrompt, setDockPrompt] = useState("");
284
- const [isDockStreaming, setIsDockStreaming] = useState(false);
285
- const dockAbortControllerRef = useRef(null);
286
- // Stop-confirm overlay state: null = not shown, "confirming" = abort dialog open.
287
- const [stopState, setStopState] = useState(null);
288
- // Inline status banner shown above the dock header after an "apply" succeeds, is canceled, or fails.
289
- const [dockBanner, setDockBanner] = useState(null);
290
- const bannerTimeoutRef = useRef(null);
291
- // Clear the banner auto-dismiss timer on unmount.
292
- useEffect(() => {
293
- return () => {
294
- clearTimeout(bannerTimeoutRef.current);
295
- };
296
- }, []);
297
- const handleDismissBanner = useCallback(() => {
298
- clearTimeout(bannerTimeoutRef.current);
299
- setDockBanner(null);
300
- }, []);
301
- // Show a dock banner. Success/cancel banners auto-dismiss; error banners persist until dismissed.
302
- const showDockBanner = useCallback((banner) => {
303
- clearTimeout(bannerTimeoutRef.current);
304
- setDockBanner(banner);
305
- if (banner.severity !== "error") {
306
- bannerTimeoutRef.current = setTimeout(() => setDockBanner(null), DOCK_BANNER_AUTO_DISMISS_MS);
307
- }
308
- }, []);
309
- const handleStopClick = useCallback(() => {
310
- setStopState("confirming");
311
- }, []);
312
- const handleKeepApplying = useCallback(() => {
313
- setStopState(null);
314
- }, []);
315
- const handleStopAndDiscard = useCallback(() => {
316
- dockAbortControllerRef.current?.abort();
317
- dockAbortControllerRef.current = null;
318
- setStopState(null);
319
- showDockBanner({
320
- severity: "info",
321
- title: "Applying cancelled.",
322
- detail: "Nothing was changed. Your prompt is restored below.",
323
- });
324
- }, [showDockBanner]);
325
299
  const openNodeEditor = useCallback((node) => {
326
300
  // Popup is only available for temporary networks.
327
301
  if (!isTemporaryNetwork)
@@ -356,162 +330,12 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
356
330
  if (node)
357
331
  openNodeEditor(node);
358
332
  }, [nodes, openNodeEditor]);
359
- const handlePopupClose = useCallback(() => {
360
- // If a save is in-flight, abort it immediately so the stream doesn't hang.
361
- saveAbortControllerRef.current?.abort();
362
- saveAbortControllerRef.current = null;
363
- setIsPopupOpen(false);
364
- setIsSavingAgent(false);
365
- }, []);
366
- /**
367
- * Applies the networks returned by the designer: upserts them and triggers navigation if needed.
368
- * Returns true when a matching reservation was applied, false (and surfaces an error banner) otherwise.
369
- */
370
- const saveUpdates = useCallback((newNetworksFromSave, currentAgentNetworkName) => {
371
- if (newNetworksFromSave.length === 0) {
372
- showDockBanner({
373
- severity: "error",
374
- title: "Failed to apply network change.",
375
- detail: "The network designer did not return a reservation. Please try again.",
376
- });
377
- return false;
378
- }
379
- // Find the returned reservation that stands in for the current network (matched by name). When
380
- // present, persist every returned network, then carry the open network's chat history over to the
381
- // replacement and notify the parent so it can navigate to the new reservation.
382
- const replacement = newNetworksFromSave.find((n) => n.agentNetworkName === currentAgentNetworkName);
383
- if (replacement) {
384
- useTempNetworksStore.getState().upsertTempNetworks(newNetworksFromSave);
385
- if (networkId && onNetworkReplaced) {
386
- useAgentChatHistoryStore.getState().copyHistory(networkId, replacement.agentInfo.agent_name);
387
- onNetworkReplaced(networkId, replacement.agentInfo.agent_name);
388
- }
389
- return true;
390
- }
391
- // Reservations came back, but none matched the current network — surface this in the dock banner.
392
- showDockBanner({
393
- severity: "error",
394
- title: "Failed to apply network change.",
395
- detail: "A reservation was returned but did not match the current network. Please try again.",
396
- });
397
- return false;
398
- }, [networkId, onNetworkReplaced, showDockBanner]);
399
- const handleDockApply = useCallback(async () => {
400
- const readyToApplyEdit = Boolean(dockPrompt.trim() && neuroSanURL && currentUser);
401
- if (!readyToApplyEdit)
402
- return;
403
- const currentTempNetwork = networkId
404
- ? tempNetworks.find((n) => n.agentInfo.agent_name === networkId)
405
- : undefined;
406
- const currentDefinition = currentTempNetwork?.agentNetworkDefinition ?? [];
407
- setIsDockStreaming(true);
408
- const controller = new AbortController();
409
- dockAbortControllerRef.current = controller;
410
- let hasTimedOut = false;
411
- const timeoutId = setTimeout(() => {
412
- hasTimedOut = true;
413
- controller.abort();
414
- }, DOCK_STREAM_TIMEOUT_MS);
415
- try {
416
- const newNetworks = await applyNetworkDesignerChanges(neuroSanURL, controller.signal, dockPrompt, currentDefinition, currentTempNetwork?.agentNetworkName, currentUser);
417
- const appliedSuccess = saveUpdates(newNetworks, currentTempNetwork?.agentNetworkName);
418
- if (appliedSuccess) {
419
- setDockPrompt("");
420
- showDockBanner({
421
- severity: "success",
422
- title: "Changes applied.",
423
- detail: "Your network has been updated.",
424
- });
425
- }
426
- }
427
- catch (e) {
428
- const isAbort = e instanceof DOMException && e.name === "AbortError";
429
- if (isAbort) {
430
- if (hasTimedOut) {
431
- showDockBanner({
432
- severity: "error",
433
- title: "Failed to apply network change.",
434
- detail: "The request timed out. Please try again.",
435
- });
436
- }
437
- }
438
- else {
439
- showDockBanner({ severity: "error", title: "Failed to apply network change.", detail: String(e) });
440
- }
441
- }
442
- finally {
443
- clearTimeout(timeoutId);
444
- dockAbortControllerRef.current = null;
445
- setIsDockStreaming(false);
446
- }
447
- }, [saveUpdates, currentUser, dockPrompt, networkId, neuroSanURL, showDockBanner, tempNetworks]);
448
- const handleExitEditMode = useCallback(() => {
449
- if (isDockStreaming) {
450
- dockAbortControllerRef.current?.abort();
451
- dockAbortControllerRef.current = null;
452
- setIsDockStreaming(false);
453
- }
454
- onExitEditMode?.();
455
- }, [isDockStreaming, onExitEditMode]);
456
- // Pressing Escape exits edit mode, mirroring the explicit exit button. Skip while the
457
- // node popup is open so Escape closes the popup first rather than the whole edit mode.
458
- useEffect(() => {
459
- if (!isEditMode || isPopupOpen)
460
- return undefined;
461
- const handleEscape = (e) => {
462
- if (e.key === "Escape")
463
- handleExitEditMode();
464
- };
465
- document.addEventListener("keydown", handleEscape);
466
- return () => document.removeEventListener("keydown", handleEscape);
467
- }, [isEditMode, isPopupOpen, handleExitEditMode]);
468
- const handlePopupSave = useCallback(async (agentName, instructionsText, descriptionText) => {
469
- if (!selectedAgent)
470
- return;
471
- // Find the temp network entry for the currently selected network.
472
- const currentTempNetwork = networkId
473
- ? tempNetworks.find((n) => n.agentInfo.agent_name === networkId)
474
- : undefined;
475
- // Produce a new array with the saved agent's fields updated; all other entries pass through unchanged.
476
- const currentDefinitions = currentTempNetwork?.agentNetworkDefinition ?? [];
477
- const updatedDefinitions = currentDefinitions.map((entry) => entry.origin === selectedAgent.agentId
478
- ? { ...entry, instructions: instructionsText, description: descriptionText }
479
- : entry);
480
- if (networkId) {
481
- updateTempNetworkDefinition(networkId, updatedDefinitions);
482
- }
483
- if (!onSaveAgent) {
484
- setIsPopupOpen(false);
485
- return;
486
- }
487
- setIsSavingAgent(true);
488
- const saveController = new AbortController();
489
- saveAbortControllerRef.current = saveController;
490
- const saveTimeoutId = setTimeout(() => saveController.abort(new DOMException("Save timed out", "TimeoutError")), AGENT_SAVE_TIMEOUT_MS);
491
- try {
492
- await onSaveAgent(agentName, updatedDefinitions, currentTempNetwork?.agentNetworkName, saveController.signal);
493
- }
494
- catch (e) {
495
- console.error(`Error saving network ${agentName}. See onSaveAgent implementation for details.`, e);
496
- sendNotification(NotificationType.error, `Failed to save agent "${agentName}".`, String(e), undefined, null // show indefinitely until the user dismisses
497
- );
498
- }
499
- finally {
500
- clearTimeout(saveTimeoutId);
501
- saveAbortControllerRef.current = null;
502
- setIsSavingAgent(false);
503
- setIsPopupOpen(false);
504
- }
505
- }, [selectedAgent, tempNetworks, updateTempNetworkDefinition, networkId, onSaveAgent]);
506
333
  const edges = layoutResult.edges;
507
334
  // Make sure to extract only thought bubble edges for the overlay.
508
335
  const thoughtBubbleEdgesForOverlay = useMemo(() => edges.filter((e) => e.type === "thoughtBubbleEdge"), [edges]);
509
336
  useEffect(() => {
510
- // Schedule a fitView after the layout is set to ensure the view is adjusted correctly
511
- setTimeout(() => {
512
- void fitView();
513
- }, 50);
514
- }, [agentsInNetwork, fitView, layout]);
337
+ scheduleFitView();
338
+ }, [agentsInNetwork, layout, scheduleFitView]);
515
339
  const onNodesChange = useCallback((changes) => {
516
340
  setNodes((currentNodes) => applyNodeChanges(changes.filter((change) => filterNodeEvents(change, isAgentNetworkDesignerMode)), currentNodes));
517
341
  }, [isAgentNetworkDesignerMode]);
@@ -566,9 +390,9 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
566
390
  justifyContent: "center",
567
391
  marginLeft: theme.spacing(0.75),
568
392
  width: "15px",
569
- }, 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) => {
570
394
  if (newValue !== null) {
571
- setColoringOption(newValue);
395
+ setGraphColoringOption(newValue);
572
396
  }
573
397
  }, size: "small", sx: {
574
398
  marginLeft: theme.spacing(2),
@@ -602,7 +426,7 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
602
426
  return isActive ? theme.palette.action.selected : undefined;
603
427
  };
604
428
  // Only show radial guides if radial layout is selected, radial guides are enabled, and it's not just Frontman
605
- const shouldShowRadialGuides = enableRadialGuides && layout === "radial" && maxDepth > 1;
429
+ const shouldShowRadialGuides = showRadialGuides && layout === "radial" && maxDepth > 1;
606
430
  // Generate the control bar for the flow, including layout and radial guides toggles
607
431
  const getControls = () => {
608
432
  return (_jsxs(Controls, { position: "top-left", style: {
@@ -615,44 +439,46 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
615
439
  backgroundColor: getControlButtonBackgroundColor(layout === "radial"),
616
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: {
617
441
  backgroundColor: getControlButtonBackgroundColor(layout === "linear"),
618
- }, 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: {
619
- 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),
620
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: {
621
445
  backgroundColor: getControlButtonBackgroundColor(showThoughtBubbles),
622
446
  }, children: _jsx(ChatBubbleOutlinedIcon, { id: "thought-bubble-icon" }) }) }) })] }));
623
447
  };
624
- const titleBackgroundColor = alpha(theme.palette.background.paper, 0.75);
625
448
  const getTitle = () => {
626
- 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: {
627
452
  alignItems: "center",
628
453
  display: "flex",
629
454
  gap: 1,
630
455
  left: "50%",
631
456
  pointerEvents: "none",
632
457
  position: "absolute",
633
- top: 0,
458
+ top: theme.spacing(1),
634
459
  transform: "translateX(-50%)",
635
460
  zIndex: getZIndex(2, theme),
636
- }, children: [_jsx(Tooltip, { title: networkDisplayName, placement: "top", children: _jsx(Box, { sx: { pointerEvents: "auto" }, children: _jsx(Typography, { id: `${id}-network-title`, variant: "subtitle1", sx: {
637
- backdropFilter: "blur(6px)",
638
- backgroundColor: titleBackgroundColor,
639
- border: `1px solid ${alpha(theme.palette.divider, 0.75)}`,
640
- borderRadius: 2,
641
- boxShadow: theme.shadows[6],
642
- color: theme.palette.text.primary,
643
- fontWeight: 600,
644
- letterSpacing: "0.01em",
645
- lineHeight: 1.35,
646
- maxWidth: 400,
647
- overflow: "hidden",
648
- px: 2,
649
- py: 0.45,
650
- textOverflow: "ellipsis",
651
- whiteSpace: "nowrap",
652
- }, 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: {
653
479
  pointerEvents: "auto",
654
480
  "&:hover": { backgroundColor: theme.palette.primary.main },
655
- }, children: "Edit" }))] })));
481
+ }, children: "Edit" }))] }));
656
482
  };
657
483
  return (_jsxs(Box, { id: `${id}-outer-box`, sx: {
658
484
  display: "flex",
@@ -675,87 +501,14 @@ export const AgentFlow = ({ agentCounts, agentIconSuggestions, agentsInNetwork,
675
501
  borderBottom: "1px solid divider",
676
502
  fill: theme.palette.text.primary,
677
503
  },
678
- }, 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, onKeyDown: handleNodeKeyDown, 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: {
679
- backdropFilter: "blur(8px)",
680
- backgroundColor: alpha(theme.palette.background.paper, 0.2),
681
- borderTop: `2px solid ${theme.palette.primary.main}`,
682
- 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,
683
509
  position: "relative",
684
- zIndex: getZIndex(2, theme),
685
- }, children: [dockBanner && (_jsx(MUIAlert, { closeable: true, id: `${id}-dock-banner`, onClose: handleDismissBanner, severity: dockBanner.severity, sx: {
686
- borderRadius: 0,
687
- // Override MUIAlert's default 1rem bottom margin so the banner sits flush
688
- // against the dock header below it.
689
- marginBottom: 0,
690
- py: 0,
691
- // Match the dock header's right padding so the banner's close X lines up
692
- // vertically with the header's close X below it.
693
- paddingRight: 0.5,
694
- alignItems: "center",
695
- // Frost the banner like the dock header, so the graph doesn't show through the
696
- // app's translucent paper background; keep a tinted, mostly opaque severity wash.
697
- "& .MuiAlert-action": {
698
- alignItems: "center",
699
- marginRight: 0,
700
- paddingTop: 0,
701
- },
702
- }, children: _jsxs(Typography, { variant: "caption", component: "span", children: [_jsx("strong", { children: dockBanner.title }), ` ${dockBanner.detail}`] }) })), _jsxs(Box, { sx: {
703
- backdropFilter: "blur(6px)",
704
- borderBottom: "1px solid divider",
705
- display: "flex",
706
- alignItems: "center",
707
- justifyContent: "space-between",
708
- paddingLeft: 1.25,
709
- paddingRight: 0.25,
710
- }, 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: {
711
- display: "flex",
712
- gap: 1,
713
- px: 1,
714
- py: 0.5,
715
- alignItems: "center",
716
- }, children: [_jsx(TextField, { autoFocus: true, fullWidth: true, placeholder: DOCK_PROMPT_PLACEHOLDER, variant: "outlined", size: "small", value: dockPrompt, onChange: (e) => setDockPrompt(e.target.value), onKeyDown: (e) => {
717
- if (e.key === "Enter" && !e.shiftKey) {
718
- e.preventDefault();
719
- void handleDockApply();
720
- }
721
- }, disabled: isDockStreaming, slotProps: { htmlInput: { style: { fontSize: "0.75rem" } } } }), _jsx(Button, { variant: "contained", onClick: () => void handleDockApply(), disabled: isDockStreaming || !dockPrompt.trim(), sx: {
722
- fontSize: 16,
723
- marginBottom: "1px",
724
- marginRight: 0,
725
- minWidth: 110,
726
- paddingTop: 0.3,
727
- paddingBottom: 0.3,
728
- whiteSpace: "nowrap",
729
- }, 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: {
730
- display: "flex",
731
- flexDirection: "column",
732
- gap: 2,
733
- px: 4,
734
- py: 3,
735
- borderRadius: 2,
736
- maxWidth: 420,
737
- }, 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: {
738
- display: "flex",
739
- gap: 1.5,
740
- justifyContent: "flex-end",
741
- }, 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: {
742
- display: "flex",
743
- alignItems: "center",
744
- gap: 2,
745
- px: 4,
746
- py: 2.5,
747
- borderRadius: 2,
748
- maxWidth: 480,
749
- }, 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: {
750
- whiteSpace: "nowrap",
751
- flexShrink: 0,
752
- color: theme.palette.common.white,
753
- borderColor: theme.palette.common.white,
754
- fontWeight: "bold",
755
- "&:hover": {
756
- borderColor: theme.palette.error.main,
757
- color: theme.palette.error.main,
758
- backgroundColor: alpha(theme.palette.error.main, 0.08),
759
- },
760
- }, 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 }))] }));
761
514
  };