Skip to content

Commit b34c859

Browse files
igardevigardevngxson
authored
server : Webui - change setText command from parent window to also send the message. (ggml-org#13309)
* setText command from parent window for llama-vscode now sends the message automatically. * Upgrade packages versions to fix vulnerabilities with "npm audit fix" command. * Fix code formatting. * Add index.html.gz changes. * Revert "Upgrade packages versions to fix vulnerabilities with "npm audit fix" command." This reverts commit 67687b7. * easier approach * add setTimeout --------- Co-authored-by: igardev <[email protected]> Co-authored-by: Xuan Son Nguyen <[email protected]>
1 parent 9b61acf commit b34c859

File tree

4 files changed

+9
-0
lines changed

4 files changed

+9
-0
lines changed

tools/server/public/index.html.gz

46 Bytes
Binary file not shown.

tools/server/webui/src/components/ChatScreen.tsx

+3
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ export default function ChatScreen() {
157157
clearExtraContext();
158158
};
159159

160+
// for vscode context
161+
textarea.refOnSubmit.current = sendNewMessage;
162+
160163
const handleEditMessage = async (msg: Message, content: string) => {
161164
if (!viewingChat) return;
162165
setCurrNodeId(msg.id);

tools/server/webui/src/components/useChatTextarea.ts

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export interface ChatTextareaApi {
3737
setValue: (value: string) => void;
3838
focus: () => void;
3939
ref: React.RefObject<HTMLTextAreaElement>;
40+
refOnSubmit: React.MutableRefObject<(() => void) | null>; // Submit handler
4041
onInput: (event: React.FormEvent<HTMLTextAreaElement>) => void; // Input handler
4142
}
4243

@@ -46,6 +47,7 @@ export interface ChatTextareaApi {
4647
export function useChatTextarea(initValue: string): ChatTextareaApi {
4748
const [savedInitValue, setSavedInitValue] = useState<string>(initValue);
4849
const textareaRef = useRef<HTMLTextAreaElement>(null);
50+
const onSubmitRef = useRef<(() => void) | null>(null);
4951

5052
// Effect to set initial value and height on mount or when initValue changes
5153
useEffect(() => {
@@ -91,6 +93,7 @@ export function useChatTextarea(initValue: string): ChatTextareaApi {
9193
}
9294
},
9395
ref: textareaRef,
96+
refOnSubmit: onSubmitRef,
9497
onInput: handleInput,
9598
};
9699
}

tools/server/webui/src/utils/llama-vscode.ts

+3
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ export const useVSCodeContext = (textarea: ChatTextareaApi) => {
3333
});
3434
}
3535
textarea.focus();
36+
setTimeout(() => {
37+
textarea.refOnSubmit.current?.();
38+
}, 10); // wait for setExtraContext to finish
3639
}
3740
};
3841

0 commit comments

Comments
 (0)