Skip to content
Merged
34 changes: 11 additions & 23 deletions org.knime.ui.js/src/components/kai/panels/useDisclaimer.ts
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
import { computed, ref } from "vue";

import { encodeString } from "@/util/encodeString";
import { useHubAuth } from "../useHubAuth";
import { useAISettingsStore } from "@/store/ai/aiSettings";
import { useKaiServer } from "../useKaiServer";

const _shouldShowDisclaimer = ref(true);
const hasBeenDismissed = ref(false);

export const useDisclaimer = () => {
const { uiStrings } = useKaiServer();
const disclaimerText = computed(() => uiStrings.disclaimer ?? "");

const { hubID, username } = useHubAuth();
const aiSettingsStore = useAISettingsStore();

const localStorageKey = computed(() => {
if (!hubID.value || !username.value || !disclaimerText.value) {
return null;
}
const identifier = `${hubID.value}${username.value}${disclaimerText.value}`;
return `kai-persistently-hide-disclaimer-${encodeString(identifier)}`;
});

const persistentlyHideDisclaimer = computed(() =>
localStorageKey.value
? Boolean(localStorage.getItem(localStorageKey.value))
: false,
);

const closeDisclaimer = (persistently: boolean = true) => {
_shouldShowDisclaimer.value = false;
const closeDisclaimer = async (persistently: boolean = true) => {
hasBeenDismissed.value = true;

if (localStorageKey.value && persistently) {
localStorage.setItem(localStorageKey.value, "true");
if (persistently && disclaimerText.value) {
await aiSettingsStore.dismissDisclaimer(disclaimerText.value);
}
};
Comment on lines +14 to 20
Copy link

Copilot AI Feb 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closeDisclaimer function is async but may be called without awaiting by the consumer. While this won't cause an error, it means the UI could proceed before the dismissal is persisted to settings. If the user closes the app or tab immediately after calling this function, the dismissal might not be saved. Consider documenting this behavior or having callers await the promise to ensure persistence completes before allowing the user to proceed.

Copilot uses AI. Check for mistakes.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jesus christ, this guy always has something to say...


const shouldShowDisclaimer = computed(
() => _shouldShowDisclaimer.value && !persistentlyHideDisclaimer.value,
() =>
!hasBeenDismissed.value &&
Boolean(disclaimerText.value) &&
!aiSettingsStore.isDisclaimerDismissed(disclaimerText.value),
);

return { disclaimerText, closeDisclaimer, shouldShowDisclaimer };
Expand Down
Loading
Loading