[Chore]: sendCommand non positional call signature (#4218)

Chore: `sendCommand` non positional call signature
This commit is contained in:
Timothy Carambat 2025-07-30 11:28:02 -07:00 committed by GitHub
parent 70a07b743b
commit 24f176c049
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 39 additions and 30 deletions

View File

@ -82,7 +82,7 @@ export default function ChatHistory({
}; };
const handleSendSuggestedMessage = (heading, message) => { const handleSendSuggestedMessage = (heading, message) => {
sendCommand(`${heading} ${message}`, true); sendCommand({ text: `${heading} ${message}`, autoSubmit: true });
}; };
const saveEditedMessage = async ({ const saveEditedMessage = async ({
@ -107,7 +107,12 @@ export default function ChatHistory({
updatedHistory[updatedHistory.length - 1].content = editedMessage; updatedHistory[updatedHistory.length - 1].content = editedMessage;
// remove all edited messages after the edited message in backend // remove all edited messages after the edited message in backend
await Workspace.deleteEditedChats(workspace.slug, threadSlug, chatId); await Workspace.deleteEditedChats(workspace.slug, threadSlug, chatId);
sendCommand(editedMessage, true, updatedHistory, attachments); sendCommand({
text: editedMessage,
autoSubmit: true,
history: updatedHistory,
attachments,
});
return; return;
} }

View File

@ -80,7 +80,7 @@ export function AvailableAgents({
const handleAgentClick = () => { const handleAgentClick = () => {
setShowing(false); setShowing(false);
sendCommand("@agent ", false); sendCommand({ text: "@agent " });
promptRef?.current?.focus(); promptRef?.current?.focus();
}; };

View File

@ -119,7 +119,7 @@ export default function SlashPresets({ setShowing, sendCommand, promptRef }) {
preset={preset} preset={preset}
onUse={() => { onUse={() => {
setShowing(false); setShowing(false);
sendCommand(`${preset.command} `, false); sendCommand({ text: `${preset.command} ` });
promptRef?.current?.focus(); promptRef?.current?.focus();
}} }}
onEdit={handleEditPreset} onEdit={handleEditPreset}

View File

@ -8,7 +8,7 @@ export default function EndAgentSession({ setShowing, sendCommand }) {
<button <button
onClick={() => { onClick={() => {
setShowing(false); setShowing(false);
sendCommand("/exit", true); sendCommand({ text: "/exit", autoSubmit: true });
}} }}
className="border-none w-full hover:cursor-pointer hover:bg-theme-action-menu-item-hover px-2 py-2 rounded-xl flex flex-col justify-start" className="border-none w-full hover:cursor-pointer hover:bg-theme-action-menu-item-hover px-2 py-2 rounded-xl flex flex-col justify-start"
> >

View File

@ -10,7 +10,7 @@ export default function ResetCommand({ setShowing, sendCommand }) {
<button <button
onClick={() => { onClick={() => {
setShowing(false); setShowing(false);
sendCommand("/reset", true); sendCommand({ text: "/reset", autoSubmit: true });
}} }}
className="border-none w-full hover:cursor-pointer hover:bg-theme-action-menu-item-hover px-2 py-2 rounded-xl flex flex-col justify-start" className="border-none w-full hover:cursor-pointer hover:bg-theme-action-menu-item-hover px-2 py-2 rounded-xl flex flex-col justify-start"
> >

View File

@ -48,7 +48,10 @@ export default function SpeechToText({ sendCommand }) {
function endSTTSession() { function endSTTSession() {
SpeechRecognition.stopListening(); SpeechRecognition.stopListening();
if (transcript.length > 0) { if (transcript.length > 0) {
sendCommand(transcript, Appearance.get("autoSubmitSttInput")); sendCommand({
text: transcript,
autoSubmit: Appearance.get("autoSubmitSttInput"),
});
} }
resetTranscript(); resetTranscript();
@ -92,7 +95,7 @@ export default function SpeechToText({ sendCommand }) {
useEffect(() => { useEffect(() => {
if (transcript?.length > 0 && listening) { if (transcript?.length > 0 && listening) {
sendCommand(transcript, false); sendCommand({ text: transcript });
clearTimeout(timeout); clearTimeout(timeout);
timeout = setTimeout(() => { timeout = setTimeout(() => {
endSTTSession(); endSTTSession();

View File

@ -85,33 +85,34 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
const lastUserMessage = updatedHistory.slice(-1)[0]; const lastUserMessage = updatedHistory.slice(-1)[0];
Workspace.deleteChats(workspace.slug, [chatId]) Workspace.deleteChats(workspace.slug, [chatId])
.then(() => .then(() =>
sendCommand( sendCommand({
lastUserMessage.content, text: lastUserMessage.content,
true, autoSubmit: true,
updatedHistory, history: updatedHistory,
lastUserMessage?.attachments attachments: lastUserMessage?.attachments,
) })
) )
.catch((e) => console.error(e)); .catch((e) => console.error(e));
}; };
/** /**
* Send a command to the LLM prompt input. * Send a command to the LLM prompt input.
* @param {string} command - The command to send to the LLM * @param {Object} options - Arguments to send to the LLM
* @param {boolean} submit - Whether the command was submitted (default: false) * @param {string} options.text - The text to send to the LLM
* @param {Object[]} history - The history of the chat * @param {boolean} options.autoSubmit - Determines if the text should be sent immediately or if it should be added to the message state (default: false)
* @param {Object[]} attachments - The attachments to send to the LLM * @param {Object[]} options.history - The history of the chat prior to this message for overriding the current chat history
* @returns {boolean} - Whether the command was sent successfully * @param {Object[import("./DnDWrapper").Attachment]} options.attachments - The attachments to send to the LLM for this message
* @returns {void}
*/ */
const sendCommand = async ( const sendCommand = async ({
command, text = "",
submit = false, autoSubmit = false,
history = [], history = [],
attachments = [] attachments = [],
) => { } = {}) => {
if (!command || command === "") return false; if (!text || text === "") return false;
if (!submit) { if (!autoSubmit) {
setMessageEmit(command); setMessageEmit(text);
return; return;
} }
@ -124,7 +125,7 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
content: "", content: "",
role: "assistant", role: "assistant",
pending: true, pending: true,
userMessage: command, userMessage: text,
attachments, attachments,
animate: true, animate: true,
}, },
@ -133,7 +134,7 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
prevChatHistory = [ prevChatHistory = [
...chatHistory, ...chatHistory,
{ {
content: command, content: text,
role: "user", role: "user",
attachments, attachments,
}, },
@ -141,7 +142,7 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
content: "", content: "",
role: "assistant", role: "assistant",
pending: true, pending: true,
userMessage: command, userMessage: text,
animate: true, animate: true,
}, },
]; ];