θΏ™ζ˜―indexlocζδΎ›ηš„ζœεŠ‘οΌŒδΈθ¦θΎ“ε…₯任何密码
Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -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 ({
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export function AvailableAgents({

const handleAgentClick = () => {
setShowing(false);
sendCommand("@agent ", false);
sendCommand({ text: "@agent " });
promptRef?.current?.focus();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
45 changes: 23 additions & 22 deletions frontend/src/components/WorkspaceChat/ChatContainer/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -124,7 +125,7 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
content: "",
role: "assistant",
pending: true,
userMessage: command,
userMessage: text,
attachments,
animate: true,
},
Expand All @@ -133,15 +134,15 @@ export default function ChatContainer({ workspace, knownHistory = [] }) {
prevChatHistory = [
...chatHistory,
{
content: command,
content: text,
role: "user",
attachments,
},
{
content: "",
role: "assistant",
pending: true,
userMessage: command,
userMessage: text,
animate: true,
},
];
Expand Down