Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
fix(llm): refresh chat models when providers change in settings
Elian Doran420bdb9116c1
diff --git a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.tsindex 9cc118c58a..89f1055f03 100644--- a/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts+++ b/apps/client/src/widgets/type_widgets/llm_chat/useLlmChat.ts@@ -4,6 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks"import { getAvailableModels, streamChatCompletion } from "../../../services/llm_chat.js";import { randomString } from "../../../services/utils.js";+import { useTriliumEvent } from "../../react/hooks.js";import type { ContentBlock, FileBlock, ImageBlock, LlmChatContent, StoredMessage, TextFileBlock } from "./llm_chat_types.js";import { useSmoothStreaming } from "./useSmoothStreaming.js";@@ -206,6 +207,16 @@ export function useLlmChat(refreshModels();}, []);+ // Re-fetch models when providers are (re)configured elsewhere — e.g. via the+ // settings page — so the chat picks up newly added providers and clears the+ // "no provider configured" prompt without requiring a page reload.+ useTriliumEvent("entitiesReloaded", useCallback(({ loadResults }) => {+ const optionNames = loadResults.getOptionNames();+ if (optionNames.includes("llmProviders") || optionNames.includes("aiEnabled")) {+ refreshModels();+ }+ }, [refreshModels]));+// Track whether the user is near the bottom of the scroll containeruseEffect(() => {const container = scrollContainerRef.current;