@cognizant-ai-lab/ui-common 1.12.0 → 1.13.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 (61) hide show
  1. package/dist/components/AgentChat/ChatCommon/ChatCommon.js +9 -3
  2. package/dist/components/AgentChat/ChatCommon/Const.js +1 -1
  3. package/dist/components/AgentChat/ChatCommon/SlyDataDialog.js +6 -2
  4. package/dist/components/Common/Snackbar.js +12 -12
  5. package/dist/components/MultiAgentAccelerator/AgentFlow/AgentFlow.js +12 -5
  6. package/dist/components/MultiAgentAccelerator/Editor/Const.d.ts +2 -0
  7. package/dist/components/MultiAgentAccelerator/Editor/Const.js +5 -0
  8. package/dist/components/MultiAgentAccelerator/Editor/NetworkEditorDock.d.ts +0 -1
  9. package/dist/components/MultiAgentAccelerator/Editor/NetworkEditorDock.js +3 -5
  10. package/dist/components/MultiAgentAccelerator/PanelSeparator.js +2 -2
  11. package/dist/components/MultiAgentAccelerator/Publish/Publish.d.ts +36 -0
  12. package/dist/components/MultiAgentAccelerator/Publish/Publish.js +99 -0
  13. package/dist/components/MultiAgentAccelerator/Publish/PublishButton.d.ts +16 -0
  14. package/dist/components/MultiAgentAccelerator/Publish/PublishButton.js +98 -0
  15. package/dist/components/MultiAgentAccelerator/Publish/PublishConfirmation.d.ts +15 -0
  16. package/dist/components/MultiAgentAccelerator/Publish/PublishConfirmation.js +8 -0
  17. package/dist/components/MultiAgentAccelerator/Publish/PublishIconButton.d.ts +17 -0
  18. package/dist/components/MultiAgentAccelerator/Publish/PublishIconButton.js +72 -0
  19. package/dist/components/MultiAgentAccelerator/Publish/PublishPanel.d.ts +13 -0
  20. package/dist/components/MultiAgentAccelerator/Publish/PublishPanel.js +28 -0
  21. package/dist/components/MultiAgentAccelerator/Publish/PublishedNetworkUrl.d.ts +11 -0
  22. package/dist/components/MultiAgentAccelerator/Publish/PublishedNetworkUrl.js +64 -0
  23. package/dist/components/MultiAgentAccelerator/Publish/usePublishTarget.d.ts +6 -0
  24. package/dist/components/MultiAgentAccelerator/Publish/usePublishTarget.js +33 -0
  25. package/dist/components/MultiAgentAccelerator/Sidebar/AgentNetworkTreeItem.js +9 -2
  26. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.d.ts +2 -0
  27. package/dist/components/MultiAgentAccelerator/Sidebar/TreeBuilder.js +2 -0
  28. package/dist/components/Settings/ApiKeyInput.d.ts +1 -0
  29. package/dist/components/Settings/ApiKeyInput.js +8 -3
  30. package/dist/components/Settings/Byok/ByokDialog.d.ts +24 -0
  31. package/dist/components/Settings/Byok/ByokDialog.js +42 -0
  32. package/dist/components/Settings/Byok/ByokInputs.d.ts +38 -0
  33. package/dist/components/Settings/Byok/ByokInputs.js +35 -0
  34. package/dist/components/Settings/Byok/ByokStorageTooltip.d.ts +7 -0
  35. package/dist/components/Settings/Byok/ByokStorageTooltip.js +41 -0
  36. package/dist/components/Settings/Byok/ByokUnsavedChangesModal.d.ts +23 -0
  37. package/dist/components/Settings/Byok/ByokUnsavedChangesModal.js +19 -0
  38. package/dist/components/Settings/Byok/index.d.ts +5 -0
  39. package/dist/components/Settings/Byok/index.js +20 -0
  40. package/dist/components/Settings/Byok/useByokKeyManager.d.ts +59 -0
  41. package/dist/components/Settings/Byok/useByokKeyManager.js +135 -0
  42. package/dist/components/Settings/PublishSettings.d.ts +15 -0
  43. package/dist/components/Settings/PublishSettings.js +109 -0
  44. package/dist/components/Settings/SettingsDialog.js +17 -133
  45. package/dist/components/Settings/SettingsLayout.d.ts +13 -0
  46. package/dist/components/Settings/SettingsLayout.js +59 -0
  47. package/dist/controller/publish/Publish.d.ts +29 -0
  48. package/dist/controller/publish/Publish.js +94 -0
  49. package/dist/generated/neuro-san/NeuroSanClient.d.ts +9 -0
  50. package/dist/index.d.ts +1 -0
  51. package/dist/index.js +1 -0
  52. package/dist/state/Environment.d.ts +4 -0
  53. package/dist/state/Environment.js +4 -0
  54. package/dist/state/Publish.d.ts +39 -0
  55. package/dist/state/Publish.js +41 -0
  56. package/dist/state/Settings.d.ts +18 -0
  57. package/dist/state/Settings.js +4 -0
  58. package/dist/tsconfig.build.tsbuildinfo +1 -1
  59. package/dist/utils/Url.d.ts +12 -0
  60. package/dist/utils/Url.js +32 -0
  61. package/package.json +1 -1
@@ -0,0 +1,59 @@
1
+ import { KeyValidationFailure, KeyValidationResult } from "../../../controller/llm/Providers.js";
2
+ import { getApiKey, LLMProvider } from "../../../state/Settings.js";
3
+ import { ApiKeyFailure } from "../ApiKeyErrorBanner.js";
4
+ import { useCheckmarkFade } from "../FadingCheckmark.js";
5
+ type CheckmarkFade = ReturnType<typeof useCheckmarkFade>;
6
+ export type ApiKeysMap = Parameters<typeof getApiKey>[0];
7
+ export interface ByokProviderItem {
8
+ /** Checkmark fade controller for save indicator. */
9
+ readonly checkmark: CheckmarkFade;
10
+ /** Unique DOM ID suffix for the provider. */
11
+ readonly idSuffix: string;
12
+ /** Provider logo asset URL. */
13
+ readonly logo: string;
14
+ /** Test handler for validating keys. */
15
+ readonly onTest: (key: string) => Promise<KeyValidationResult>;
16
+ /** Input placeholder text. */
17
+ readonly placeholder: string;
18
+ /** LLM provider identifier. */
19
+ readonly vendor: LLMProvider;
20
+ }
21
+ export interface UseByokKeyManagerProps {
22
+ /** Callback invoked when the parent dialog closes. */
23
+ readonly onClose?: () => void;
24
+ /** Optional filter for supported providers. */
25
+ readonly supportedProviders?: ReadonlySet<LLMProvider>;
26
+ }
27
+ export interface UseByokKeyManagerReturn {
28
+ /** Active provider input configurations. */
29
+ readonly activeConfigs: readonly ByokProviderItem[];
30
+ /** Persisted API keys from settings store. */
31
+ readonly apiKeys: ApiKeysMap | undefined;
32
+ /** Handler for closing the dialog, prompting confirmation if unsaved edits exist. */
33
+ readonly handleClose: () => void;
34
+ /** Handler for discarding unsaved changes and closing the dialog. */
35
+ readonly handleDiscard: () => void;
36
+ /** Handler for updating validation failure results for a vendor. */
37
+ readonly handleKeyResultChange: (vendor: LLMProvider, result: KeyValidationFailure | null) => void;
38
+ /** Handler for saving all unsaved changes and closing the dialog. */
39
+ readonly handleSave: () => void;
40
+ /** Handler for updating draft key values when inputs change. */
41
+ readonly handleValueChange: (vendor: LLMProvider, value: string) => void;
42
+ /** Current validation failures for active providers. */
43
+ readonly keyFailures: readonly ApiKeyFailure[];
44
+ /** Persists a single API key to settings store. */
45
+ readonly persistKey: (vendor: LLMProvider, key: string, checkmark: CheckmarkFade, now: number) => void;
46
+ /** Whether the unsaved changes confirmation modal is currently visible. */
47
+ readonly showUnsavedChangesModal: boolean;
48
+ }
49
+ /**
50
+ * Custom hook managing the state, validation, and lifecycle for Bring Your Own Key (BYOK) inputs.
51
+ * Tracks unsaved drafts and prompts before closing when unpersisted changes exist.
52
+ *
53
+ * @param props Hook options
54
+ * @param props.onClose Callback invoked when the parent dialog closes
55
+ * @param props.supportedProviders Optional filter for supported providers
56
+ * @return State and callbacks for managing BYOK inputs and confirmation modal
57
+ */
58
+ export declare const useByokKeyManager: ({ onClose, supportedProviders }: UseByokKeyManagerProps) => UseByokKeyManagerReturn;
59
+ export {};
@@ -0,0 +1,135 @@
1
+ /*
2
+ Copyright 2026 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 { useTheme } from "@mui/material/styles";
17
+ import { useCallback, useMemo, useState } from "react";
18
+ import { isAnthropicKeyValid, isOpenAIKeyValid, } from "../../../controller/llm/Providers.js";
19
+ import { API_KEYS_TTL_MS, getApiKey, useSettingsStore } from "../../../state/Settings.js";
20
+ import { useCheckmarkFade } from "../FadingCheckmark.js";
21
+ const PROVIDER_DEFINITIONS = [
22
+ {
23
+ getLogo: (isDarkMode) => (isDarkMode ? "/OpenAI-white.png" : "/OpenAI-black.png"),
24
+ idSuffix: "openai",
25
+ onTest: isOpenAIKeyValid,
26
+ placeholder: "sk-...",
27
+ vendor: "OpenAI",
28
+ },
29
+ {
30
+ getLogo: () => "/Anthropic.png",
31
+ idSuffix: "anthropic",
32
+ onTest: isAnthropicKeyValid,
33
+ placeholder: "sk-ant-...",
34
+ vendor: "Anthropic",
35
+ },
36
+ ];
37
+ /**
38
+ * Custom hook managing the state, validation, and lifecycle for Bring Your Own Key (BYOK) inputs.
39
+ * Tracks unsaved drafts and prompts before closing when unpersisted changes exist.
40
+ *
41
+ * @param props Hook options
42
+ * @param props.onClose Callback invoked when the parent dialog closes
43
+ * @param props.supportedProviders Optional filter for supported providers
44
+ * @return State and callbacks for managing BYOK inputs and confirmation modal
45
+ */
46
+ export const useByokKeyManager = ({ onClose, supportedProviders }) => {
47
+ const theme = useTheme();
48
+ const openAIKeyCheckmark = useCheckmarkFade();
49
+ const anthropicKeyCheckmark = useCheckmarkFade();
50
+ const apiKeys = useSettingsStore((state) => state.settings.apiKeys);
51
+ const updateSettings = useSettingsStore((state) => state.updateSettings);
52
+ const [keyTestResults, setKeyTestResults] = useState({});
53
+ const [draftKeys, setDraftKeys] = useState({});
54
+ const [showUnsavedChangesModal, setShowUnsavedChangesModal] = useState(false);
55
+ const checkmarks = useMemo(() => ({
56
+ Anthropic: anthropicKeyCheckmark,
57
+ OpenAI: openAIKeyCheckmark,
58
+ }), [anthropicKeyCheckmark, openAIKeyCheckmark]);
59
+ const isDarkMode = theme.palette.mode === "dark";
60
+ const providerItems = useMemo(() => PROVIDER_DEFINITIONS.map((def) => ({
61
+ checkmark: checkmarks[def.vendor],
62
+ idSuffix: def.idSuffix,
63
+ logo: def.getLogo(isDarkMode),
64
+ onTest: def.onTest,
65
+ placeholder: def.placeholder,
66
+ vendor: def.vendor,
67
+ })), [checkmarks, isDarkMode]);
68
+ const activeConfigs = useMemo(() => (supportedProviders ? providerItems.filter((c) => supportedProviders.has(c.vendor)) : providerItems), [providerItems, supportedProviders]);
69
+ const persistKey = useCallback((vendor, key, checkmark, now) => {
70
+ updateSettings({
71
+ apiKeys: {
72
+ [vendor]: {
73
+ value: key,
74
+ expiresAt: key ? now + API_KEYS_TTL_MS : 0,
75
+ },
76
+ },
77
+ });
78
+ checkmark.trigger();
79
+ setDraftKeys((prev) => {
80
+ const { [vendor]: _, ...rest } = prev;
81
+ return rest;
82
+ });
83
+ }, [updateSettings]);
84
+ const handleValueChange = useCallback((vendor, value) => {
85
+ setDraftKeys((prev) => ({ ...prev, [vendor]: value }));
86
+ }, []);
87
+ const handleKeyResultChange = useCallback((vendor, result) => {
88
+ setKeyTestResults((prev) => ({
89
+ ...prev,
90
+ [vendor]: result ? { result, vendor } : null,
91
+ }));
92
+ }, []);
93
+ const keyFailures = useMemo(() => activeConfigs.flatMap(({ vendor }) => {
94
+ const failure = keyTestResults[vendor];
95
+ return failure ? [failure] : [];
96
+ }), [activeConfigs, keyTestResults]);
97
+ const getDirtyDrafts = useCallback(() => activeConfigs.filter(({ vendor }) => {
98
+ const draft = draftKeys[vendor];
99
+ return draft !== undefined && draft !== (getApiKey(apiKeys, vendor) ?? "");
100
+ }), [activeConfigs, apiKeys, draftKeys]);
101
+ const handleClose = useCallback(() => {
102
+ if (getDirtyDrafts().length > 0) {
103
+ setShowUnsavedChangesModal(true);
104
+ }
105
+ else {
106
+ onClose?.();
107
+ }
108
+ }, [getDirtyDrafts, onClose]);
109
+ const handleDiscard = useCallback(() => {
110
+ setDraftKeys({});
111
+ setShowUnsavedChangesModal(false);
112
+ onClose?.();
113
+ }, [onClose]);
114
+ const handleSave = useCallback(() => {
115
+ const now = Date.now();
116
+ getDirtyDrafts().forEach(({ checkmark, vendor }) => {
117
+ persistKey(vendor, draftKeys[vendor], checkmark, now);
118
+ });
119
+ setDraftKeys({});
120
+ setShowUnsavedChangesModal(false);
121
+ onClose?.();
122
+ }, [getDirtyDrafts, draftKeys, persistKey, onClose]);
123
+ return {
124
+ activeConfigs,
125
+ apiKeys,
126
+ handleClose,
127
+ handleDiscard,
128
+ handleKeyResultChange,
129
+ handleSave,
130
+ handleValueChange,
131
+ keyFailures,
132
+ persistKey,
133
+ showUnsavedChangesModal,
134
+ };
135
+ };
@@ -0,0 +1,15 @@
1
+ import { FC } from "react";
2
+ export declare const DEFAULT_PUBLISH_SERVER_LABEL = "Use the default publish server";
3
+ export declare const ORG_NAME_LABEL = "Org name";
4
+ export declare const PUBLISH_SERVER_HOST_LABEL = "Publish server host";
5
+ export declare const SAVE_PUBLISHING_LABEL = "Save publishing settings";
6
+ export declare const TEST_PUBLISH_SERVER_LABEL = "Test publish server";
7
+ interface PublishSettingsProps {
8
+ readonly id: string;
9
+ }
10
+ /**
11
+ * "Publish server" part of the External Services section of the Settings dialog: the server that networks are
12
+ * published to, and the org name sent with each publish.
13
+ */
14
+ export declare const PublishSettings: FC<PublishSettingsProps>;
15
+ export {};
@@ -0,0 +1,109 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ Copyright 2026 Cognizant Technology Solutions Corp, www.cognizant.com.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+ import ClearIcon from "@mui/icons-material/Clear";
18
+ import Box from "@mui/material/Box";
19
+ import Button from "@mui/material/Button";
20
+ import FormLabel from "@mui/material/FormLabel";
21
+ import IconButton from "@mui/material/IconButton";
22
+ import InputAdornment from "@mui/material/InputAdornment";
23
+ import MenuItem from "@mui/material/MenuItem";
24
+ import Select from "@mui/material/Select";
25
+ import TextField from "@mui/material/TextField";
26
+ import { useState } from "react";
27
+ import { SettingsSubsection } from "./SettingsLayout.js";
28
+ import { checkHealth } from "../../controller/publish/Publish.js";
29
+ import { useEnvironmentStore } from "../../state/Environment.js";
30
+ import { useSettingsStore } from "../../state/Settings.js";
31
+ import { normalizeUrlInput, stripProtocol } from "../../utils/Url.js";
32
+ export const DEFAULT_PUBLISH_SERVER_LABEL = "Use the default publish server";
33
+ export const ORG_NAME_LABEL = "Org name";
34
+ export const PUBLISH_SERVER_HOST_LABEL = "Publish server host";
35
+ export const SAVE_PUBLISHING_LABEL = "Save publishing settings";
36
+ export const TEST_PUBLISH_SERVER_LABEL = "Test publish server";
37
+ /**
38
+ * A colored dot followed by a short status, like "● Connected".
39
+ */
40
+ const StatusText = ({ color, children }) => (_jsxs(Box, { component: "span", sx: { alignItems: "center", color, display: "inline-flex", fontSize: "0.7rem", fontWeight: 400, gap: 0.75 }, children: [_jsx(Box, { "aria-hidden": true, component: "span", sx: { backgroundColor: color, borderRadius: "50%", height: "0.5rem", width: "0.5rem" } }), children] }));
41
+ /**
42
+ * One row of the form: label, field, then an optional action. Rows go inside a FieldGrid, which owns the columns, so
43
+ * fields line up and have the same width whether or not their row has an action.
44
+ */
45
+ const FieldRow = ({ label, required = false, field, action, helper }) => (_jsxs(Box, { sx: { display: "contents" }, children: [_jsx(FormLabel, { required: required, sx: { gridColumn: 1, "& .MuiFormLabel-asterisk": { color: "error.main" } }, children: label }), _jsx(Box, { sx: { gridColumn: 2 }, children: field }), action && _jsx(Box, { sx: { gridColumn: 3 }, children: action }), helper && _jsx(Box, { sx: { gridColumn: 2, mb: 1 }, children: helper })] }));
46
+ const FieldGrid = ({ children }) => (_jsx(Box, { sx: {
47
+ alignItems: "center",
48
+ columnGap: 2,
49
+ display: "grid",
50
+ gridTemplateColumns: "10rem minmax(0, 34rem) auto",
51
+ rowGap: 0.75,
52
+ }, children: children }));
53
+ /**
54
+ * "Publish server" part of the External Services section of the Settings dialog: the server that networks are
55
+ * published to, and the org name sent with each publish.
56
+ */
57
+ export const PublishSettings = ({ id }) => {
58
+ const updateSettings = useSettingsStore((state) => state.updateSettings);
59
+ const savedServerUrl = useSettingsStore((state) => state.settings.publish.serverUrl) ?? "";
60
+ const savedOrgName = useSettingsStore((state) => state.settings.publish.orgName) ?? "";
61
+ const defaultServerUrl = useEnvironmentStore((state) => state.publishServerUrl) ?? "";
62
+ const effectiveServerUrl = savedServerUrl || defaultServerUrl;
63
+ const [protocol, setProtocol] = useState(effectiveServerUrl.startsWith("http://") ? "http" : "https");
64
+ const [hostInput, setHostInput] = useState(stripProtocol(effectiveServerUrl));
65
+ const [isServerReachable, setIsServerReachable] = useState(null);
66
+ const [orgNameInput, setOrgNameInput] = useState(savedOrgName);
67
+ const normalized = normalizeUrlInput(hostInput, protocol);
68
+ const serverUrl = normalized.host ? `${normalized.protocol}://${normalized.host}` : "";
69
+ const orgName = orgNameInput.trim();
70
+ const isPublishingOn = Boolean(effectiveServerUrl && savedOrgName);
71
+ const hasChanges = serverUrl !== effectiveServerUrl || orgName !== savedOrgName;
72
+ const handleHostChange = (host) => {
73
+ setHostInput(host);
74
+ setIsServerReachable(null);
75
+ };
76
+ const handleTest = async () => {
77
+ const result = await checkHealth(serverUrl);
78
+ setIsServerReachable(result.success);
79
+ };
80
+ const handleDefault = () => {
81
+ const defaultServer = normalizeUrlInput(defaultServerUrl, "https");
82
+ handleHostChange(defaultServer.host);
83
+ setProtocol(defaultServer.protocol);
84
+ };
85
+ const handleSave = () => {
86
+ // Only save a server that differs from the default, so a change to the default still applies
87
+ const serverOverride = serverUrl && serverUrl !== defaultServerUrl ? serverUrl : null;
88
+ updateSettings({ publish: { serverUrl: serverOverride, orgName: orgName || null } });
89
+ };
90
+ return (_jsxs(SettingsSubsection, { status: isPublishingOn ? (_jsx(StatusText, { color: "success.main", children: "On" })) : (_jsx(StatusText, { color: "text.disabled", children: "Off" })), title: "Publish server", children: [_jsxs(FieldGrid, { children: [_jsx(FieldRow, { action: _jsxs(Box, { sx: { display: "flex", gap: 1 }, children: [_jsx(Button, { "aria-label": TEST_PUBLISH_SERVER_LABEL, disabled: !serverUrl, onClick: handleTest, size: "small", variant: "contained", children: "Test" }), defaultServerUrl && (_jsx(Button, { "aria-label": DEFAULT_PUBLISH_SERVER_LABEL, disabled: serverUrl === defaultServerUrl, onClick: handleDefault, size: "small", variant: "contained", children: "Default" }))] }), field: _jsx(TextField, { onBlur: () => {
91
+ setHostInput(normalized.host);
92
+ setProtocol(normalized.protocol);
93
+ }, onChange: (e) => handleHostChange(e.target.value), placeholder: "publish.example.com", size: "small", slotProps: {
94
+ htmlInput: { "aria-label": PUBLISH_SERVER_HOST_LABEL },
95
+ input: {
96
+ startAdornment: (_jsx(InputAdornment, { position: "start", sx: {
97
+ borderRight: 1,
98
+ borderColor: "divider",
99
+ height: "100%",
100
+ mr: 1.5,
101
+ pr: 1,
102
+ }, children: _jsxs(Select, { "aria-label": "Publish server protocol", disableUnderline: true, onChange: (e) => {
103
+ setProtocol(e.target.value);
104
+ setIsServerReachable(null);
105
+ }, value: protocol, variant: "standard", children: [_jsx(MenuItem, { value: "https", children: "https://" }), _jsx(MenuItem, { value: "http", children: "http://" })] }) })),
106
+ endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(IconButton, { "aria-label": "Clear publish server", edge: "end", onClick: () => handleHostChange(""), size: "small", children: _jsx(ClearIcon, { fontSize: "small" }) }) })),
107
+ },
108
+ }, fullWidth: true, value: hostInput }), helper: isServerReachable === null ? null : isServerReachable ? (_jsx(StatusText, { color: "success.main", children: "Connected" })) : (_jsx(StatusText, { color: "error.main", children: "Couldn't connect" })), label: "Server" }), _jsx(FieldRow, { field: _jsx(TextField, { fullWidth: true, onChange: (e) => setOrgNameInput(e.target.value), size: "small", slotProps: { htmlInput: { "aria-label": ORG_NAME_LABEL } }, value: orgNameInput }), label: ORG_NAME_LABEL, required: true })] }), _jsx(Box, { children: _jsx(Button, { "aria-label": SAVE_PUBLISHING_LABEL, disabled: !hasChanges, id: `${id}-publishing-save`, onClick: handleSave, size: "small", variant: "contained", children: "Save" }) })] }));
109
+ };
@@ -10,79 +10,29 @@ import IconButton from "@mui/material/IconButton";
10
10
  import InputAdornment from "@mui/material/InputAdornment";
11
11
  import MenuItem from "@mui/material/MenuItem";
12
12
  import Select from "@mui/material/Select";
13
- import { createTheme, styled, ThemeProvider, useTheme } from "@mui/material/styles";
13
+ import { createTheme, ThemeProvider, useTheme } from "@mui/material/styles";
14
14
  import TextField from "@mui/material/TextField";
15
15
  import ToggleButton from "@mui/material/ToggleButton";
16
16
  import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
17
17
  import Tooltip from "@mui/material/Tooltip";
18
18
  import Typography from "@mui/material/Typography";
19
- import { useCallback, useEffect, useMemo, useState, } from "react";
20
- import { ApiKeyErrorBanner } from "./ApiKeyErrorBanner.js";
21
- import { ApiKeyInput } from "./ApiKeyInput.js";
19
+ import { useEffect, useMemo, useState } from "react";
20
+ import { ByokInputs, ByokStorageTooltip, ByokUnsavedChangesModal, useByokKeyManager } from "./Byok/index.js";
22
21
  import { useCheckmarkFade } from "./FadingCheckmark.js";
22
+ import { PublishSettings } from "./PublishSettings.js";
23
+ import { Section, SettingsSectionTitle, SettingsSubsection, SubSection, SubSectionBody } from "./SettingsLayout.js";
23
24
  import { SettingsRow } from "./SettingsRow.js";
24
25
  import { getBrandingSuggestions, testConnection } from "../../controller/agent/Agent.js";
25
- import { isAnthropicKeyValid, isOpenAIKeyValid, } from "../../controller/llm/Providers.js";
26
26
  import { useEnvironmentStore } from "../../state/Environment.js";
27
- import { API_KEYS_TTL_MS, DEFAULT_SETTINGS, getApiKey, useSettingsStore, } from "../../state/Settings.js";
27
+ import { DEFAULT_SETTINGS, useSettingsStore } from "../../state/Settings.js";
28
28
  import { PALETTES } from "../../Theme/Palettes.js";
29
+ import { normalizeUrlInput, stripProtocol } from "../../utils/Url.js";
29
30
  import { ConfirmationModal } from "../Common/ConfirmationModal.js";
30
31
  import { MUIDialog } from "../Common/MUIDialog.js";
31
32
  import { NotificationType, sendNotification } from "../Common/notification.js";
32
33
  import { StatusLight } from "../Common/StatusLight.js";
33
34
  import { CustomerLogo } from "../Logo/CustomerLogo.js";
34
- //#region: Styled Components
35
- const SettingsSectionTitleBase = (props) => (_jsx(Typography, { variant: "h6", ...props }));
36
- const SettingsSectionTitle = styled(SettingsSectionTitleBase)(({ theme }) => ({
37
- marginBottom: theme.spacing(0.5),
38
- }));
39
- const Section = styled(Box)(({ theme }) => ({
40
- display: "flex",
41
- flexDirection: "column",
42
- gap: theme.spacing(2),
43
- marginBottom: theme.spacing(2),
44
- }));
45
- const SubsectionTitle = styled(Typography)(({ theme }) => ({
46
- borderBottom: `1px solid ${theme.palette.divider}`,
47
- color: theme.palette.text.secondary,
48
- fontWeight: 600,
49
- paddingBottom: theme.spacing(0.5),
50
- marginBottom: theme.spacing(1.5),
51
- width: "100%",
52
- }));
53
- const SubSection = styled(Box)(({ theme }) => ({
54
- alignItems: "start",
55
- display: "flex",
56
- flexDirection: "column",
57
- gap: theme.spacing(2),
58
- marginBottom: theme.spacing(4),
59
- }));
60
- const SubSectionBody = styled(Box)(({ theme }) => ({
61
- alignContent: "center",
62
- display: "flex",
63
- flexDirection: "column",
64
- gap: theme.spacing(2.5),
65
- width: "100%",
66
- }));
67
35
  //#endregion: Types and Interfaces
68
- const SettingsSubsection = ({ title, children }) => (_jsxs(SubSection, { children: [_jsx(SubsectionTitle, { variant: "subtitle1", children: title }), _jsx(SubSectionBody, { children: children })] }));
69
- const URL_PROTOCOL_REGEX = /^https?:\/\//iu;
70
- const HTTP_PROTOCOL_REGEX = /^http:\/\//iu;
71
- const stripProtocol = (value) => (value ?? "").replace(URL_PROTOCOL_REGEX, "");
72
- /**
73
- * Normalize a Neuro SAN URL input by stripping the protocol and determining the protocol to use.
74
- * @param value The input URL value to normalize.
75
- * @param fallbackProtocol The protocol to use if the input value does not specify one.
76
- * @return An object containing the normalized host and protocol.
77
- */
78
- const normalizeNeuroSanUrlInput = (value, fallbackProtocol) => {
79
- const trimmedValue = value.trim();
80
- const hasProtocol = URL_PROTOCOL_REGEX.exec(trimmedValue);
81
- return {
82
- host: stripProtocol(trimmedValue),
83
- protocol: hasProtocol ? (HTTP_PROTOCOL_REGEX.test(trimmedValue) ? "http" : "https") : fallbackProtocol,
84
- };
85
- };
86
36
  export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
87
37
  // Settings store actions
88
38
  const updateSettings = useSettingsStore((state) => state.updateSettings);
@@ -114,15 +64,12 @@ export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
114
64
  // Zen mode
115
65
  const enableZenMode = useSettingsStore((state) => state.settings.behavior.enableZenMode);
116
66
  const enableZenModeCheckmark = useCheckmarkFade();
117
- // API keys
118
- const apiKeys = useSettingsStore((state) => state.settings.apiKeys);
119
- const openAIKeyCheckmark = useCheckmarkFade();
120
- const anthropicKeyCheckmark = useCheckmarkFade();
121
- // Failing key-test results, aggregated into the banner at the top of the API Keys section
122
- const [keyTestResults, setKeyTestResults] = useState({});
67
+ // BYOK state and unsaved changes lifecycle
68
+ const { activeConfigs: apiKeyConfigs, apiKeys, handleClose: handleSettingsClose, handleDiscard: handleDiscardUnsavedKeys, handleKeyResultChange, handleSave: handleSaveUnsavedKeys, handleValueChange, keyFailures, persistKey, showUnsavedChangesModal, } = useByokKeyManager({ onClose });
123
69
  // Native names setting
124
70
  const useNativeNames = useSettingsStore((state) => state.settings.appearance.useNativeNames);
125
71
  const nativeNamesCheckmark = useCheckmarkFade();
72
+ const enablePublishing = useEnvironmentStore((state) => state.enablePublishing);
126
73
  /*
127
74
  Neuro SAN URL
128
75
  This can come from three sources:
@@ -235,37 +182,8 @@ export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
235
182
  brandingCheckmark.trigger();
236
183
  logoCheckmark.trigger();
237
184
  };
238
- /**
239
- * Records the latest key-test result for a vendor, or clears it when result is null.
240
- * @param vendor Vendor for this key: see the list in LLMProvider type
241
- * @param result Validation failure to display, or null to clear
242
- */
243
- const handleKeyResultChange = useCallback((vendor, result) => {
244
- setKeyTestResults((prev) => ({
245
- ...prev,
246
- [vendor]: result ? { vendor, result } : null,
247
- }));
248
- }, []);
249
- /**
250
- * Used for both saving and removing keys.
251
- * @param vendor Vendor for this key: see the list in LLMProvider type
252
- * @param key Value of the key
253
- * @param checkmark Checkmark to trigger on save
254
- * @param now Timestamp for "now"
255
- */
256
- const persistKey = (vendor, key, checkmark, now) => {
257
- updateSettings({
258
- apiKeys: {
259
- [vendor]: {
260
- value: key,
261
- expiresAt: key ? now + API_KEYS_TTL_MS : 0,
262
- },
263
- },
264
- });
265
- checkmark.trigger();
266
- };
267
185
  const handleTestConnection = async () => {
268
- const normalized = normalizeNeuroSanUrlInput(neuroSanUrlInput, neuroSanProtocol);
186
+ const normalized = normalizeUrlInput(neuroSanUrlInput, neuroSanProtocol);
269
187
  setNeuroSanProtocol(normalized.protocol);
270
188
  setNeuroSanUrlInput(normalized.host);
271
189
  const result = await testConnection(`${normalized.protocol}://${normalized.host}`);
@@ -276,7 +194,7 @@ export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
276
194
  setNeuroSanUrlValidated(null);
277
195
  };
278
196
  const handleSaveNeuroSanUrl = () => {
279
- const normalized = normalizeNeuroSanUrlInput(neuroSanUrlInput, neuroSanProtocol);
197
+ const normalized = normalizeUrlInput(neuroSanUrlInput, neuroSanProtocol);
280
198
  setNeuroSanProtocol(normalized.protocol);
281
199
  setNeuroSanUrlInput(normalized.host);
282
200
  updateSettings({
@@ -292,12 +210,12 @@ export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
292
210
  setNeuroSanUrlValidated(null);
293
211
  };
294
212
  const handleNeuroSanUrlBlur = () => {
295
- const normalized = normalizeNeuroSanUrlInput(neuroSanUrlInput, neuroSanProtocol);
213
+ const normalized = normalizeUrlInput(neuroSanUrlInput, neuroSanProtocol);
296
214
  setNeuroSanProtocol(normalized.protocol);
297
215
  setNeuroSanUrlInput(normalized.host);
298
216
  };
299
217
  const handleResetNeuroSanUrl = () => {
300
- const normalized = normalizeNeuroSanUrlInput(defaultNeuroSanUrl, "https");
218
+ const normalized = normalizeUrlInput(defaultNeuroSanUrl, "https");
301
219
  setNeuroSanUrlInput(normalized.host);
302
220
  setNeuroSanProtocol(normalized.protocol);
303
221
  };
@@ -307,25 +225,6 @@ export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
307
225
  }, [customer]);
308
226
  const availablePalettes = customer && brandingRangePalette?.length > 0 ? { brand: brandingRangePalette } : PALETTES;
309
227
  const paletteKeys = Object.keys(availablePalettes);
310
- // Config for API key inputs, so we can easily add new providers in the future by just adding to this array
311
- const apiKeyConfigs = [
312
- {
313
- checkmark: openAIKeyCheckmark,
314
- idSuffix: "openai",
315
- logo: theme.palette.mode === "dark" ? "/OpenAI-white.png" : "/OpenAI-black.png",
316
- onTest: isOpenAIKeyValid,
317
- placeholder: "sk-...",
318
- vendor: "OpenAI",
319
- },
320
- {
321
- checkmark: anthropicKeyCheckmark,
322
- idSuffix: "anthropic",
323
- logo: "/claude.png",
324
- onTest: isAnthropicKeyValid,
325
- placeholder: "sk-ant-...",
326
- vendor: "Anthropic",
327
- },
328
- ];
329
228
  const getConfirmationModal = () => (_jsx(ConfirmationModal, { id: `${id}-reset-to-default-settings-confirmation-modal`, content: "This will reset all settings to their default values and cannot be undone. " +
330
229
  "Are you sure you want to proceed?", handleCancel: () => {
331
230
  setResetToDefaultSettingsOpen(false);
@@ -344,23 +243,8 @@ export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
344
243
  },
345
244
  }, sx: { flex: 1 }, value: neuroSanUrlInput }), _jsx(StatusLight, { id: `${id}-status-light`, statusValue: statusLightValue }), _jsx(Button, { disabled: neuroSanUrlInput.trim().length === 0, onClick: handleTestConnection, size: "small", variant: "contained", children: "Test" }), _jsx(Button, { disabled: neuroSanUrlSaveDisabled, onClick: handleSaveNeuroSanUrl, size: "small", variant: "contained", children: "Save" }), _jsx(Button, { disabled: neuroSanUrlResetDisabled, onClick: handleResetNeuroSanUrl, size: "small", variant: "contained", children: "Default" })] }, `${id}-neuro-san-server-url`) }));
346
245
  };
347
- const getServicesSection = () => (_jsxs(Section, { children: [_jsx(SettingsSectionTitle, { children: "External Services" }), getNeuroSanSubsection()] }));
348
- // Collect the current test failure for each vendor that has one.
349
- const keyFailures = apiKeyConfigs.flatMap(({ vendor }) => {
350
- const failure = keyTestResults[vendor];
351
- return failure ? [failure] : [];
352
- });
353
- const getApiKeysSection = () => (_jsxs(Section, { children: [_jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: theme.spacing(1) }, children: [_jsx(SettingsSectionTitle, { children: "API Keys" }), _jsx(Tooltip, { title: "API keys are stored locally in your browser's memory for the duration of your session only\n and are only sent to the Neuro SAN service for use with the associated LLM provider when you use\n this application to interact with networks.\n Your keys are never sent to any other servers or services and are not stored on our servers.\n When you close this tab or your browser, your keys will be permanently cleared from memory and\n you will need to enter them again to use services that require them.", children: _jsxs(Typography, { sx: {
354
- alignSelf: "flex-start",
355
- color: "var(--bs-secondary)",
356
- cursor: "help",
357
- fontSize: "0.7rem",
358
- lineHeight: 1,
359
- mt: 0.5,
360
- }, variant: "caption", children: [_jsx(Box, { component: "span", sx: { mr: 0.5 }, children: "\u24D8" }), _jsx(Box, { component: "span", sx: {
361
- borderBottom: "1px dashed",
362
- pb: 0.25,
363
- }, children: "How are my keys stored and used?" })] }) })] }), _jsxs(SettingsSubsection, { title: "LLM Providers", children: [_jsx(ApiKeyErrorBanner, { failures: keyFailures, id: `${id}-api-key-error-banner` }), _jsx(Box, { sx: { display: "flex", flexDirection: "column", alignItems: "center", gap: 1.5 }, children: apiKeyConfigs.map(({ checkmark, vendor, idSuffix, logo, onTest, placeholder }) => (_jsx(SettingsRow, { checkmark: checkmark, label: "", tooltip: `API key for ${vendor}.`, children: _jsx(ApiKeyInput, { forgetKey: () => persistKey(vendor, "", checkmark, 0), id: `${id}-${idSuffix}`, logo: logo, onResultChange: handleKeyResultChange, onSave: (key) => persistKey(vendor, key, checkmark, Date.now()), onTest: onTest, persistedValue: getApiKey(apiKeys, vendor), placeholder: placeholder, vendor: vendor }) }, `${id}-${idSuffix}`))) })] })] }));
246
+ const getServicesSection = () => (_jsxs(Section, { children: [_jsx(SettingsSectionTitle, { children: "External Services" }), getNeuroSanSubsection(), enablePublishing && _jsx(PublishSettings, { id: `${id}-publish` })] }));
247
+ const getApiKeysSection = () => (_jsxs(Section, { children: [_jsxs(Box, { sx: { display: "flex", alignItems: "center", gap: theme.spacing(1) }, children: [_jsx(SettingsSectionTitle, { children: "API Keys" }), _jsx(ByokStorageTooltip, {})] }), _jsx(SettingsSubsection, { title: "LLM Providers", children: _jsx(ByokInputs, { apiKeys: apiKeys, configs: apiKeyConfigs, id: id, keyFailures: keyFailures, onKeyResultChange: handleKeyResultChange, onPersistKey: persistKey, onValueChange: handleValueChange }) })] }));
364
248
  const getBehaviorSection = () => (_jsxs(Section, { children: [_jsx(SettingsSectionTitle, { children: "Behavior" }), _jsx(SettingsSubsection, { title: "Zen mode", children: _jsx(SettingsRow, { label: 'Enable "Zen" mode:', checkmark: enableZenModeCheckmark, tooltip: "Hides most of the UI during agent network animations providing a more immersive " +
365
249
  "experience.", children: _jsx(Checkbox, { checked: enableZenMode, "data-testid": "zen-mode-checkbox", onChange: (_, checked) => {
366
250
  updateSettings({ behavior: { enableZenMode: checked } });
@@ -491,7 +375,7 @@ export const SettingsDialog = ({ id, isOpen, logoServiceToken, onClose }) => {
491
375
  return (
492
376
  // Always use the default theme for settings dialog so user can always see to reset. It's possible that with
493
377
  // certain custom themes the dialog would be unreadable.
494
- _jsxs(ThemeProvider, { theme: settingsTheme, children: [resetToDefaultSettingsOpen ? getConfirmationModal() : null, _jsxs(MUIDialog, { id: id, title: _jsx(Box, { sx: { fontSize: "1.5rem" }, children: "Settings" }), isOpen: isOpen, onClose: onClose, paperProps: {
378
+ _jsxs(ThemeProvider, { theme: settingsTheme, children: [resetToDefaultSettingsOpen ? getConfirmationModal() : null, showUnsavedChangesModal ? (_jsx(ByokUnsavedChangesModal, { id: id, onDiscard: handleDiscardUnsavedKeys, onSave: handleSaveUnsavedKeys })) : null, _jsxs(MUIDialog, { id: id, title: _jsx(Box, { sx: { fontSize: "1.5rem" }, children: "Settings" }), isOpen: isOpen, onClose: handleSettingsClose, paperProps: {
495
379
  minWidth: "50%",
496
380
  minHeight: "50%",
497
381
  border: "1px solid",
@@ -0,0 +1,13 @@
1
+ import { FC, ReactNode } from "react";
2
+ export declare const Section: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
3
+ export declare const SettingsSectionTitle: import("@emotion/styled").StyledComponent<Omit<import("@mui/material/Typography").TypographyOwnProps & import("@mui/material/OverridableComponent").CommonProps & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "style" | "children" | "sx" | "className" | "color" | "classes" | "variant" | "align" | "gutterBottom" | "noWrap" | "variantMapping">, "ref"> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
4
+ export declare const SubSection: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
5
+ export declare const SubSectionBody: import("@emotion/styled").StyledComponent<import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme> & Omit<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, keyof import("@mui/system").BoxOwnProps<import("@mui/material/styles").Theme>> & import("@mui/system").MUIStyledCommonProps<import("@mui/material/styles").Theme>, {}, {}>;
6
+ interface SettingsSubsectionProps {
7
+ readonly title: string;
8
+ /** Shown at the right end of the title row */
9
+ readonly status?: ReactNode;
10
+ readonly children: ReactNode;
11
+ }
12
+ export declare const SettingsSubsection: FC<SettingsSubsectionProps>;
13
+ export {};
@@ -0,0 +1,59 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /*
3
+ Copyright 2026 Cognizant Technology Solutions Corp, www.cognizant.com.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
16
+ */
17
+ import Box from "@mui/material/Box";
18
+ import { styled } from "@mui/material/styles";
19
+ import Typography from "@mui/material/Typography";
20
+ /**
21
+ * Layout pieces shared by the sections of the Settings dialog.
22
+ */
23
+ const SettingsSectionTitleBase = (props) => (_jsx(Typography, { variant: "h6", ...props }));
24
+ //#region: Styled Components
25
+ export const Section = styled(Box)(({ theme }) => ({
26
+ display: "flex",
27
+ flexDirection: "column",
28
+ gap: theme.spacing(2),
29
+ marginBottom: theme.spacing(2),
30
+ }));
31
+ export const SettingsSectionTitle = styled(SettingsSectionTitleBase)(({ theme }) => ({
32
+ marginBottom: theme.spacing(0.5),
33
+ }));
34
+ export const SubSection = styled(Box)(({ theme }) => ({
35
+ alignItems: "start",
36
+ display: "flex",
37
+ flexDirection: "column",
38
+ gap: theme.spacing(2),
39
+ marginBottom: theme.spacing(4),
40
+ }));
41
+ export const SubSectionBody = styled(Box)(({ theme }) => ({
42
+ alignContent: "center",
43
+ display: "flex",
44
+ flexDirection: "column",
45
+ gap: theme.spacing(2.5),
46
+ width: "100%",
47
+ }));
48
+ const SubsectionTitle = styled(Typography)(({ theme }) => ({
49
+ alignItems: "baseline",
50
+ borderBottom: `1px solid ${theme.palette.divider}`,
51
+ color: theme.palette.text.secondary,
52
+ display: "flex",
53
+ fontWeight: 600,
54
+ gap: theme.spacing(1.5),
55
+ paddingBottom: theme.spacing(0.5),
56
+ marginBottom: theme.spacing(1.5),
57
+ width: "100%",
58
+ }));
59
+ export const SettingsSubsection = ({ children, status: statusNode, title }) => (_jsxs(SubSection, { children: [_jsxs(SubsectionTitle, { variant: "subtitle1", children: [title, statusNode && (_jsx(Box, { component: "span", sx: { ml: "auto" }, children: statusNode }))] }), _jsx(SubSectionBody, { children: children })] }));