validated + cleaned

This commit is contained in:
pablodanswer 2024-10-16 14:52:38 -07:00
parent ab09b967ac
commit 100dd0ad53
11 changed files with 88 additions and 42 deletions

View File

@ -28,6 +28,7 @@ export function AssistantGalleryCard({
setPopup: (popup: PopupSpec) => void;
selectedAssistant: boolean;
}) {
const { refreshUser } = useUser();
const router = useRouter();
return (
<div
@ -82,7 +83,7 @@ export function AssistantGalleryCard({
message: `"${assistant.name}" has been removed from your list.`,
type: "success",
});
router.refresh();
await refreshUser();
} else {
setPopup({
message: `"${assistant.name}" could not be removed from your list.`,
@ -110,7 +111,7 @@ export function AssistantGalleryCard({
message: `"${assistant.name}" has been added to your list.`,
type: "success",
});
router.refresh();
await refreshUser();
} else {
setPopup({
message: `"${assistant.name}" could not be added to your list.`,

View File

@ -27,11 +27,17 @@ export default async function GalleryPage({
openedFolders,
shouldShowWelcomeModal,
toggleSidebar,
hasAnyConnectors,
hasImageCompatibleModel,
} = data;
return (
<>
<AssistantsProvider initialAssistants={assistants}>
<AssistantsProvider
initialAssistants={assistants}
hasAnyConnectors={hasAnyConnectors}
hasImageCompatibleModel={hasImageCompatibleModel}
>
{shouldShowWelcomeModal && <WelcomeModal user={user} />}
<InstantSSRAutoRefresh />

View File

@ -138,7 +138,6 @@ export function AssistantSharingModal({
onOutsideClick={onClose}
>
<div>
{isUpdating && <Spinner />}
<p className="text-text-600 text-lg mb-6">
Manage access to this assistant by sharing it with other users.
</p>
@ -225,6 +224,7 @@ export function AssistantSharingModal({
)}
</div>
</Modal>
{isUpdating && <Spinner />}
</>
);
}

View File

@ -109,6 +109,7 @@ function AssistantListItem({
setPopup: (popupSpec: PopupSpec | null) => void;
isDragging?: boolean;
}) {
const { refreshUser } = useUser();
const router = useRouter();
const [showSharingModal, setShowSharingModal] = useState(false);
@ -203,7 +204,7 @@ function AssistantListItem({
message: `"${assistant.name}" has been removed from your list.`,
type: "success",
});
router.refresh();
await refreshUser();
} else {
setPopup({
message: `"${assistant.name}" could not be removed from your list.`,
@ -226,7 +227,7 @@ function AssistantListItem({
message: `"${assistant.name}" has been added to your list.`,
type: "success",
});
router.refresh();
await refreshUser();
} else {
setPopup({
message: `"${assistant.name}" could not be added to your list.`,
@ -359,7 +360,7 @@ export function AssistantsList() {
message: `"${deletingPersona.name}" has been deleted.`,
type: "success",
});
router.refresh();
await refreshUser();
} else {
setPopup({
message: `"${deletingPersona.name}" could not be deleted.`,
@ -380,7 +381,7 @@ export function AssistantsList() {
makePublicPersona.id,
newPublicStatus
);
router.refresh();
await refreshAssistants();
}}
/>
)}

View File

@ -27,10 +27,16 @@ export default async function GalleryPage({
openedFolders,
shouldShowWelcomeModal,
toggleSidebar,
hasAnyConnectors,
hasImageCompatibleModel,
} = data;
return (
<AssistantsProvider initialAssistants={assistants}>
<AssistantsProvider
initialAssistants={assistants}
hasAnyConnectors={hasAnyConnectors}
hasImageCompatibleModel={hasImageCompatibleModel}
>
{shouldShowWelcomeModal && <WelcomeModal user={user} />}
<InstantSSRAutoRefresh />

View File

@ -35,6 +35,7 @@ export function AssistantsTab({
const [_, llmName] = getFinalLLM(llmProviders, null, null);
const { finalAssistants, refreshAssistants } = useAssistants();
const [assistants, setAssistants] = useState(finalAssistants);
console.log(finalAssistants);
useEffect(() => {
setAssistants(finalAssistants);

View File

@ -34,13 +34,19 @@ export default async function Page({
shouldShowWelcomeModal,
assistants,
userInputPrompts,
hasAnyConnectors,
hasImageCompatibleModel,
} = data;
return (
<>
<InstantSSRAutoRefresh />
{shouldShowWelcomeModal && <WelcomeModal user={user} />}
<AssistantsProvider initialAssistants={assistants}>
<AssistantsProvider
initialAssistants={assistants}
hasAnyConnectors={hasAnyConnectors}
hasImageCompatibleModel={hasImageCompatibleModel}
>
<ChatProvider
value={{
chatSessions,

View File

@ -36,6 +36,7 @@ import WrappedSearch from "./WrappedSearch";
import { SearchProvider } from "@/components/context/SearchContext";
import { fetchLLMProvidersSS } from "@/lib/llm/fetchLLMs";
import { LLMProviderDescriptor } from "../admin/configuration/llm/interfaces";
import { AssistantsProvider } from "@/components/context/AssisantsContext";
import { headers } from "next/headers";
export default async function Home({
@ -193,36 +194,39 @@ export default async function Home({
<HealthCheckBanner />
{shouldShowWelcomeModal && <WelcomeModal user={user} />}
<InstantSSRAutoRefresh />
{shouldDisplayNoSourcesModal && <NoSourcesModal />}
{shouldDisplaySourcesIncompleteModal && (
<NoCompleteSourcesModal ccPairs={ccPairs} />
)}
{/* ChatPopup is a custom popup that displays a admin-specified message on initial user visit.
Only used in the EE version of the app. */}
<ChatPopup />
<SearchProvider
value={{
querySessions,
ccPairs,
documentSets,
assistants,
tags,
agenticSearchEnabled,
disabledAgentic: DISABLE_LLM_DOC_RELEVANCE,
initiallyToggled: toggleSidebar,
shouldShowWelcomeModal,
shouldDisplayNoSources: shouldDisplayNoSourcesModal,
}}
<AssistantsProvider
initialAssistants={assistants}
hasAnyConnectors={hasAnyConnectors}
hasImageCompatibleModel={false}
>
<WrappedSearch
initiallyToggled={toggleSidebar}
searchTypeDefault={searchTypeDefault}
/>
</SearchProvider>
<SearchProvider
value={{
querySessions,
ccPairs,
documentSets,
assistants,
tags,
agenticSearchEnabled,
disabledAgentic: DISABLE_LLM_DOC_RELEVANCE,
initiallyToggled: toggleSidebar,
shouldShowWelcomeModal,
shouldDisplayNoSources: shouldDisplayNoSourcesModal,
}}
>
<WrappedSearch
initiallyToggled={toggleSidebar}
searchTypeDefault={searchTypeDefault}
/>
</SearchProvider>
</AssistantsProvider>
s
</>
);
}

View File

@ -10,6 +10,7 @@ import { AssistantIcon } from "@/components/assistants/AssistantIcon";
import { addAssistantToList } from "@/lib/assistants/updateAssistantPreferences";
import { useAssistants } from "../context/AssisantsContext";
import { useUser } from "../user/UserProvider";
import { Bell } from "@phosphor-icons/react";
export const NotificationCard = () => {
const [showDropdown, setShowDropdown] = useState(false);
@ -118,18 +119,12 @@ export const NotificationCard = () => {
}, [showDropdown]);
return (
<div className="relative">
<div className="my-auto relative">
<div
onClick={() => setShowDropdown(!showDropdown)}
className="cursor-pointer relative notification-dropdown"
>
<svg
className="w-6 h-6 text-text-600 hover:text-text-800"
viewBox="0 0 24 24"
fill="currentColor"
>
<path d="M12 22c1.1 0 2-.9 2-2h-4c0 1.1.9 2 2 2zm6-6v-5c0-3.07-1.63-5.64-4.5-6.32V4c0-.83-.67-1.5-1.5-1.5s-1.5.67-1.5 1.5v.68C7.64 5.36 6 7.92 6 11v5l-2 2v1h16v-1l-2-2zm-2 1H8v-6c0-2.48 1.51-4.5 4-4.5s4 2.02 4 4.5v6z" />
</svg>
<Bell size={20} />
{sortedNotifications.length > 0 && (
<span className="absolute top-0 right-0 h-2 w-2 bg-red-500 rounded-full"></span>
)}

View File

@ -24,7 +24,14 @@ const AssistantsContext = createContext<AssistantsContextProps | undefined>(
export const AssistantsProvider: React.FC<{
children: React.ReactNode;
initialAssistants: Persona[];
}> = ({ children, initialAssistants }) => {
hasAnyConnectors: boolean;
hasImageCompatibleModel: boolean;
}> = ({
children,
initialAssistants,
hasAnyConnectors,
hasImageCompatibleModel,
}) => {
const [assistants, setAssistants] = useState<Persona[]>(
initialAssistants || []
);
@ -39,7 +46,20 @@ export const AssistantsProvider: React.FC<{
},
});
if (!response.ok) throw new Error("Failed to fetch assistants");
const assistants = await response.json();
let assistants: Persona[] = await response.json();
if (!hasImageCompatibleModel) {
assistants = assistants.filter(
(assistant) =>
!assistant.tools.some(
(tool) => tool.in_code_tool_id === "ImageGenerationTool"
)
);
}
if (!hasAnyConnectors) {
assistants = assistants.filter(
(assistant) => assistant.num_chunks === 0
);
}
setAssistants(assistants);
} catch (error) {
console.error("Error refreshing assistants:", error);
@ -56,9 +76,11 @@ export const AssistantsProvider: React.FC<{
user,
assistants
);
const finalAssistants = user
? orderAssistantsForUser(visibleAssistants, user)
: visibleAssistants;
const ownedButHiddenAssistants = getUserCreatedAssistants(
user,
hiddenAssistants

View File

@ -47,6 +47,8 @@ interface FetchChatDataResult {
finalDocumentSidebarInitialWidth?: number;
shouldShowWelcomeModal: boolean;
userInputPrompts: InputPrompt[];
hasAnyConnectors: boolean;
hasImageCompatibleModel: boolean;
}
export async function fetchChatData(searchParams: {
@ -251,5 +253,7 @@ export async function fetchChatData(searchParams: {
toggleSidebar,
shouldShowWelcomeModal,
userInputPrompts,
hasAnyConnectors,
hasImageCompatibleModel,
};
}