- Added a new `DeleteConfirmationDialog` component for confirming deletions. - Updated `KnowledgeDropdown` to include a loading state and improved user feedback during file operations. - Enhanced the search page to support bulk deletion of documents with confirmation dialog. - Integrated event dispatching for knowledge updates after file operations. - Refactored various components for better readability and maintainability.
51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import {
|
|
useQuery,
|
|
useQueryClient,
|
|
UseQueryOptions,
|
|
} from "@tanstack/react-query";
|
|
|
|
type Nudge = string;
|
|
|
|
const DEFAULT_NUDGES = [
|
|
"Show me this quarter's top 10 deals",
|
|
"Summarize recent client interactions",
|
|
"Search OpenSearch for mentions of our competitors",
|
|
];
|
|
|
|
export const useGetNudgesQuery = (
|
|
chatId?: string | null,
|
|
options?: Omit<UseQueryOptions, "queryKey" | "queryFn">
|
|
) => {
|
|
const queryClient = useQueryClient();
|
|
|
|
function cancel() {
|
|
queryClient.removeQueries({ queryKey: ["nudges", chatId] });
|
|
}
|
|
|
|
async function getNudges(): Promise<Nudge[]> {
|
|
try {
|
|
const response = await fetch(`/api/nudges${chatId ? `/${chatId}` : ""}`);
|
|
const data = await response.json();
|
|
|
|
if (data.response && typeof data.response === "string") {
|
|
return data.response.split("\n").filter(Boolean);
|
|
}
|
|
|
|
return DEFAULT_NUDGES;
|
|
} catch (error) {
|
|
console.error("Error getting nudges", error);
|
|
return DEFAULT_NUDGES;
|
|
}
|
|
}
|
|
|
|
const queryResult = useQuery(
|
|
{
|
|
queryKey: ["nudges", chatId],
|
|
queryFn: getNudges,
|
|
...options,
|
|
},
|
|
queryClient
|
|
);
|
|
|
|
return { ...queryResult, cancel };
|
|
};
|