mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-09-26 11:58:28 +02:00
Assistant cleanup (#3236)
* minor cleanup * ensure users don't modify built-in attributes of assistants * update sidebar * k * update update flow + assistant creation
This commit is contained in:
@@ -379,6 +379,7 @@ export function AssistantEditor({
|
||||
if (!promptResponse.ok) {
|
||||
error = await promptResponse.text();
|
||||
}
|
||||
|
||||
if (!personaResponse) {
|
||||
error = "Failed to create Assistant - no response received";
|
||||
} else if (!personaResponse.ok) {
|
||||
|
@@ -259,9 +259,29 @@ export async function updatePersona(
|
||||
): Promise<[Response, Response | null]> {
|
||||
const { id, existingPromptId } = personaUpdateRequest;
|
||||
|
||||
// first update prompt
|
||||
let fileId = null;
|
||||
if (personaUpdateRequest.uploaded_image) {
|
||||
fileId = await uploadFile(personaUpdateRequest.uploaded_image);
|
||||
if (!fileId) {
|
||||
return [new Response(null, { status: 400 }), null];
|
||||
}
|
||||
}
|
||||
|
||||
const updatePersonaResponse = await fetch(`/api/persona/${id}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(
|
||||
buildPersonaAPIBody(personaUpdateRequest, existingPromptId ?? 0, fileId)
|
||||
),
|
||||
});
|
||||
|
||||
if (!updatePersonaResponse.ok) {
|
||||
return [updatePersonaResponse, null];
|
||||
}
|
||||
|
||||
let promptResponse;
|
||||
let promptId;
|
||||
if (existingPromptId !== undefined) {
|
||||
promptResponse = await updatePrompt({
|
||||
promptId: existingPromptId,
|
||||
@@ -270,7 +290,6 @@ export async function updatePersona(
|
||||
taskPrompt: personaUpdateRequest.task_prompt,
|
||||
includeCitations: personaUpdateRequest.include_citations,
|
||||
});
|
||||
promptId = existingPromptId;
|
||||
} else {
|
||||
promptResponse = await createPrompt({
|
||||
personaName: personaUpdateRequest.name,
|
||||
@@ -278,30 +297,8 @@ export async function updatePersona(
|
||||
taskPrompt: personaUpdateRequest.task_prompt,
|
||||
includeCitations: personaUpdateRequest.include_citations,
|
||||
});
|
||||
promptId = promptResponse.ok ? (await promptResponse.json()).id : null;
|
||||
}
|
||||
|
||||
let fileId = null;
|
||||
if (personaUpdateRequest.uploaded_image) {
|
||||
fileId = await uploadFile(personaUpdateRequest.uploaded_image);
|
||||
if (!fileId) {
|
||||
return [promptResponse, null];
|
||||
}
|
||||
}
|
||||
|
||||
const updatePersonaResponse =
|
||||
promptResponse.ok && promptId
|
||||
? await fetch(`/api/persona/${id}`, {
|
||||
method: "PATCH",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: JSON.stringify(
|
||||
buildPersonaAPIBody(personaUpdateRequest, promptId, fileId)
|
||||
),
|
||||
})
|
||||
: null;
|
||||
|
||||
return [promptResponse, updatePersonaResponse];
|
||||
}
|
||||
|
||||
|
@@ -33,18 +33,19 @@ import {
|
||||
} from "@/components/ui/select";
|
||||
|
||||
export function AssistantGalleryCard({
|
||||
onlyAssistant,
|
||||
assistant,
|
||||
user,
|
||||
setPopup,
|
||||
selectedAssistant,
|
||||
}: {
|
||||
onlyAssistant: boolean;
|
||||
assistant: Persona;
|
||||
user: User | null;
|
||||
setPopup: (popup: PopupSpec) => void;
|
||||
selectedAssistant: boolean;
|
||||
}) {
|
||||
const { data: categories } = useCategories();
|
||||
|
||||
const { refreshUser } = useUser();
|
||||
|
||||
return (
|
||||
@@ -83,10 +84,7 @@ export function AssistantGalleryCard({
|
||||
"
|
||||
icon={FiMinus}
|
||||
onClick={async () => {
|
||||
if (
|
||||
user.preferences?.chosen_assistants &&
|
||||
user.preferences?.chosen_assistants.length === 1
|
||||
) {
|
||||
if (onlyAssistant) {
|
||||
setPopup({
|
||||
message: `Cannot remove "${assistant.name}" - you must have at least one assistant.`,
|
||||
type: "error",
|
||||
@@ -356,6 +354,7 @@ export function AssistantsGallery() {
|
||||
>
|
||||
{defaultAssistants.map((assistant) => (
|
||||
<AssistantGalleryCard
|
||||
onlyAssistant={visibleAssistants.length === 1}
|
||||
selectedAssistant={visibleAssistants.includes(assistant)}
|
||||
key={assistant.id}
|
||||
assistant={assistant}
|
||||
@@ -389,6 +388,7 @@ export function AssistantsGallery() {
|
||||
>
|
||||
{nonDefaultAssistants.map((assistant) => (
|
||||
<AssistantGalleryCard
|
||||
onlyAssistant={visibleAssistants.length === 1}
|
||||
selectedAssistant={visibleAssistants.includes(assistant)}
|
||||
key={assistant.id}
|
||||
assistant={assistant}
|
||||
|
@@ -60,7 +60,7 @@ import { CustomTooltip } from "@/components/tooltip/CustomTooltip";
|
||||
import { useAssistants } from "@/components/context/AssistantsContext";
|
||||
import { useUser } from "@/components/user/UserProvider";
|
||||
|
||||
function DraggableAssistantListItem(props: any) {
|
||||
function DraggableAssistantListItem({ ...props }: any) {
|
||||
const {
|
||||
attributes,
|
||||
listeners,
|
||||
@@ -100,6 +100,7 @@ function AssistantListItem({
|
||||
deleteAssistant,
|
||||
shareAssistant,
|
||||
isDragging,
|
||||
onlyAssistant,
|
||||
}: {
|
||||
assistant: Persona;
|
||||
user: User | null;
|
||||
@@ -109,14 +110,13 @@ function AssistantListItem({
|
||||
shareAssistant: Dispatch<SetStateAction<Persona | null>>;
|
||||
setPopup: (popupSpec: PopupSpec | null) => void;
|
||||
isDragging?: boolean;
|
||||
onlyAssistant: boolean;
|
||||
}) {
|
||||
const { refreshUser } = useUser();
|
||||
const router = useRouter();
|
||||
const [showSharingModal, setShowSharingModal] = useState(false);
|
||||
|
||||
const isOwnedByUser = checkUserOwnsAssistant(user, assistant);
|
||||
const currentChosenAssistants = user?.preferences
|
||||
?.chosen_assistants as number[];
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -192,13 +192,14 @@ function AssistantListItem({
|
||||
key="remove"
|
||||
className="flex items-center gap-x-2 px-4 py-2 hover:bg-gray-100 w-full text-left"
|
||||
onClick={async () => {
|
||||
if (currentChosenAssistants?.length === 1) {
|
||||
if (onlyAssistant) {
|
||||
setPopup({
|
||||
message: `Cannot remove "${assistant.name}" - you must have at least one assistant.`,
|
||||
type: "error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const success = await removeAssistantFromList(
|
||||
assistant.id
|
||||
);
|
||||
@@ -432,6 +433,7 @@ export function AssistantsList() {
|
||||
<div className="w-full items-center py-4">
|
||||
{currentlyVisibleAssistants.map((assistant, index) => (
|
||||
<DraggableAssistantListItem
|
||||
onlyAssistant={currentlyVisibleAssistants.length === 1}
|
||||
deleteAssistant={setDeletingPersona}
|
||||
shareAssistant={setMakePublicPersona}
|
||||
key={assistant.id}
|
||||
@@ -461,6 +463,7 @@ export function AssistantsList() {
|
||||
<div className="w-full p-4">
|
||||
{ownedButHiddenAssistants.map((assistant, index) => (
|
||||
<AssistantListItem
|
||||
onlyAssistant={currentlyVisibleAssistants.length === 1}
|
||||
deleteAssistant={setDeletingPersona}
|
||||
shareAssistant={setMakePublicPersona}
|
||||
key={assistant.id}
|
||||
|
@@ -8,13 +8,6 @@ import {
|
||||
} from "@/app/admin/configuration/llm/interfaces";
|
||||
import { ToolSnapshot } from "../tools/interfaces";
|
||||
import { fetchToolsSS } from "../tools/fetchTools";
|
||||
import {
|
||||
OpenAIIcon,
|
||||
AnthropicIcon,
|
||||
AWSIcon,
|
||||
AzureIcon,
|
||||
OpenSourceIcon,
|
||||
} from "@/components/icons/icons";
|
||||
|
||||
export async function fetchAssistantEditorInfoSS(
|
||||
personaId?: number | string
|
||||
@@ -104,15 +97,22 @@ export async function fetchAssistantEditorInfoSS(
|
||||
? ((await personaResponse.json()) as Persona)
|
||||
: null;
|
||||
|
||||
return [
|
||||
{
|
||||
ccPairs,
|
||||
documentSets,
|
||||
llmProviders,
|
||||
user,
|
||||
existingPersona,
|
||||
tools: toolsResponse,
|
||||
},
|
||||
null,
|
||||
];
|
||||
let error: string | null = null;
|
||||
if (existingPersona?.builtin_persona) {
|
||||
return [null, "cannot update builtin persona"];
|
||||
}
|
||||
|
||||
return (
|
||||
error || [
|
||||
{
|
||||
ccPairs,
|
||||
documentSets,
|
||||
llmProviders,
|
||||
user,
|
||||
existingPersona,
|
||||
tools: toolsResponse,
|
||||
},
|
||||
null,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
Reference in New Issue
Block a user