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: changing tools while conversing results in incorrect tool use (#6985)

Louis6afeed8ba87a
diff --git a/web-app/src/hooks/useChat.ts b/web-app/src/hooks/useChat.ts
index e99f8471f..56e42cc91 100644
--- a/web-app/src/hooks/useChat.ts
+++ b/web-app/src/hooks/useChat.ts
@@ -43,6 +43,7 @@ import { useShallow } from 'zustand/shallow'
import { TEMPORARY_CHAT_QUERY_ID, TEMPORARY_CHAT_ID } from '@/constants/chat'
import { toast } from 'sonner'
import { Attachment } from '@/types/attachment'
+import { MCPTool } from '@/types/completion'
// Helper to create thread content with consistent structure
const createThreadContent = (
@@ -668,12 +669,21 @@ export const useChat = () => {
let isCompleted = false
+ const disabledTools = getDisabledToolsForThread(activeThread.id)
+ const isToolDisabled = (tool: MCPTool) => {
+ const compositeKey = `${tool.server}::${tool.name}`
+ return (
+ disabledTools.includes(compositeKey) ||
+ // Backwards compatibility with pre-migration keys
+ disabledTools.includes(tool.name)
+ )
+ }
+
// Filter tools based on model capabilities and available tools for this thread
let availableTools = selectedModel?.capabilities?.includes('tools')
- ? useAppState.getState().tools.filter((tool) => {
- const disabledTools = getDisabledToolsForThread(activeThread.id)
- return !disabledTools.includes(tool.name)
- })
+ ? useAppState
+ .getState()
+ .tools.filter((tool) => !isToolDisabled(tool))
: []
// Conditionally inject RAG if tools are supported and documents are attached
@@ -691,7 +701,10 @@ export const useChat = () => {
.getTools()
.catch(() => [])
if (Array.isArray(ragTools) && ragTools.length) {
- availableTools = [...availableTools, ...ragTools]
+ const enabledRagTools = ragTools.filter(
+ (tool) => !isToolDisabled(tool)
+ )
+ availableTools = [...availableTools, ...enabledRagTools]
console.log('RAG tools injected for completion.')
}
} catch (e) {