From 7bedea14d8f78b119ca43861a3fad84c1c356238 Mon Sep 17 00:00:00 2001 From: Oleg Shulyakov Date: Thu, 18 Sep 2025 11:50:18 +0300 Subject: [PATCH] fix: Remove vscode logic --- src/components/ChatInput.tsx | 2 -- src/hooks/useVSCode.ts | 62 ------------------------------------ 2 files changed, 64 deletions(-) delete mode 100644 src/hooks/useVSCode.ts diff --git a/src/components/ChatInput.tsx b/src/components/ChatInput.tsx index 0ae45b0..b6db82f 100644 --- a/src/components/ChatInput.tsx +++ b/src/components/ChatInput.tsx @@ -9,7 +9,6 @@ import toast from 'react-hot-toast'; import { useNavigate } from 'react-router'; import { useChatExtraContext } from '../hooks/useChatExtraContext'; import { ChatTextareaApi, useChatTextarea } from '../hooks/useChatTextarea'; -import { useVSCodeContext } from '../hooks/useVSCode'; import { MessageExtra } from '../types'; import { classNames, cleanCurrentUrl } from '../utils'; import { DropzoneArea } from './DropzoneArea'; @@ -45,7 +44,6 @@ export function ChatInput({ const navigate = useNavigate(); const textarea: ChatTextareaApi = useChatTextarea(getPrefilledContent()); const extraContext = useChatExtraContext(); - useVSCodeContext(textarea, extraContext); const sendNewMessage = async () => { const lastInpMsg = textarea.value(); diff --git a/src/hooks/useVSCode.ts b/src/hooks/useVSCode.ts deleted file mode 100644 index 27b8438..0000000 --- a/src/hooks/useVSCode.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { useEffect } from 'react'; -import { ChatExtraContextApi } from './useChatExtraContext'; -import { ChatTextareaApi } from './useChatTextarea'; - -// Extra context when using llama.cpp WebUI from llama-vscode, inside an iframe -// Ref: https://github.com/ggml-org/llama.cpp/pull/11940 - -interface SetTextEvData { - text: string; - context: string; -} - -/** - * To test it: - * window.postMessage({ command: 'setText', text: 'Spot the syntax error', context: 'def test()\n return 123' }, '*'); - */ - -export const useVSCodeContext = ( - textarea: ChatTextareaApi, - extraContext: ChatExtraContextApi -) => { - // Accept setText message from a parent window and set inputMsg and extraContext - useEffect(() => { - const handleMessage = (event: MessageEvent) => { - if (event.data?.command === 'setText') { - const data: SetTextEvData = event.data; - textarea.setValue(data?.text); - if (data?.context && data.context.length > 0) { - extraContext.clearItems(); - extraContext.addItems([ - { - type: 'context', - name: 'Extra context', - content: data.context, - }, - ]); - } - textarea.focus(); - setTimeout(() => { - textarea.refOnSubmit.current?.(); - }, 10); // wait for setExtraContext to finish - } - }; - - window.addEventListener('message', handleMessage); - return () => window.removeEventListener('message', handleMessage); - }, [textarea, extraContext]); - - // Add a keydown listener that sends the "escapePressed" message to the parent window - useEffect(() => { - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Escape') { - window.parent.postMessage({ command: 'escapePressed' }, '*'); - } - }; - - window.addEventListener('keydown', handleKeyDown); - return () => window.removeEventListener('keydown', handleKeyDown); - }, []); - - return {}; -};