@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
@@ -8,7 +8,7 @@ export declare const AD_TENANT_ID = "de08c407-19b9-427d-9fe8-edf254300ca7";
8
8
  * being handled by the app via NextAuth. This way existing pages only need trivial changes to use this hook instead
9
9
  * of NextAuth's useSession hook.
10
10
  */
11
- export declare function useAuthentication(): {
11
+ export declare const useAuthentication: () => {
12
12
  data: {
13
13
  user: {
14
14
  name: string;
@@ -28,4 +28,4 @@ export declare function useAuthentication(): {
28
28
  * @return Nothing, but executes the sign-out process.
29
29
  *
30
30
  */
31
- export declare function smartSignOut(currentUser: string, auth0Domain: string, auth0ClientId: string, oidcProvider: OidcProvider): Promise<void>;
31
+ export declare const smartSignOut: (currentUser: string, auth0Domain: string, auth0ClientId: string, oidcProvider: OidcProvider) => Promise<void>;
@@ -26,7 +26,7 @@ export const AD_TENANT_ID = "de08c407-19b9-427d-9fe8-edf254300ca7";
26
26
  * being handled by the app via NextAuth. This way existing pages only need trivial changes to use this hook instead
27
27
  * of NextAuth's useSession hook.
28
28
  */
29
- export function useAuthentication() {
29
+ export const useAuthentication = () => {
30
30
  const { data: session } = useSession();
31
31
  const { currentUser: albUser, picture: albPicture } = useUserInfoStore();
32
32
  // Return the user data in the same format as NextAuth's useSession hook. We prioritize the ALB info if we have
@@ -39,7 +39,7 @@ export function useAuthentication() {
39
39
  },
40
40
  },
41
41
  };
42
- }
42
+ };
43
43
  /**
44
44
  * Create the logout URL for Auth0.
45
45
  * @param oidcProvider The OIDC provider. See OIDC doc for more details.
@@ -47,7 +47,7 @@ export function useAuthentication() {
47
47
  * @param auth0ClientId The Auth0 client ID. See Auth0 doc for more details. Identifies the app being used in Auth0.
48
48
  * @return The logout URL.
49
49
  */
50
- function createAuth0LogoutUrl(oidcProvider, auth0Domain, auth0ClientId) {
50
+ const createAuth0LogoutUrl = (oidcProvider, auth0Domain, auth0ClientId) => {
51
51
  switch (oidcProvider) {
52
52
  case "AD":
53
53
  return `https://login.microsoftonline.com/${AD_TENANT_ID}/oauth2/v2.0/logout`;
@@ -58,7 +58,7 @@ function createAuth0LogoutUrl(oidcProvider, auth0Domain, auth0ClientId) {
58
58
  return `https://${auth0Domain}/v2/logout?client_id=${auth0ClientId}&returnTo=${returnTo}`;
59
59
  }
60
60
  }
61
- }
61
+ };
62
62
  /**
63
63
  * Smart sign out function that abstracts away the authentication provider.
64
64
  * We are migrating to ALB-based authentication, instead of it being handled by the app via NextAuth. This function
@@ -71,7 +71,7 @@ function createAuth0LogoutUrl(oidcProvider, auth0Domain, auth0ClientId) {
71
71
  * @return Nothing, but executes the sign-out process.
72
72
  *
73
73
  */
74
- export async function smartSignOut(currentUser, auth0Domain, auth0ClientId, oidcProvider) {
74
+ export const smartSignOut = async (currentUser, auth0Domain, auth0ClientId, oidcProvider) => {
75
75
  if (currentUser === undefined) {
76
76
  // Don't know what authentication provider we're using, so just return
77
77
  return;
@@ -91,4 +91,4 @@ export async function smartSignOut(currentUser, auth0Domain, auth0ClientId, oidc
91
91
  }));
92
92
  navigateToUrl(createAuth0LogoutUrl(oidcProvider, auth0Domain, auth0ClientId));
93
93
  }
94
- }
94
+ };
@@ -4,7 +4,7 @@
4
4
  * @param input Input to be tested
5
5
  * @returns True if input contains only whitespace, false otherwise
6
6
  */
7
- export declare function hasOnlyWhitespace(input: string): boolean;
7
+ export declare const hasOnlyWhitespace: (input: string) => boolean;
8
8
  /**
9
9
  * Extracts the ID from a model ID
10
10
  *
@@ -18,7 +18,7 @@ export declare function hasOnlyWhitespace(input: string): boolean;
18
18
  * = "67fb86d3-9047-4ce0-0d42-4e3d3b0f715e"
19
19
  * ```
20
20
  */
21
- export declare function extractId(modelId: string, modelType: "prescriptor" | "rio"): string;
21
+ export declare const extractId: (modelId: string, modelType: "prescriptor" | "rio") => string;
22
22
  /**
23
23
  * Hashes a string using MD5. For example: for generating keys for React nodes from a longer string identifer.
24
24
  *
@@ -23,9 +23,7 @@ import { createHash } from "crypto";
23
23
  * @param input Input to be tested
24
24
  * @returns True if input contains only whitespace, false otherwise
25
25
  */
26
- export function hasOnlyWhitespace(input) {
27
- return input?.trim().length === 0;
28
- }
26
+ export const hasOnlyWhitespace = (input) => input?.trim().length === 0;
29
27
  /**
30
28
  * Extracts the ID from a model ID
31
29
  *
@@ -39,7 +37,7 @@ export function hasOnlyWhitespace(input) {
39
37
  * = "67fb86d3-9047-4ce0-0d42-4e3d3b0f715e"
40
38
  * ```
41
39
  */
42
- export function extractId(modelId, modelType) {
40
+ export const extractId = (modelId, modelType) => {
43
41
  if (!modelId || !modelType || !modelId.includes(modelType)) {
44
42
  return "";
45
43
  }
@@ -49,7 +47,7 @@ export function extractId(modelId, modelType) {
49
47
  .split("-") // split by hyphens
50
48
  .slice(0, -1) // remove the last element
51
49
  .join("-"); // join with hyphens
52
- }
50
+ };
53
51
  /**
54
52
  * Hashes a string using MD5. For example: for generating keys for React nodes from a longer string identifer.
55
53
  *
@@ -1 +1 @@
1
- export declare function getTitleBase(): string;
1
+ export declare const getTitleBase: () => string;
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
16
  // Miscellaneous utilities for dealing with browser tab title
17
- export function getTitleBase() {
17
+ export const getTitleBase = () => {
18
18
  const subdomain = window.location.host.split(".")[0];
19
19
  return `${subdomain[0].toUpperCase()}${subdomain.substring(1)}`;
20
- }
20
+ };
@@ -1 +1 @@
1
- export declare function useLocalStorage(key: string, initialValue: unknown): any[];
1
+ export declare const useLocalStorage: (key: string, initialValue: unknown) => any[];
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
14
14
  limitations under the License.
15
15
  */
16
16
  import { useState } from "react";
17
- export function useLocalStorage(key, initialValue) {
17
+ export const useLocalStorage = (key, initialValue) => {
18
18
  // State to store our value
19
19
  // Pass initial state function to useState so logic is only executed once
20
20
  const [storedValue, setStoredValue] = useState(() => {
@@ -24,7 +24,7 @@ export function useLocalStorage(key, initialValue) {
24
24
  try {
25
25
  // Get from local storage by key
26
26
  const item = window.localStorage.getItem(key);
27
- // Parse stored json or if none return initialValue
27
+ // Parse stored JSON or if none return initialValue
28
28
  return item ? JSON.parse(item) : initialValue;
29
29
  }
30
30
  catch (error) {
@@ -52,4 +52,4 @@ export function useLocalStorage(key, initialValue) {
52
52
  }
53
53
  };
54
54
  return [storedValue, setValue];
55
- }
55
+ };
@@ -1,2 +1,2 @@
1
- import { Theme } from "@mui/material";
1
+ import { Theme } from "@mui/material/styles";
2
2
  export declare const getZIndex: (layer: number, appTheme: Theme) => number;
@@ -1,18 +1,6 @@
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
- */
1
+ // MUI zIndex information:
2
+ // github.com/mui/material-ui/blob/master/packages/mui-material/src/styles/zIndex.js
3
+ // mui.com/material-ui/customization/z-index/
16
4
  const DEFAULT_Z_INDEX = 500;
17
5
  export const getZIndex = (layer, appTheme) => {
18
6
  switch (layer) {
package/package.json CHANGED
@@ -1,25 +1,25 @@
1
1
  {
2
2
  "name": "@cognizant-ai-lab/ui-common",
3
- "version": "1.3.3",
3
+ "version": "1.4.0",
4
4
  "type": "module",
5
5
  "scripts": {
6
- "build": "yarn clean && yarn generate && tsc --project tsconfig.build.json && fix-esm-import-path dist > /dev/null",
6
+ "build": "yarn clean && yarn generate && yarn run --top-level tsc --project tsconfig.build.json && fix-esm-import-path dist > /dev/null",
7
7
  "clean": "rm -rf dist generated",
8
- "generate": "rm -rf generated && ./build_scripts/do_openapi_generate.sh"
8
+ "generate": "rm -rf generated && ./build_scripts/do_openapi_generate.sh",
9
+ "prepack": "echo PREPACK_RUNNING && yarn build"
9
10
  },
10
11
  "dependencies": {
11
- "@langchain/core": "0.2.36",
12
- "dagre": "0.8.5",
12
+ "@dagrejs/dagre": "1.0.4",
13
+ "@langchain/core": "1.1.17",
14
+ "@xyflow/react": "12.10.1",
13
15
  "http-status": "1.7.3",
14
16
  "jsonrepair": "3.8.0",
15
- "lodash-es": "4.17.21",
16
- "next": "15.4.6",
17
- "next-auth": "5.0.0-beta.20",
18
- "notistack": "3.0.1",
19
- "react-dom": "18.2.0",
20
- "react-markdown": "9.0.1",
21
- "react-syntax-highlighter": "15.5.0",
22
- "reactflow": "11.10.2",
17
+ "lodash-es": "4.17.23",
18
+ "next": "16.1.6",
19
+ "notistack": "3.0.2",
20
+ "react-dom": "19.2.4",
21
+ "react-markdown": "10.1.0",
22
+ "react-syntax-highlighter": "16.1.0",
23
23
  "rehype-raw": "7.0.0",
24
24
  "rehype-slug": "6.0.0",
25
25
  "zustand": "4.4.7"
@@ -27,13 +27,12 @@
27
27
  "devDependencies": {
28
28
  "@babel/core": "7.23.7",
29
29
  "@babel/preset-env": "7.28.3",
30
- "@types/dagre": "0.7.53",
31
30
  "@types/lodash-es": "4.17.12",
32
31
  "@types/node": "20.11.5",
33
- "@types/react": "18.2.0",
34
- "@types/react-dom": "18.2.0",
32
+ "@types/react": "19.2.14",
33
+ "@types/react-dom": "19.2.3",
35
34
  "@types/react-syntax-highlighter": "15.5.13",
36
- "babel-jest": "30.0.5",
35
+ "babel-jest": "30.2.0",
37
36
  "fix-esm-import-path": "1.10.3",
38
37
  "globals": "16.3.0",
39
38
  "openapi-typescript": "7.8.0"
@@ -43,8 +42,11 @@
43
42
  "@emotion/styled": "^11.13.0",
44
43
  "@mui/icons-material": "^7.3.1",
45
44
  "@mui/material": "^7.3.1",
46
- "react": "^18.2.0",
47
- "react-dom": "^18.2.0",
45
+ "@mui/system": "^7.3.1",
46
+ "@mui/x-tree-view": "^8.22.0",
47
+ "next-auth": "5.0.0-beta.30",
48
+ "react": "^19.2.4",
49
+ "react-dom": "^19.2.4",
48
50
  "typescript": "^5.9.2"
49
51
  },
50
52
  "repository": {
@@ -52,8 +54,8 @@
52
54
  "url": "git+https://github.com/cognizant-ai-lab/neuro-san-ui.git"
53
55
  },
54
56
  "publishConfig": {
55
- "registry": "https://npm.pkg.github.com/",
56
- "repository": "https://github.com/cognizant-ai-lab/neuro-san-ui"
57
+ "registry": "https://registry.npmjs.org/",
58
+ "access": "public"
57
59
  },
58
60
  "types": "dist/index.d.ts",
59
61
  "exports": {
@@ -1,12 +0,0 @@
1
- import { FC } from "react";
2
- interface SidebarProps {
3
- customURLCallback: (url: string) => void;
4
- customURLLocalStorage?: string;
5
- id: string;
6
- isAwaitingLlm: boolean;
7
- networks: string[];
8
- selectedNetwork: string;
9
- setSelectedNetwork: (network: string) => void;
10
- }
11
- export declare const Sidebar: FC<SidebarProps>;
12
- export {};
@@ -1,7 +0,0 @@
1
- /**
2
- * Helper to determine if dark mode is active based on mode and systemMode.
3
- * @param mode Current mode setting: "light", "dark", or "system"
4
- * @param systemMode If mode is "system", this indicates the system preference: "light" or "dark"
5
- * @returns true if dark mode is active, false otherwise
6
- */
7
- export declare const isDarkMode: (mode: "light" | "dark" | "system", systemMode: "light" | "dark") => boolean;
@@ -1,7 +0,0 @@
1
- /**
2
- * Helper to determine if dark mode is active based on mode and systemMode.
3
- * @param mode Current mode setting: "light", "dark", or "system"
4
- * @param systemMode If mode is "system", this indicates the system preference: "light" or "dark"
5
- * @returns true if dark mode is active, false otherwise
6
- */
7
- export const isDarkMode = (mode, systemMode) => mode === "dark" || (mode === "system" && systemMode === "dark");
@@ -1,24 +0,0 @@
1
- import { ChatMessageType, Origin } from "../generated/neuro-san/NeuroSanClient.js";
2
- export interface AgentConversationBase {
3
- agents: Set<string>;
4
- startedAt: Date;
5
- text?: string;
6
- type: ChatMessageType;
7
- }
8
- export interface AgentConversation extends AgentConversationBase {
9
- id: string;
10
- }
11
- export declare const isFinalMessage: (chatMessage: {
12
- structure?: {
13
- tool_end?: boolean;
14
- total_tokens?: number;
15
- };
16
- text?: string;
17
- }) => boolean;
18
- export declare const createConversation: (agents: string[], text: string, type: ChatMessageType) => AgentConversation;
19
- export declare const updateAgentCounts: (agentCountsMap: Map<string, number>, origins: readonly Origin[]) => Map<string, number>;
20
- export declare const processChatChunk: (chunk: string, agentCountsMap: Map<string, number>, currentConversations: AgentConversation[] | null) => {
21
- success: boolean;
22
- newCounts: Map<string, number>;
23
- newConversations: AgentConversation[] | null;
24
- };
@@ -1,113 +0,0 @@
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 { chatMessageFromChunk } from "../components/AgentChat/Utils.js";
17
- import { NotificationType, sendNotification } from "../components/Common/notification.js";
18
- import { ChatMessageType } from "../generated/neuro-san/NeuroSanClient.js";
19
- export const isFinalMessage = (chatMessage) => {
20
- const isAgentFinalResponse = chatMessage.structure?.total_tokens;
21
- const isCodedToolFinalResponse = chatMessage.structure?.tool_end;
22
- return Boolean(isAgentFinalResponse || isCodedToolFinalResponse);
23
- };
24
- export const createConversation = (agents, text, type) => ({
25
- // Could use crypto.randomUUID, but it's only available under HTTPS, and don't want to use a different
26
- // solution for HTTP on localhost.
27
- // eslint-disable-next-line newline-per-chained-call
28
- id: `conv_${Date.now()}${Math.random().toString(36).slice(2, 10)}`,
29
- agents: new Set(agents),
30
- startedAt: new Date(),
31
- text,
32
- type,
33
- });
34
- export const updateAgentCounts = (agentCountsMap, origins) => {
35
- // Update agent counts.
36
- // Note: we increment an agent's count each time it appears in the origin info, but another strategy
37
- // would be to only count an agent when it is the "end destination" of the chain. Needs some thought to
38
- // determine which is more useful.
39
- return origins.reduce((acc, { tool }) => {
40
- // If the agent is not already in the counts map, initialize it to 0 aka "upsert"
41
- acc.set(tool, (acc.get(tool) || 0) + 1);
42
- return acc;
43
- }, new Map(agentCountsMap));
44
- };
45
- const processAgentCompletion = (conversations, tools) => {
46
- const toolsToRemove = new Set(tools);
47
- // For each conversation:
48
- // 1) Remove all agents whose tool is in toolsToRemove
49
- // 2) Only keep conversations that still have agents left
50
- return (conversations
51
- .map((conv) => {
52
- // Remove all matching tools from this conversation's agents
53
- const updatedAgents = new Set([...conv.agents].filter((agent) => !toolsToRemove.has(agent)));
54
- // Return a new conversation object with updated agents
55
- return { ...conv, agents: updatedAgents };
56
- })
57
- // Filter out conversations that have no agents left
58
- .filter((conv) => conv.agents.size > 0));
59
- };
60
- export const processChatChunk = (chunk, agentCountsMap, currentConversations) => {
61
- try {
62
- const updatedConversations = [...(currentConversations || [])];
63
- // Get chat message if it's a known message type
64
- const chatMessage = chatMessageFromChunk(chunk);
65
- // If there are no origins in a chat message, return current state
66
- if (!chatMessage?.origin?.length) {
67
- return {
68
- success: true,
69
- newCounts: agentCountsMap,
70
- newConversations: currentConversations,
71
- };
72
- }
73
- // Update agent counts
74
- const updatedCounts = updateAgentCounts(agentCountsMap, chatMessage.origin);
75
- const isFinal = isFinalMessage(chatMessage);
76
- const agents = chatMessage.origin.map((originItem) => originItem.tool).filter(Boolean);
77
- let finalConversations;
78
- // Check if this is an AGENT message and if it's a final message, i.e. an end event (could be an AGENT final
79
- // message or coded tool end, see isFinalMessage function)
80
- if (chatMessage.type === ChatMessageType.AGENT && isFinal) {
81
- const currentConversationsToUpdate = processAgentCompletion(updatedConversations, agents);
82
- finalConversations = currentConversationsToUpdate.length === 0 ? null : currentConversationsToUpdate;
83
- }
84
- else {
85
- // Create a new conversation for this communication path
86
- let inquiryText;
87
- const params = chatMessage.structure?.["params"];
88
- if (params && typeof params === "object" && "inquiry" in params) {
89
- inquiryText = params.inquiry;
90
- }
91
- const textToShow = inquiryText || chatMessage.text;
92
- // Show inquiry (from structure), that's only for networks that use AAOSA with a JSON format.
93
- // Otherwise show the raw data from the `text` field of the chat message.
94
- const newConversation = createConversation(agents, textToShow, chatMessage.type);
95
- updatedConversations.push(newConversation);
96
- finalConversations = updatedConversations;
97
- }
98
- return {
99
- success: true,
100
- newCounts: updatedCounts,
101
- newConversations: finalConversations,
102
- };
103
- }
104
- catch (error) {
105
- sendNotification(NotificationType.error, "Agent conversation error");
106
- console.error("Agent conversation error:", error);
107
- return {
108
- success: false,
109
- newCounts: agentCountsMap,
110
- newConversations: currentConversations,
111
- };
112
- }
113
- };