Skip to content

Webui - change setText command from parent window to also send the message. #13309

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified tools/server/public/index.html.gz
Binary file not shown.
3 changes: 3 additions & 0 deletions tools/server/webui/src/components/ChatScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ export default function ChatScreen() {
clearExtraContext();
};

// for vscode context
textarea.refOnSubmit.current = sendNewMessage;

const handleEditMessage = async (msg: Message, content: string) => {
if (!viewingChat) return;
setCurrNodeId(msg.id);
Expand Down
3 changes: 3 additions & 0 deletions tools/server/webui/src/components/useChatTextarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export interface ChatTextareaApi {
setValue: (value: string) => void;
focus: () => void;
ref: React.RefObject<HTMLTextAreaElement>;
refOnSubmit: React.MutableRefObject<(() => void) | null>; // Submit handler
onInput: (event: React.FormEvent<HTMLTextAreaElement>) => void; // Input handler
}

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

// Effect to set initial value and height on mount or when initValue changes
useEffect(() => {
Expand Down Expand Up @@ -91,6 +93,7 @@ export function useChatTextarea(initValue: string): ChatTextareaApi {
}
},
ref: textareaRef,
refOnSubmit: onSubmitRef,
onInput: handleInput,
};
}
3 changes: 3 additions & 0 deletions tools/server/webui/src/utils/llama-vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ export const useVSCodeContext = (textarea: ChatTextareaApi) => {
});
}
textarea.focus();
setTimeout(() => {
textarea.refOnSubmit.current?.();
}, 10); // wait for setExtraContext to finish
Comment on lines +36 to +38
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok seems like if this is called right away, setExtraContext hasn't yet finished, hence why you don't see it. Can you give it a try now?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works now. Thanks!

}
};

Expand Down