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

View File

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

View File

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

View File

@ -8,7 +8,7 @@ export default function EndAgentSession({ setShowing, sendCommand }) {
<button
onClick={() => {
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"
>

View File

@ -10,7 +10,7 @@ export default function ResetCommand({ setShowing, sendCommand }) {
<button
onClick={() => {
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"
>

View File

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

View File

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