Skip to content

Commit

Permalink
[Assistants] Fix remove behaviour (#869)
Browse files Browse the repository at this point in the history
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))
  • Loading branch information
Mishig authored Feb 22, 2024
1 parent 105d8aa commit 264c8d0
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/routes/+layout.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
.limit(300)
.toArray();

const userAssistants = settings?.assistants?.map((assistantId) => assistantId.toString()) ?? [];
const userAssistantsSet = new Set(userAssistants);

const assistantIds = [
...(settings?.assistants?.map((assistantId) => assistantId) ?? []),
...userAssistants.map((el) => new ObjectId(el)),
...(conversations.map((conv) => conv.assistantId).filter((el) => !!el) as ObjectId[]),
];

Expand Down Expand Up @@ -147,7 +150,7 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
settings?.shareConversationsWithModelAuthors ??
DEFAULT_SETTINGS.shareConversationsWithModelAuthors,
customPrompts: settings?.customPrompts ?? {},
assistants: settings?.assistants?.map((el) => el.toString()) ?? [],
assistants: userAssistants,
},
models: models.map((model) => ({
id: model.id,
Expand All @@ -166,12 +169,15 @@ export const load: LayoutServerLoad = async ({ locals, depends }) => {
unlisted: model.unlisted,
})),
oldModels,
assistants: assistants.map((el) => ({
...el,
_id: el._id.toString(),
createdById: undefined,
createdByMe: el.createdById.toString() === (locals.user?._id ?? locals.sessionId).toString(),
})),
assistants: assistants
.filter((el) => userAssistantsSet.has(el._id.toString()))
.map((el) => ({
...el,
_id: el._id.toString(),
createdById: undefined,
createdByMe:
el.createdById.toString() === (locals.user?._id ?? locals.sessionId).toString(),
})),
user: locals.user && {
id: locals.user._id.toString(),
username: locals.user.username,
Expand Down

0 comments on commit 264c8d0

Please sign in to comment.