Skip to content

Commit 264c8d0

Browse files
author
Mishig
authored
[Assistants] Fix remove behaviour (#869)
Follow up to #859, specifically to [this comment](#859 (comment)) Bug: when a user removes an assistant, the assistant was NOT being removed from the settings list. [This PR fixes this problem](#869 (comment))
1 parent 105d8aa commit 264c8d0

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/routes/+layout.server.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,11 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
7676
.limit(300)
7777
.toArray();
7878

79+
const userAssistants = settings?.assistants?.map((assistantId) => assistantId.toString()) ?? [];
80+
const userAssistantsSet = new Set(userAssistants);
81+
7982
const assistantIds = [
80-
...(settings?.assistants?.map((assistantId) => assistantId) ?? []),
83+
...userAssistants.map((el) => new ObjectId(el)),
8184
...(conversations.map((conv) => conv.assistantId).filter((el) => !!el) as ObjectId[]),
8285
];
8386

@@ -147,7 +150,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
147150
settings?.shareConversationsWithModelAuthors ??
148151
DEFAULT_SETTINGS.shareConversationsWithModelAuthors,
149152
customPrompts: settings?.customPrompts ?? {},
150-
assistants: settings?.assistants?.map((el) => el.toString()) ?? [],
153+
assistants: userAssistants,
151154
},
152155
models: models.map((model) => ({
153156
id: model.id,
@@ -166,12 +169,15 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
166169
unlisted: model.unlisted,
167170
})),
168171
oldModels,
169-
assistants: assistants.map((el) => ({
170-
...el,
171-
_id: el._id.toString(),
172-
createdById: undefined,
173-
createdByMe: el.createdById.toString() === (locals.user?._id ?? locals.sessionId).toString(),
174-
})),
172+
assistants: assistants
173+
.filter((el) => userAssistantsSet.has(el._id.toString()))
174+
.map((el) => ({
175+
...el,
176+
_id: el._id.toString(),
177+
createdById: undefined,
178+
createdByMe:
179+
el.createdById.toString() === (locals.user?._id ?? locals.sessionId).toString(),
180+
})),
175181
user: locals.user && {
176182
id: locals.user._id.toString(),
177183
username: locals.user.username,

0 commit comments

Comments
 (0)