Skip to content

Conversation

mishig25
Copy link
Collaborator

@mishig25 mishig25 commented Feb 22, 2024

Follow up to #859, specifically to this comment

Bug: when a user removes an assistant, the assistant was NOT being removed from the settings list.
This PR fixes this problem

createdByMe: el.createdById.toString() === (locals.user?._id ?? locals.sessionId).toString(),
})),
assistants: assistants
.filter((el) => userAssistantsSet.has(el._id.toString()))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this filter is the key line

@mishig25 mishig25 marked this pull request as ready for review February 22, 2024 15:55
@@ -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);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have EqualitySet that we could bring to this codebase:

/**
 * Subclass of Set but works with non-primitives
 * using a bijective object to id mapping.
 * (passed to the constructor)
 *
 * By default the mapping is calling the String function on the
 * object.
 */
export class EqualitySet<K = ObjectId> extends Set<unknown> {
	private oToId: (o: K) => string;

	constructor(oToId?: (o: K) => string);
	constructor(iterable: Iterable<K>, oToId?: (o: K) => string);
	constructor(iterableOrFn?: Iterable<K> | ((o: K) => string), oToId?: (o: K) => string) {
		super();

		const iterable = oToId
			? (iterableOrFn as Iterable<K>)
			: iterableOrFn
				? Symbol.iterator in iterableOrFn
					? (iterableOrFn as Iterable<K>)
					: undefined
				: undefined;

		this.oToId = (iterable ? oToId : (iterableOrFn as (o: K) => string)) || String;

		/// do not pass iterable to super()
		/// because this.oToId is not yet defined.
		if (iterable) {
			for (const k of iterable) {
				this.add(k);
			}
		}
	}

	override delete(key: K): boolean {
		return super.delete(this.oToId(key));
	}

	override has(key: K): boolean {
		return super.has(this.oToId(key));
	}

	override add(key: K): this {
		return super.add(this.oToId(key));
	}

	*toIterable<Ret = K>(idToObject: (str: string) => Ret): Iterable<Ret> {
		for (const val of this) {
			yield idToObject(val as string);
		}
	}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the process of chat-ui becoming moon-landing continues :)

@mishig25 mishig25 merged commit 264c8d0 into main Feb 22, 2024
@mishig25 mishig25 deleted the assistants_remove_behaviour branch February 22, 2024 23:24
ice91 pushed a commit to ice91/chat-ui that referenced this pull request Oct 30, 2024
Follow up to huggingface#859,
specifically to [this
comment](huggingface#859 (comment))

Bug: when a user removes an assistant, the assistant was NOT being
removed from the settings list.
[This PR fixes this
problem](huggingface#869 (comment))
JulienDelavande pushed a commit to JulienDelavande/chat-ui-energy-score that referenced this pull request Apr 7, 2025
Follow up to huggingface/chat-ui#859,
specifically to [this
comment](huggingface/chat-ui#859 (comment))

Bug: when a user removes an assistant, the assistant was NOT being
removed from the settings list.
[This PR fixes this
problem](huggingface/chat-ui#869 (comment))
Matsenas pushed a commit to Matsenas/chat-ui that referenced this pull request Jul 4, 2025
Follow up to huggingface#859,
specifically to [this
comment](huggingface#859 (comment))

Bug: when a user removes an assistant, the assistant was NOT being
removed from the settings list.
[This PR fixes this
problem](huggingface#869 (comment))
Matsenas pushed a commit to Matsenas/chat-ui that referenced this pull request Jul 4, 2025
Follow up to huggingface#859,
specifically to [this
comment](huggingface#859 (comment))

Bug: when a user removes an assistant, the assistant was NOT being
removed from the settings list.
[This PR fixes this
problem](huggingface#869 (comment))
gary149 pushed a commit to gary149/chat-ui that referenced this pull request Aug 29, 2025
Follow up to huggingface#859,
specifically to [this
comment](huggingface#859 (comment))

Bug: when a user removes an assistant, the assistant was NOT being
removed from the settings list.
[This PR fixes this
problem](huggingface#869 (comment))
gary149 pushed a commit to gary149/chat-ui that referenced this pull request Aug 29, 2025
Follow up to huggingface#859,
specifically to [this
comment](huggingface#859 (comment))

Bug: when a user removes an assistant, the assistant was NOT being
removed from the settings list.
[This PR fixes this
problem](huggingface#869 (comment))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants