@cognizant-ai-lab/ui-common 1.3.3

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 (108) hide show
  1. package/dist/components/AgentChat/ChatCommon.d.ts +94 -0
  2. package/dist/components/AgentChat/ChatCommon.js +581 -0
  3. package/dist/components/AgentChat/ControlButtons.d.ts +16 -0
  4. package/dist/components/AgentChat/ControlButtons.js +24 -0
  5. package/dist/components/AgentChat/FormattedMarkdown.d.ts +32 -0
  6. package/dist/components/AgentChat/FormattedMarkdown.js +82 -0
  7. package/dist/components/AgentChat/Greetings.d.ts +1 -0
  8. package/dist/components/AgentChat/Greetings.js +38 -0
  9. package/dist/components/AgentChat/LlmChatButton.d.ts +12 -0
  10. package/dist/components/AgentChat/LlmChatButton.js +33 -0
  11. package/dist/components/AgentChat/SendButton.d.ts +12 -0
  12. package/dist/components/AgentChat/SendButton.js +28 -0
  13. package/dist/components/AgentChat/SyntaxHighlighterThemes.d.ts +14 -0
  14. package/dist/components/AgentChat/SyntaxHighlighterThemes.js +27 -0
  15. package/dist/components/AgentChat/Types.d.ts +17 -0
  16. package/dist/components/AgentChat/Types.js +26 -0
  17. package/dist/components/AgentChat/UserQueryDisplay.d.ts +5 -0
  18. package/dist/components/AgentChat/UserQueryDisplay.js +33 -0
  19. package/dist/components/AgentChat/Utils.d.ts +11 -0
  20. package/dist/components/AgentChat/Utils.js +64 -0
  21. package/dist/components/AgentChat/VoiceChat/MicrophoneButton.d.ts +29 -0
  22. package/dist/components/AgentChat/VoiceChat/MicrophoneButton.js +55 -0
  23. package/dist/components/AgentChat/VoiceChat/VoiceChat.d.ts +33 -0
  24. package/dist/components/AgentChat/VoiceChat/VoiceChat.js +180 -0
  25. package/dist/components/Authentication/Auth.d.ts +14 -0
  26. package/dist/components/Authentication/Auth.js +58 -0
  27. package/dist/components/ChatBot/ChatBot.d.ts +20 -0
  28. package/dist/components/ChatBot/ChatBot.js +75 -0
  29. package/dist/components/Common/Breadcrumbs.d.ts +6 -0
  30. package/dist/components/Common/Breadcrumbs.js +36 -0
  31. package/dist/components/Common/LlmChatOptionsButton.d.ts +9 -0
  32. package/dist/components/Common/LlmChatOptionsButton.js +31 -0
  33. package/dist/components/Common/LoadingSpinner.d.ts +10 -0
  34. package/dist/components/Common/LoadingSpinner.js +24 -0
  35. package/dist/components/Common/MUIAccordion.d.ts +17 -0
  36. package/dist/components/Common/MUIAccordion.js +76 -0
  37. package/dist/components/Common/MUIAlert.d.ts +11 -0
  38. package/dist/components/Common/MUIAlert.js +41 -0
  39. package/dist/components/Common/MUIDialog.d.ts +16 -0
  40. package/dist/components/Common/MUIDialog.js +40 -0
  41. package/dist/components/Common/Navbar.d.ts +15 -0
  42. package/dist/components/Common/Navbar.js +137 -0
  43. package/dist/components/Common/PageLoader.d.ts +5 -0
  44. package/dist/components/Common/PageLoader.js +26 -0
  45. package/dist/components/Common/Snackbar.d.ts +5 -0
  46. package/dist/components/Common/Snackbar.js +84 -0
  47. package/dist/components/Common/confirmationModal.d.ts +14 -0
  48. package/dist/components/Common/confirmationModal.js +65 -0
  49. package/dist/components/Common/notification.d.ts +18 -0
  50. package/dist/components/Common/notification.js +79 -0
  51. package/dist/components/ErrorPage/ErrorBoundary.d.ts +38 -0
  52. package/dist/components/ErrorPage/ErrorBoundary.js +77 -0
  53. package/dist/components/ErrorPage/ErrorPage.d.ts +12 -0
  54. package/dist/components/ErrorPage/ErrorPage.js +46 -0
  55. package/dist/components/MultiAgentAccelerator/AgentFlow.d.ts +21 -0
  56. package/dist/components/MultiAgentAccelerator/AgentFlow.js +394 -0
  57. package/dist/components/MultiAgentAccelerator/AgentNode.d.ts +18 -0
  58. package/dist/components/MultiAgentAccelerator/AgentNode.js +129 -0
  59. package/dist/components/MultiAgentAccelerator/GraphLayouts.d.ts +33 -0
  60. package/dist/components/MultiAgentAccelerator/GraphLayouts.js +297 -0
  61. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.d.ts +17 -0
  62. package/dist/components/MultiAgentAccelerator/MultiAgentAccelerator.js +208 -0
  63. package/dist/components/MultiAgentAccelerator/PlasmaEdge.d.ts +3 -0
  64. package/dist/components/MultiAgentAccelerator/PlasmaEdge.js +124 -0
  65. package/dist/components/MultiAgentAccelerator/Sidebar.d.ts +12 -0
  66. package/dist/components/MultiAgentAccelerator/Sidebar.js +204 -0
  67. package/dist/components/MultiAgentAccelerator/ThoughtBubbleEdge.d.ts +12 -0
  68. package/dist/components/MultiAgentAccelerator/ThoughtBubbleEdge.js +15 -0
  69. package/dist/components/MultiAgentAccelerator/ThoughtBubbleOverlay.d.ts +11 -0
  70. package/dist/components/MultiAgentAccelerator/ThoughtBubbleOverlay.js +466 -0
  71. package/dist/components/MultiAgentAccelerator/const.d.ts +7 -0
  72. package/dist/components/MultiAgentAccelerator/const.js +39 -0
  73. package/dist/const.d.ts +10 -0
  74. package/dist/const.js +30 -0
  75. package/dist/controller/agent/Agent.d.ts +56 -0
  76. package/dist/controller/agent/Agent.js +162 -0
  77. package/dist/controller/llm/LlmChat.d.ts +18 -0
  78. package/dist/controller/llm/LlmChat.js +65 -0
  79. package/dist/controller/llm/endpoints.d.ts +1 -0
  80. package/dist/controller/llm/endpoints.js +17 -0
  81. package/dist/generated/neuro-san/NeuroSanClient.d.ts +413 -0
  82. package/dist/generated/neuro-san/NeuroSanClient.js +28 -0
  83. package/dist/index.d.ts +37 -0
  84. package/dist/index.js +52 -0
  85. package/dist/state/UserInfo.d.ts +16 -0
  86. package/dist/state/UserInfo.js +27 -0
  87. package/dist/state/environment.d.ts +18 -0
  88. package/dist/state/environment.js +33 -0
  89. package/dist/tsconfig.build.tsbuildinfo +1 -0
  90. package/dist/utils/Authentication.d.ts +31 -0
  91. package/dist/utils/Authentication.js +94 -0
  92. package/dist/utils/BrowserNavigation.d.ts +5 -0
  93. package/dist/utils/BrowserNavigation.js +22 -0
  94. package/dist/utils/Theme.d.ts +7 -0
  95. package/dist/utils/Theme.js +7 -0
  96. package/dist/utils/agentConversations.d.ts +24 -0
  97. package/dist/utils/agentConversations.js +113 -0
  98. package/dist/utils/text.d.ts +28 -0
  99. package/dist/utils/text.js +64 -0
  100. package/dist/utils/title.d.ts +1 -0
  101. package/dist/utils/title.js +20 -0
  102. package/dist/utils/types.d.ts +17 -0
  103. package/dist/utils/types.js +16 -0
  104. package/dist/utils/useLocalStorage.d.ts +1 -0
  105. package/dist/utils/useLocalStorage.js +55 -0
  106. package/dist/utils/zIndexLayers.d.ts +2 -0
  107. package/dist/utils/zIndexLayers.js +29 -0
  108. package/package.json +69 -0
@@ -0,0 +1,162 @@
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
+ /**
17
+ * Controller module for interacting with the Agent LLM API.
18
+ */
19
+ import { ApiPaths,
20
+ // eslint-disable-next-line camelcase
21
+ ChatFilterChat_filter_type, ChatMessageType, } from "../../generated/neuro-san/NeuroSanClient.js";
22
+ import { sendLlmRequest } from "../llm/LlmChat.js";
23
+ /**
24
+ * Insert the target agent name into the path. The paths Api enum contains values like:
25
+ * <code>"/api/v1/{agent_name}/connectivity"</code> so unfortunately we need to do a replace() to insert the target
26
+ * agent.
27
+ * @param agent The agent to send the request to.
28
+ * @param path The API path to insert the target agent into.
29
+ * @returns The path with the target agent name inserted.
30
+ */
31
+ const insertTargetAgent = (agent, path) => {
32
+ return path.replace("{agent_name}", agent);
33
+ };
34
+ /**
35
+ * Test connection for a neuro-san server.
36
+ * @param url The neuro-san server URL.
37
+ * @returns A boolean indicating whether the connection was successful.
38
+ */
39
+ export async function testConnection(url) {
40
+ const controller = new AbortController();
41
+ const timeout = setTimeout(() => controller.abort(), 2500); // 2.5s timeout
42
+ try {
43
+ const response = await fetch(url, { signal: controller.signal });
44
+ if (!response.ok) {
45
+ return { success: false, status: response.statusText };
46
+ }
47
+ const jsonResponse = await response.json();
48
+ // eslint-disable-next-line no-shadow
49
+ const status = jsonResponse?.status;
50
+ // Different versions of the server return different status values, so we need to check for both.
51
+ const success = status === "healthy" || status === "ok";
52
+ // For now, just capture the Neuro-san version since that's all the server returns. More can be added later.
53
+ const version = jsonResponse?.versions?.["neuro-san"];
54
+ return { success, status, version };
55
+ }
56
+ catch (error) {
57
+ const errorMessage = error instanceof Error ? error.message : String(error);
58
+ return { success: false, status: errorMessage };
59
+ }
60
+ finally {
61
+ clearTimeout(timeout);
62
+ }
63
+ }
64
+ /**
65
+ * Get the list of available agent networks from the concierge service.
66
+ * @param url The neuro-san server URL
67
+ * @returns A promise that resolves to an array of agent network names.
68
+ */
69
+ export async function getAgentNetworks(url) {
70
+ const path = `${url}${ApiPaths.ConciergeService_List}`;
71
+ const response = await fetch(path);
72
+ const conciergeResponse = (await response.json());
73
+ return conciergeResponse.agents.map((network) => network.agent_name);
74
+ }
75
+ // Function to split each chunk by newline and call the real callback. The server can send multiple JSON objects per
76
+ // chunk delimited by newline.
77
+ function handleJsonLines(chunk, callback) {
78
+ chunk.split("\n").forEach((line) => {
79
+ const trimmed = line.trim();
80
+ if (trimmed) {
81
+ callback(trimmed);
82
+ }
83
+ });
84
+ }
85
+ /**
86
+ * Send a chat query to the Agent LLM API. This opens a session with the agent network..
87
+ * @param url The neuro-san server URL
88
+ * @param signal The AbortSignal to use for the request. Used to cancel the request on user demand
89
+ * @param userInput The user input to send to the agent.
90
+ * In practice this "input" will actually be the output from one of the previous agents such as the data generator
91
+ * or scoping agent.
92
+ * @param targetAgent The target agent to send the request to. See CombinedAgentType for the list of available agents.
93
+ * @param callback The callback function to be called when a chunk of data is received from the server.
94
+ * @param chatContext "Opaque" conversation context for maintaining conversation state with the server. Neuro-san
95
+ * agents do not use ChatHistory directly, but rather, ChatContext, which is a collection of ChatHistory objects.
96
+ * @param slyData Data items that should not be send to the LLM. Generated by the server.
97
+ * @param userId Current user ID in the session.
98
+ * @returns The response from the agent network.
99
+ */
100
+ export async function sendChatQuery(url, signal, userInput, targetAgent, callback, chatContext, slyData, userId) {
101
+ // Create request
102
+ const userMessage = {
103
+ type: ChatMessageType.HUMAN,
104
+ text: userInput,
105
+ };
106
+ const agentChatRequest = {
107
+ sly_data: slyData,
108
+ user_message: userMessage,
109
+ // eslint-disable-next-line camelcase
110
+ chat_filter: { chat_filter_type: ChatFilterChat_filter_type.MAXIMAL },
111
+ chat_context: chatContext,
112
+ };
113
+ const fetchUrl = `${url}${insertTargetAgent(targetAgent, ApiPaths.AgentService_StreamingChat)}`;
114
+ const requestRecord = Object.entries(agentChatRequest).reduce((acc, [key, value]) => (value ? { ...acc, [key]: value } : acc), {});
115
+ return sendLlmRequest((chunk) => handleJsonLines(chunk, callback), signal, fetchUrl, requestRecord, null, null, userId);
116
+ }
117
+ /**
118
+ * Gets information on the agent and tool connections within a network
119
+ * @param url The neuro-san server URL
120
+ * @param network The network to get connectivity information for
121
+ * @param userId Current user ID in the session.
122
+ * @returns The connectivity info as a <code>ConnectivityResponse</code> object
123
+ * @throws Various exceptions if anything goes wrong such as network issues or invalid agent type.
124
+ * Caller is responsible for try-catch.
125
+ */
126
+ export async function getConnectivity(url, network, userId) {
127
+ const fetchUrl = `${url}${insertTargetAgent(network, ApiPaths.AgentService_Connectivity)}`;
128
+ const response = await fetch(fetchUrl, {
129
+ method: "GET",
130
+ headers: {
131
+ "Content-Type": "application/json",
132
+ user_id: userId,
133
+ },
134
+ });
135
+ if (!response.ok) {
136
+ console.debug(`response: ${JSON.stringify(response)}`);
137
+ throw new Error(`Failed to send connectivity request: ${response.statusText}`);
138
+ }
139
+ return response.json();
140
+ }
141
+ /**
142
+ * Get the function of a specified agent meaning its brief description
143
+ * @param url The neuro-san server URL
144
+ * @param agent The agent to get the function for
145
+ * @param userId Current user ID in the session.
146
+ * @returns The function info as a <code>FunctionResponse</code> object
147
+ * @throws Various exceptions if anything goes wrong such as network issues or invalid agent type.
148
+ */
149
+ export async function getAgentFunction(url, agent, userId) {
150
+ const fetchUrl = `${url}${insertTargetAgent(agent, ApiPaths.AgentService_Function)}`;
151
+ const response = await fetch(fetchUrl, {
152
+ method: "GET",
153
+ headers: {
154
+ "Content-Type": "application/json",
155
+ user_id: userId,
156
+ },
157
+ });
158
+ if (!response.ok) {
159
+ throw new Error(`Failed to send agent function request: ${response.statusText}`);
160
+ }
161
+ return response.json();
162
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Generic controller class for allowing the user to chat with LLMs.
3
+ * Allows streaming callback for a more interactive experience.
4
+ */
5
+ import { BaseMessage } from "@langchain/core/messages";
6
+ /**
7
+ * Send a request to an LLM and stream the response to a callback.
8
+ * @param callback The callback function to be called when a chunk of data is received from the server.
9
+ * @param signal The AbortSignal object to be used for aborting the request.
10
+ * @param fetchUrl The URL to send the request to.
11
+ * @param params Arbitrary parameters to send to the server.
12
+ * @param userQuery The user query to send to the server (sometimes part of chat history instead).
13
+ * @param chatHistory The chat history to be sent to the server. Contains user requests and server responses.
14
+ * @param userId Current user ID in the session.
15
+ * @returns Either the JSON result of the call, or, if a callback is provided, nothing, but tokens are streamed
16
+ * to the callback as they are received from the server.
17
+ */
18
+ export declare function sendLlmRequest(callback: (token: string) => void, signal: AbortSignal, fetchUrl: string, params: Record<string, unknown>, userQuery?: string, chatHistory?: BaseMessage[], userId?: string): Promise<any>;
@@ -0,0 +1,65 @@
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
+ /**
17
+ * Send a request to an LLM and stream the response to a callback.
18
+ * @param callback The callback function to be called when a chunk of data is received from the server.
19
+ * @param signal The AbortSignal object to be used for aborting the request.
20
+ * @param fetchUrl The URL to send the request to.
21
+ * @param params Arbitrary parameters to send to the server.
22
+ * @param userQuery The user query to send to the server (sometimes part of chat history instead).
23
+ * @param chatHistory The chat history to be sent to the server. Contains user requests and server responses.
24
+ * @param userId Current user ID in the session.
25
+ * @returns Either the JSON result of the call, or, if a callback is provided, nothing, but tokens are streamed
26
+ * to the callback as they are received from the server.
27
+ */
28
+ export async function sendLlmRequest(callback, signal, fetchUrl, params, userQuery, chatHistory, userId) {
29
+ const res = await fetch(fetchUrl, {
30
+ method: "POST",
31
+ headers: {
32
+ Accept: "application/json",
33
+ "Content-Type": "application/json",
34
+ ...(userId && { user_id: userId }), // Only include user query if it exists (optional)
35
+ },
36
+ body: JSON.stringify({
37
+ ...(chatHistory && { chatHistory }), // Only include chat history if it exists (optional)
38
+ ...(userQuery && { userQuery }), // Only include user query if it exists (optional)
39
+ ...params,
40
+ }),
41
+ signal,
42
+ });
43
+ // Check if the request was successful
44
+ if (!res.ok) {
45
+ throw new Error(`Failed to fetch: ${res.statusText} error code ${res.status}`);
46
+ }
47
+ if (callback) {
48
+ const reader = res.body.getReader();
49
+ const utf8decoder = new TextDecoder("utf8");
50
+ while (true) {
51
+ const { done, value } = await reader.read();
52
+ if (done) {
53
+ break; // End of stream
54
+ }
55
+ // Decode chunk from server
56
+ const chunk = utf8decoder.decode(value);
57
+ // Send current chunk to callback
58
+ callback(chunk);
59
+ }
60
+ return null;
61
+ }
62
+ else {
63
+ return res.json();
64
+ }
65
+ }
@@ -0,0 +1 @@
1
+ export declare const CHATBOT_ENDPOINT = "/api/gpt/chatBot";
@@ -0,0 +1,17 @@
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
+ // Temporarily not used pending migration from Pinecone to pgvector
17
+ export const CHATBOT_ENDPOINT = "/api/gpt/chatBot";