@cognizant-ai-lab/ui-common 1.3.3 → 1.4.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 (114) hide show
  1. package/README.md +287 -0
  2. package/dist/Theme/Palettes.d.ts +18 -0
  3. package/dist/Theme/Palettes.js +94 -0
  4. package/dist/Theme/Theme.d.ts +22 -0
  5. package/dist/Theme/Theme.js +58 -0
  6. package/dist/components/AgentChat/ChatCommon.d.ts +4 -2
  7. package/dist/components/AgentChat/ChatCommon.js +141 -105
  8. package/dist/components/AgentChat/ControlButtons.js +3 -1
  9. package/dist/components/AgentChat/FormattedMarkdown.d.ts +4 -4
  10. package/dist/components/AgentChat/FormattedMarkdown.js +5 -7
  11. package/dist/components/AgentChat/LlmChatButton.d.ts +2 -6
  12. package/dist/components/AgentChat/LlmChatButton.js +3 -3
  13. package/dist/components/AgentChat/UserQueryDisplay.js +2 -4
  14. package/dist/components/AgentChat/Utils.d.ts +2 -1
  15. package/dist/components/AgentChat/Utils.js +4 -1
  16. package/dist/components/AgentChat/VoiceChat/MicrophoneButton.d.ts +2 -2
  17. package/dist/components/AgentChat/VoiceChat/VoiceChat.d.ts +3 -3
  18. package/dist/components/AgentChat/VoiceChat/VoiceChat.js +5 -5
  19. package/dist/components/ChatBot/ChatBot.js +2 -2
  20. package/dist/components/Common/Breadcrumbs.js +1 -1
  21. package/dist/components/Common/{confirmationModal.js → ConfirmationModal.js} +2 -5
  22. package/dist/components/Common/CustomerLogo.d.ts +17 -0
  23. package/dist/components/Common/CustomerLogo.js +49 -0
  24. package/dist/components/Common/Footer.d.ts +18 -0
  25. package/dist/components/Common/Footer.js +59 -0
  26. package/dist/components/Common/LlmChatOptionsButton.d.ts +1 -4
  27. package/dist/components/Common/LlmChatOptionsButton.js +4 -4
  28. package/dist/components/Common/LoadingSpinner.js +1 -1
  29. package/dist/components/Common/MUIAccordion.d.ts +2 -2
  30. package/dist/components/Common/MUIAccordion.js +2 -12
  31. package/dist/components/Common/MUIAlert.d.ts +2 -1
  32. package/dist/components/Common/MUIAlert.js +4 -1
  33. package/dist/components/Common/MUIDialog.d.ts +1 -1
  34. package/dist/components/Common/MUIDialog.js +1 -1
  35. package/dist/components/Common/Navbar.d.ts +3 -1
  36. package/dist/components/Common/Navbar.js +60 -35
  37. package/dist/components/Common/PageLoader.js +3 -4
  38. package/dist/components/Common/Snackbar.d.ts +4 -1
  39. package/dist/components/Common/Snackbar.js +11 -19
  40. package/dist/components/Common/notification.d.ts +3 -3
  41. package/dist/components/Common/notification.js +6 -6
  42. package/dist/components/ErrorPage/ErrorBoundary.d.ts +2 -2
  43. package/dist/components/ErrorPage/ErrorBoundary.js +1 -1
  44. package/dist/components/ErrorPage/ErrorPage.js +6 -5
  45. package/dist/components/MultiAgentAccelerator/AgentConversations.d.ts +17 -0
  46. package/dist/components/MultiAgentAccelerator/AgentConversations.js +77 -0
  47. package/dist/components/MultiAgentAccelerator/AgentCounts.d.ts +12 -0
  48. package/dist/components/MultiAgentAccelerator/AgentCounts.js +21 -0
  49. package/dist/components/MultiAgentAccelerator/AgentFlow.d.ts +6 -4
  50. package/dist/components/MultiAgentAccelerator/AgentFlow.js +106 -185
  51. package/dist/components/MultiAgentAccelerator/AgentNode.d.ts +7 -5
  52. package/dist/components/MultiAgentAccelerator/AgentNode.js +93 -50
  53. package/dist/components/MultiAgentAccelerator/GraphLayouts.d.ts +20 -17
  54. package/dist/components/MultiAgentAccelerator/GraphLayouts.js +16 -14
  55. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.d.ts +2 -3
  56. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.js +214 -55
  57. package/dist/components/MultiAgentAccelerator/PlasmaEdge.d.ts +1 -1
  58. package/dist/components/MultiAgentAccelerator/PlasmaEdge.js +14 -12
  59. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.d.ts +15 -0
  60. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.js +104 -0
  61. package/dist/components/MultiAgentAccelerator/Sidebar/Sidebar.d.ts +17 -0
  62. package/dist/components/MultiAgentAccelerator/{Sidebar.js → Sidebar/Sidebar.js} +146 -59
  63. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.d.ts +19 -0
  64. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.js +113 -0
  65. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.d.ts +26 -0
  66. package/dist/components/MultiAgentAccelerator/TemporaryNetworks.js +20 -0
  67. package/dist/components/MultiAgentAccelerator/ThoughtBubbleEdge.d.ts +10 -8
  68. package/dist/components/MultiAgentAccelerator/ThoughtBubbleEdge.js +1 -1
  69. package/dist/components/MultiAgentAccelerator/ThoughtBubbleOverlay.d.ts +3 -2
  70. package/dist/components/MultiAgentAccelerator/ThoughtBubbleOverlay.js +10 -13
  71. package/dist/components/MultiAgentAccelerator/const.d.ts +1 -3
  72. package/dist/components/MultiAgentAccelerator/const.js +4 -18
  73. package/dist/components/Settings/FadingCheckmark.d.ts +14 -0
  74. package/dist/components/Settings/FadingCheckmark.js +43 -0
  75. package/dist/components/Settings/SettingsDialog.d.ts +9 -0
  76. package/dist/components/Settings/SettingsDialog.js +265 -0
  77. package/dist/const.d.ts +1 -2
  78. package/dist/const.js +2 -3
  79. package/dist/controller/Types/AgentIconSuggestions.d.ts +4 -0
  80. package/dist/controller/Types/AgentIconSuggestions.js +1 -0
  81. package/dist/controller/Types/Branding.d.ts +12 -0
  82. package/dist/controller/Types/Branding.js +1 -0
  83. package/dist/controller/Types/NetworkIconSuggestions.d.ts +4 -0
  84. package/dist/controller/Types/NetworkIconSuggestions.js +1 -0
  85. package/dist/controller/agent/Agent.d.ts +32 -12
  86. package/dist/controller/agent/Agent.js +71 -19
  87. package/dist/controller/llm/LlmChat.d.ts +1 -1
  88. package/dist/controller/llm/LlmChat.js +2 -2
  89. package/dist/index.d.ts +10 -5
  90. package/dist/index.js +10 -5
  91. package/dist/state/{environment.d.ts → Environment.d.ts} +2 -0
  92. package/dist/state/{environment.js → Environment.js} +2 -0
  93. package/dist/state/Settings.d.ts +62 -0
  94. package/dist/state/Settings.js +62 -0
  95. package/dist/state/TemporaryNetworks.d.ts +32 -0
  96. package/dist/state/TemporaryNetworks.js +26 -0
  97. package/dist/tsconfig.build.tsbuildinfo +1 -1
  98. package/dist/utils/Authentication.d.ts +2 -2
  99. package/dist/utils/Authentication.js +6 -6
  100. package/dist/utils/text.d.ts +2 -2
  101. package/dist/utils/text.js +3 -5
  102. package/dist/utils/title.d.ts +1 -1
  103. package/dist/utils/title.js +2 -2
  104. package/dist/utils/useLocalStorage.d.ts +1 -1
  105. package/dist/utils/useLocalStorage.js +3 -3
  106. package/dist/utils/zIndexLayers.d.ts +1 -1
  107. package/dist/utils/zIndexLayers.js +3 -15
  108. package/package.json +23 -21
  109. package/dist/components/MultiAgentAccelerator/Sidebar.d.ts +0 -12
  110. package/dist/utils/Theme.d.ts +0 -7
  111. package/dist/utils/Theme.js +0 -7
  112. package/dist/utils/agentConversations.d.ts +0 -24
  113. package/dist/utils/agentConversations.js +0 -113
  114. /package/dist/components/Common/{confirmationModal.d.ts → ConfirmationModal.d.ts} +0 -0
@@ -15,12 +15,10 @@ See the License for the specific language governing permissions and
15
15
  limitations under the License.
16
16
  */
17
17
  import CloseIcon from "@mui/icons-material/Close";
18
- import { styled, useColorScheme } from "@mui/material";
19
18
  import Box from "@mui/material/Box";
20
19
  import IconButton from "@mui/material/IconButton";
20
+ import { alpha, styled, useTheme } from "@mui/material/styles";
21
21
  import { SnackbarContent, useSnackbar } from "notistack";
22
- import { forwardRef } from "react";
23
- import { isDarkMode } from "../../utils/Theme.js";
24
22
  // #region: Styled Components
25
23
  const IconBox = styled(Box)({
26
24
  position: "relative",
@@ -39,30 +37,24 @@ const IconBox = styled(Box)({
39
37
  },
40
38
  });
41
39
  // #endregion: Types
42
- // Passing Snackbar callback as a function because if we use an arrow function here we'd have to set displayName
43
- export const Snackbar = forwardRef(
44
- // eslint-disable-next-line prefer-arrow-callback
45
- function Snackbar({ description, hideIconVariant = false, iconVariant, id, message, variant }, ref) {
40
+ export const Snackbar = ({ ref, description, hideIconVariant = false, iconVariant, id, message, variant, }) => {
46
41
  const { closeSnackbar } = useSnackbar();
47
42
  const handleCloseSnackbar = () => closeSnackbar(id);
48
43
  const icon = iconVariant[variant];
49
- const { mode, systemMode } = useColorScheme();
50
- const darkMode = isDarkMode(mode, systemMode);
51
- // Temporary styling for implementation of dark mode
52
- const darkModeStyling = {
53
- backgroundColor: darkMode ? "var(--bs-dark-mode-dim)" : "var(--bs-white)",
54
- color: darkMode ? "var(--bs-white)" : "var(--bs-primary)",
55
- };
56
- return (_jsx(SnackbarContent, { ref: ref, role: "alert", children: _jsxs(Box, { className: `${variant}-snackbar-notification`, id: `${id}-snackbar-box`, sx: {
57
- ...darkModeStyling,
44
+ // Theming/Dark mode
45
+ const theme = useTheme();
46
+ const shadowColor = theme.palette.mode === "dark" ? theme.palette.common.white : theme.palette.common.black;
47
+ return (_jsx(SnackbarContent, { ref: ref, role: "alert", children: _jsxs(Box, { className: `${variant}-snackbar-notification`, id: `${id}-snackbar-box`, "data-testid": `${id}-snackbar-box`, sx: {
48
+ background: theme.palette.background.paper,
58
49
  borderColor: "transparent",
59
50
  borderRadius: "var(--bs-border-radius)",
60
51
  borderWidth: "1px",
61
- boxShadow: `0 6px 16px 0 rgba(0, 0, 0, 0.08), 0 3px 6px -4px rgba(0, 0, 0, 0.12),
62
- 0 9px 28px 8px rgba(0, 0, 0, 0.05)`,
52
+ boxShadow: `0 6px 16px 0 ${alpha(shadowColor, 0.08)}, 0 3px 6px -4px ${alpha(shadowColor, 0.12)},
53
+ 0 9px 28px 8px ${alpha(shadowColor, 0.05)}`,
63
54
  maxWidth: "450px",
64
55
  minWidth: "250px",
65
56
  padding: "0.9rem",
57
+ paddingRight: "4rem",
66
58
  }, children: [!hideIconVariant && (_jsx(Box, { id: `${id}-snackbar-icon-box-container`, sx: { display: "inline-flex", flexDirection: "column" }, children: _jsx(IconBox, { className: variant, "data-testid": `${id}-snackbar-icon-box`, id: `${id}-snackbar-icon-box`, children: icon }) })), _jsxs(Box, { id: `${id}-snackbar-content-box`, sx: {
67
59
  display: "inline-flex",
68
60
  flexDirection: "column",
@@ -81,4 +73,4 @@ function Snackbar({ description, hideIconVariant = false, iconVariant, id, messa
81
73
  color: "var(--bs-gray-medium)",
82
74
  fontSize: "0.6em",
83
75
  } }) }), description && (_jsx(Box, { id: `${id}-snackbar-description-box`, sx: { fontSize: "0.8rem", paddingTop: "10px", paddingBottom: "10px" }, children: description }))] })] }) }));
84
- });
76
+ };
@@ -1,4 +1,4 @@
1
- import { SnackbarKey, SnackbarOrigin } from "notistack";
1
+ import { SnackbarOrigin } from "notistack";
2
2
  import { JSX as ReactJSX } from "react";
3
3
  export declare enum NotificationType {
4
4
  "success" = 0,
@@ -6,7 +6,7 @@ export declare enum NotificationType {
6
6
  "warning" = 2,
7
7
  "error" = 3
8
8
  }
9
- export declare function closeNotification(snackbarId?: SnackbarKey): void;
9
+ export declare const closeNotification: () => void;
10
10
  /**
11
11
  * Convenience method to allow sending notifications to user with a one-liner.
12
12
  * Simply wraps @Notification function
@@ -15,4 +15,4 @@ export declare function closeNotification(snackbarId?: SnackbarKey): void;
15
15
  * @param description More complete description of the notification
16
16
  * @param placement Where to show notification. Defaults to top-right.
17
17
  */
18
- export declare function sendNotification(variantType: NotificationType, message: string, description?: string | ReactJSX.Element, placement?: SnackbarOrigin): void;
18
+ export declare const sendNotification: (variantType: NotificationType, message: string, description?: string | ReactJSX.Element, placement?: SnackbarOrigin) => void;
@@ -27,9 +27,9 @@ export var NotificationType;
27
27
  const ERROR_WARNING_NOTIFICATION_DURATION_MS = 15_000;
28
28
  // Display info notification popups for this many seconds
29
29
  const SUCCESS_NOTIFICATION_DURATION_MS = 5000;
30
- export function closeNotification(snackbarId) {
31
- closeSnackbar(snackbarId);
32
- }
30
+ export const closeNotification = () => {
31
+ closeSnackbar();
32
+ };
33
33
  /**
34
34
  * Convenience method to allow sending notifications to user with a one-liner.
35
35
  * Simply wraps @Notification function
@@ -38,12 +38,12 @@ export function closeNotification(snackbarId) {
38
38
  * @param description More complete description of the notification
39
39
  * @param placement Where to show notification. Defaults to top-right.
40
40
  */
41
- export function sendNotification(variantType, message, description = "",
41
+ export const sendNotification = (variantType, message, description = "",
42
42
  // eslint-disable-next-line unicorn/no-object-as-default-parameter
43
43
  placement = {
44
44
  vertical: "top",
45
45
  horizontal: "right",
46
- }) {
46
+ }) => {
47
47
  // Log a copy to the console for troubleshooting
48
48
  const descriptionAsString = typeof description === "string" ? description : renderToString(description);
49
49
  console.debug(`Notification: Message: "${message}" Description: "${descriptionAsString}"`);
@@ -76,4 +76,4 @@ placement = {
76
76
  key: baseId,
77
77
  variant: NotificationType[variantType],
78
78
  });
79
- }
79
+ };
@@ -14,7 +14,7 @@ interface ErrorBoundaryProps {
14
14
  readonly children: ReactNode;
15
15
  }
16
16
  /**
17
- * Implements a system-wide error handler for NextJS pages in our app.
17
+ * Implements a system-wide error handler for Next.js pages in our app.
18
18
  * Taken from here: https://nextjs.org/docs/advanced-features/error-handling
19
19
  *
20
20
  * Note: as of writing (April 2023) ReactJS does not support error boundaries for functional components (like all of
@@ -33,6 +33,6 @@ export declare class ErrorBoundary extends Component<ErrorBoundaryProps, ErrorBo
33
33
  };
34
34
  constructor(props: ErrorBoundaryProps);
35
35
  componentDidCatch(error: unknown, errorInfo: ErrorInfo): void;
36
- render(): string | number | boolean | Iterable<ReactNode> | import("react").PromiseLikeOfReactNode | import("react/jsx-runtime").JSX.Element;
36
+ render(): ReactNode;
37
37
  }
38
38
  export {};
@@ -17,7 +17,7 @@ limitations under the License.
17
17
  import { Component } from "react";
18
18
  import ErrorPage from "./ErrorPage.js";
19
19
  /**
20
- * Implements a system-wide error handler for NextJS pages in our app.
20
+ * Implements a system-wide error handler for Next.js pages in our app.
21
21
  * Taken from here: https://nextjs.org/docs/advanced-features/error-handling
22
22
  *
23
23
  * Note: as of writing (April 2023) ReactJS does not support error boundaries for functional components (like all of
@@ -17,10 +17,11 @@ limitations under the License.
17
17
  import Box from "@mui/material/Box";
18
18
  import { useRouter } from "next/router.js";
19
19
  import { LOGO } from "../../const.js";
20
- import { useEnvironmentStore } from "../../state/environment.js";
20
+ import { useEnvironmentStore } from "../../state/Environment.js";
21
21
  import { useUserInfoStore } from "../../state/UserInfo.js";
22
22
  import { smartSignOut, useAuthentication } from "../../utils/Authentication.js";
23
23
  import { NeuroAIBreadcrumbs } from "../Common/Breadcrumbs.js";
24
+ import { Footer } from "../Common/Footer.js";
24
25
  import { Navbar } from "../Common/Navbar.js";
25
26
  /**
26
27
  * This is the page that will be shown to users when the outer error boundary is triggered
@@ -28,7 +29,7 @@ import { Navbar } from "../Common/Navbar.js";
28
29
  * @param errorText Error text to be displayed
29
30
  */
30
31
  export default function ErrorPage({ id, errorText }) {
31
- const { auth0ClientId, auth0Domain, supportEmailAddress } = useEnvironmentStore();
32
+ const { auth0ClientId, auth0Domain, supportEmailAddress, logoServiceToken } = useEnvironmentStore();
32
33
  // Access NextJS router
33
34
  const router = useRouter();
34
35
  // Access user info store
@@ -36,11 +37,11 @@ export default function ErrorPage({ id, errorText }) {
36
37
  // Infer authentication type
37
38
  const authenticationType = currentUser ? `ALB using ${oidcProvider}` : "NextAuth";
38
39
  const { data: { user: userInfo } = {} } = useAuthentication();
39
- async function handleSignOut() {
40
+ const handleSignOut = async () => {
40
41
  // Clear our state storage variables
41
42
  setCurrentUser(undefined);
42
43
  setPicture(undefined);
43
44
  await smartSignOut(currentUser, auth0Domain, auth0ClientId, oidcProvider);
44
- }
45
- return (_jsxs(_Fragment, { children: [_jsx(Navbar, { id: "nav-bar", logo: LOGO, query: router.query, pathname: router.pathname, authenticationType: authenticationType, signOut: handleSignOut, supportEmailAddress: supportEmailAddress, userInfo: userInfo }), _jsxs(Box, { id: id, sx: { marginLeft: "1rem" }, children: [_jsx(NeuroAIBreadcrumbs, {}), _jsx("h4", { id: "error-header", style: { color: "var(--bs-red)", marginTop: "1rem" }, children: "Oops, an internal error occurred on our end." }), _jsxs("div", { id: "error-div-1", children: [_jsxs(Box, { id: "no-need-to-worry", sx: { marginBottom: "1.5rem" }, children: [_jsx("b", { id: "bold-1", children: "There's no need to worry \u2013 you didn't do anything wrong." }), " This is a bug in our server and we'll fix it as soon as possible."] }), _jsx(Box, { id: "try-these-steps", sx: { marginBottom: "1.5rem" }, children: "To attempt to recover from the error, try these steps:" }), _jsx(Box, { id: "refresh-page", sx: { marginBottom: "1.5rem" }, children: _jsxs("ul", { id: "error-boundary-advice-list", className: "list-decimal list-inside", children: [_jsx("li", { id: "error-advice-refresh", children: "Refresh the page to see if the error goes away." }), _jsx("li", { id: "error-advice-reload", children: "Close and re-open your browser, then navigate back to the page where you encountered the error." })] }) }), "If none of that helps, please report the following error to the LEAF team:"] }), _jsx("div", { id: "error-text-div", style: { fontFamily: "monospace", marginTop: "1.5rem", marginBottom: "1.5rem" }, children: errorText }), "More information may be available in the browser console. Please include such information in your report if possible."] })] }));
45
+ };
46
+ return (_jsxs(_Fragment, { children: [_jsx(Navbar, { authenticationType: authenticationType, id: "nav-bar", logo: LOGO, logoServiceToken: logoServiceToken, pathname: router.pathname, query: router.query, signOut: handleSignOut, supportEmailAddress: supportEmailAddress, userInfo: userInfo }), _jsxs(Box, { id: id, sx: { marginLeft: "1rem" }, children: [_jsx(NeuroAIBreadcrumbs, {}), _jsx("h4", { id: "error-header", style: { color: "var(--bs-red)", marginTop: "1rem" }, children: "Oops, an internal error occurred on our end." }), _jsxs("div", { id: "error-div-1", children: [_jsxs(Box, { id: "no-need-to-worry", sx: { marginBottom: "1.5rem" }, children: [_jsx("b", { id: "bold-1", children: "There's no need to worry \u2013 you didn't do anything wrong." }), " This is a bug in our server and we'll fix it as soon as possible."] }), _jsx(Box, { id: "try-these-steps", sx: { marginBottom: "1.5rem" }, children: "To attempt to recover from the error, try these steps:" }), _jsx(Box, { id: "refresh-page", sx: { marginBottom: "1.5rem" }, children: _jsxs("ul", { id: "error-boundary-advice-list", className: "list-decimal list-inside", children: [_jsx("li", { id: "error-advice-refresh", children: "Refresh the page to see if the error goes away." }), _jsx("li", { id: "error-advice-reload", children: "Close and re-open your browser, then navigate back to the page where you encountered the error." })] }) }), "If none of that helps, please report the following error to the LEAF team:"] }), _jsx("div", { id: "error-text-div", style: { fontFamily: "monospace", marginTop: "1.5rem", marginBottom: "1.5rem" }, children: errorText }), "More information may be available in the browser console. Please include such information in your report if possible."] }), _jsx(Footer, { supportEmailAddress: supportEmailAddress, logoLinkUrl: "https://www.cognizant.com/", logoUrl: "/cognizant-logo-white.svg" })] }));
46
47
  }
@@ -0,0 +1,17 @@
1
+ import { ChatMessage, ChatMessageType } from "../../generated/neuro-san/NeuroSanClient.js";
2
+ export interface AgentConversation {
3
+ agents: Set<string>;
4
+ id: string;
5
+ startedAt: Date;
6
+ text?: string;
7
+ type: ChatMessageType;
8
+ }
9
+ export declare const isFinalMessage: (chatMessage: {
10
+ structure?: {
11
+ tool_end?: boolean;
12
+ total_tokens?: number;
13
+ };
14
+ text?: string;
15
+ }) => boolean;
16
+ export declare const createConversation: (agents: string[], text: string, type: ChatMessageType) => AgentConversation;
17
+ export declare const extractConversations: (chatMessage: ChatMessage, currentConversations: AgentConversation[] | null) => AgentConversation[] | null;
@@ -0,0 +1,77 @@
1
+ /*
2
+ Copyright 2025 Cognizant Technology Solutions Corp, www.cognizant.com.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */
16
+ import { ChatMessageType } from "../../generated/neuro-san/NeuroSanClient.js";
17
+ export const isFinalMessage = (chatMessage) => {
18
+ const isAgentFinalResponse = chatMessage.structure?.total_tokens;
19
+ const isCodedToolFinalResponse = chatMessage.structure?.tool_end;
20
+ return Boolean(isAgentFinalResponse || isCodedToolFinalResponse);
21
+ };
22
+ export const createConversation = (agents, text, type) => ({
23
+ // Could use crypto.randomUUID, but it's only available under HTTPS, and don't want to use a different
24
+ // solution for HTTP on localhost.
25
+ // eslint-disable-next-line newline-per-chained-call
26
+ id: `conv_${Date.now()}${Math.random().toString(36).slice(2, 10)}`,
27
+ agents: new Set(agents),
28
+ startedAt: new Date(),
29
+ text,
30
+ type,
31
+ });
32
+ const processAgentCompletion = (conversations, tools) => {
33
+ const toolsToRemove = new Set(tools);
34
+ // For each conversation:
35
+ // 1) Remove all agents whose tool is in toolsToRemove
36
+ // 2) Only keep conversations that still have agents left
37
+ return (conversations
38
+ .map((conv) => {
39
+ // Remove all matching tools from this conversation's agents
40
+ const updatedAgents = new Set([...conv.agents].filter((agent) => !toolsToRemove.has(agent)));
41
+ // Return a new conversation object with updated agents
42
+ return { ...conv, agents: updatedAgents };
43
+ })
44
+ // Filter out conversations that have no agents left
45
+ .filter((conv) => conv.agents.size > 0));
46
+ };
47
+ export const extractConversations = (chatMessage, currentConversations) => {
48
+ const updatedConversations = [...(currentConversations || [])];
49
+ // If there are no origins in a chat message, return current state
50
+ if (!chatMessage?.origin?.length) {
51
+ return currentConversations;
52
+ }
53
+ const isFinal = isFinalMessage(chatMessage);
54
+ const agents = chatMessage.origin.map((originItem) => originItem.tool).filter(Boolean);
55
+ let finalConversations;
56
+ // Check if this is an AGENT message and if it's a final message, i.e. an end event (could be an AGENT final
57
+ // message or coded tool end, see isFinalMessage function)
58
+ if (chatMessage.type === ChatMessageType.AGENT && isFinal) {
59
+ const currentConversationsToUpdate = processAgentCompletion(updatedConversations, agents);
60
+ finalConversations = currentConversationsToUpdate.length === 0 ? [] : currentConversationsToUpdate;
61
+ }
62
+ else {
63
+ // Create a new conversation for this communication path
64
+ let inquiryText;
65
+ const params = chatMessage.structure?.["params"];
66
+ if (params && typeof params === "object" && "inquiry" in params) {
67
+ inquiryText = params.inquiry;
68
+ }
69
+ const textToShow = inquiryText || chatMessage.text;
70
+ // Show inquiry (from structure), that's only for networks that use AAOSA with a JSON format.
71
+ // Otherwise, show the raw data from the `text` field of the chat message.
72
+ const newConversation = createConversation(agents, textToShow, chatMessage.type);
73
+ updatedConversations.push(newConversation);
74
+ finalConversations = updatedConversations;
75
+ }
76
+ return finalConversations;
77
+ };
@@ -0,0 +1,12 @@
1
+ import { Origin } from "../../generated/neuro-san/NeuroSanClient.js";
2
+ /**
3
+ * Given a map of agent counts and a list of origins, return an updated map of agent counts that includes the
4
+ * counts from the origins.
5
+ * @param agentCountsMap Existing map of agent counts, where the key is the agent name and the value is the
6
+ * count of that agent.
7
+ * @param origins List of origins, where each origin has a "tool" property that corresponds to an agent name.
8
+ * @return Updated map of agent counts that includes counts from the origins. If an agent from the origins is not
9
+ * already in the map, it will be added with a count of 1. If it is already in the map, its count will be
10
+ * incremented by 1.
11
+ */
12
+ export declare const getUpdatedAgentCounts: (agentCountsMap: Map<string, number>, origins: readonly Origin[]) => Map<string, number>;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Given a map of agent counts and a list of origins, return an updated map of agent counts that includes the
3
+ * counts from the origins.
4
+ * @param agentCountsMap Existing map of agent counts, where the key is the agent name and the value is the
5
+ * count of that agent.
6
+ * @param origins List of origins, where each origin has a "tool" property that corresponds to an agent name.
7
+ * @return Updated map of agent counts that includes counts from the origins. If an agent from the origins is not
8
+ * already in the map, it will be added with a count of 1. If it is already in the map, its count will be
9
+ * incremented by 1.
10
+ */
11
+ export const getUpdatedAgentCounts = (agentCountsMap, origins) => {
12
+ if (!origins?.length) {
13
+ // If there are no origins, return the existing counts map without modification
14
+ return agentCountsMap;
15
+ }
16
+ return origins.reduce((acc, { tool }) => {
17
+ // If the agent is not already in the counts map, initialize it to 0 aka "upsert"
18
+ acc.set(tool, (acc.get(tool) || 0) + 1);
19
+ return acc;
20
+ }, new Map(agentCountsMap));
21
+ };
@@ -1,20 +1,22 @@
1
1
  import { Dispatch, FC, SetStateAction } from "react";
2
- import { Edge, EdgeProps } from "reactflow";
2
+ import { AgentConversation } from "./AgentConversations.js";
3
+ import { ThoughtBubbleEdgeShape } from "./ThoughtBubbleEdge.js";
4
+ import { AgentIconSuggestions } from "../../controller/Types/AgentIconSuggestions.js";
3
5
  import { ConnectivityInfo } from "../../generated/neuro-san/NeuroSanClient.js";
4
- import { AgentConversation } from "../../utils/agentConversations.js";
5
6
  export interface AgentFlowProps {
6
7
  readonly agentCounts?: Map<string, number>;
8
+ readonly agentIconSuggestions?: AgentIconSuggestions;
7
9
  readonly agentsInNetwork: ConnectivityInfo[];
8
10
  readonly currentConversations?: AgentConversation[] | null;
9
11
  readonly id: string;
10
12
  readonly isAwaitingLlm?: boolean;
11
13
  readonly isStreaming?: boolean;
12
14
  readonly thoughtBubbleEdges: Map<string, {
13
- edge: Edge<EdgeProps>;
15
+ edge: ThoughtBubbleEdgeShape;
14
16
  timestamp: number;
15
17
  }>;
16
18
  readonly setThoughtBubbleEdges: Dispatch<SetStateAction<Map<string, {
17
- edge: Edge<EdgeProps>;
19
+ edge: ThoughtBubbleEdgeShape;
18
20
  timestamp: number;
19
21
  }>>>;
20
22
  }