Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix: tools use issue

Louis6d169d0a1481
diff --git a/web-app/src/hooks/use-chat.ts b/web-app/src/hooks/use-chat.ts
index 38e9bcf50..480c97a6c 100644
--- a/web-app/src/hooks/use-chat.ts
+++ b/web-app/src/hooks/use-chat.ts
@@ -143,7 +143,7 @@ export function useChat(
if (transportRef.current) {
// Use forceRefreshTools to update the transport's tool cache
// This ensures the transport has the latest tools when MCP server status changes
- transportRef.current.forceRefreshTools()
+ transportRef.current.refreshTools()
}
}, [mcpToolNames, ragToolNames])
diff --git a/web-app/src/lib/custom-chat-transport.ts b/web-app/src/lib/custom-chat-transport.ts
index 47a6b0610..e1c13bb44 100644
--- a/web-app/src/lib/custom-chat-transport.ts
+++ b/web-app/src/lib/custom-chat-transport.ts
@@ -102,7 +102,7 @@ export class CustomChatTransport implements ChatTransport<UIMessage> {
* Filters out disabled tools based on thread settings
* @private
*/
- private async refreshTools() {
+ async refreshTools() {
if (!this.serviceHub) {
this.tools = {}
return
@@ -184,14 +184,6 @@ export class CustomChatTransport implements ChatTransport<UIMessage> {
return this.tools
}
- /**
- * Force refresh tools from services
- * Called when MCP server status changes or tools are updated
- */
- async forceRefreshTools() {
- await this.refreshTools()
- }
-
async sendMessages(
options: {
chatId: string
@@ -202,6 +194,10 @@ export class CustomChatTransport implements ChatTransport<UIMessage> {
messageId: string | undefined
} & ChatRequestOptions
): Promise<ReadableStream<UIMessageChunk>> {
+
+ // Ensure tools updated before sending messages
+ await this.refreshTools()
+
// Initialize model if not already initialized
const modelId = useModelProvider.getState().selectedModel?.id
const providerId = useModelProvider.getState().selectedProvider