Repository: ggerganov/llama.cpp
File: tools/server/webui/src/lib/stores/chat.svelte.ts (TypeScript)

Code before:
	 * @param allMessages - All messages in the conversation
	 * @param assistantMessage - The assistant message to stream content into
	 * @param onComplete - Optional callback when streaming completes
	 * @param onError - Optional callback when an error occurs
	 */
	private async streamChatCompletion(
		allMessages: DatabaseMessage[],
		assistantMessage: DatabaseMessage,
		onComplete?: (content: string) => Promise<void>,
		onError?: (error: Error) => void
	): Promise<void> {
		let streamedContent = '';
		let streamedReasoningContent = '';

		let resolvedModel: string | null = null;
		let modelPersisted = false;

		const recordModel = (modelName: string, persistImmediately = true): void => {
			const normalizedModel = normalizeModelName(modelName);

			if (!normalizedModel || normalizedModel === resolvedModel) {
				return;
			}

			resolvedModel = normalizedModel;

			const messageIndex = this.findMessageIndex(assistantMessage.id);

			this.updateMessageAtIndex(messageIndex, { model: normalizedModel });

			if (persistImmediately && !modelPersisted) {
				modelPersisted = true;
				DatabaseStore.updateMessage(assistantMessage.id, { model: normalizedModel }).catch(
					(error) => {
						console.error('Failed to persist model name:', error);
						modelPersisted = false;
						resolvedModel = null;
					}
				);
			}
		};

		slotsService.startStreaming();
		slotsService.setActiveConversation(assistantMessage.convId);

		await chatService.sendMessage(
			allMessages,
			{
				...this.getApiOptions(),

				onChunk: (chunk: string) => {

Review comment (suggestion):
```suggestion
			serverPropsRefreshRequested = false;

			if (options?.immediate) {
```

Code after:
	 * Handles streaming chat completion with the AI model
	 * @param allMessages - All messages in the conversation
	 * @param assistantMessage - The assistant message to stream content into
	 * @param onComplete - Optional callback when streaming completes
	 * @param onError - Optional callback when an error occurs
	 */
	private async streamChatCompletion(
		allMessages: DatabaseMessage[],
		assistantMessage: DatabaseMessage,
		onComplete?: (content: string) => Promise<void>,
		onError?: (error: Error) => void
	): Promise<void> {
		let streamedContent = '';
		let streamedReasoningContent = '';

		let resolvedModel: string | null = null;
		let modelPersisted = false;
		const currentConfig = config();
		const preferServerPropsModel = !currentConfig.modelSelectorEnabled;
		let serverPropsRefreshed = false;
		let updateModelFromServerProps: ((persistImmediately?: boolean) => void) | null = null;

		const refreshServerPropsOnce = () => {
			if (serverPropsRefreshed) {
				return;
			}

			serverPropsRefreshed = true;

			const hasExistingProps = serverStore.serverProps !== null;

			serverStore
				.fetchServerProps({ silent: hasExistingProps })
				.then(() => {
					updateModelFromServerProps?.(true);
				})
				.catch((error) => {
					console.warn('Failed to refresh server props after streaming started:', error);
				});
		};

		const recordModel = (modelName: string | null | undefined, persistImmediately = true): void => {
			const serverModelName = serverStore.modelName;
			const preferredModelSource = preferServerPropsModel
				? (serverModelName ?? modelName ?? null)
				: (modelName ?? serverModelName ?? null);

			if (!preferredModelSource) {
				return;
			}