feat: copilot context menu for tool

This commit is contained in:
n4ze3m
2024-08-03 23:00:57 +05:30
parent 9c7ebc8778
commit ac9c9ca887
14 changed files with 696 additions and 132 deletions

View File

@@ -3,8 +3,11 @@ import {
formatToMessage,
getRecentChatFromCopilot
} from "@/db"
import useBackgroundMessage from "@/hooks/useBackgroundMessage"
import { copilotResumeLastChat } from "@/services/app"
import { notification } from "antd"
import React from "react"
import { useTranslation } from "react-i18next"
import { SidePanelBody } from "~/components/Sidepanel/Chat/body"
import { SidepanelForm } from "~/components/Sidepanel/Chat/form"
import { SidepanelHeader } from "~/components/Sidepanel/Chat/header"
@@ -13,17 +16,27 @@ import { useMessage } from "~/hooks/useMessage"
const SidepanelChat = () => {
const drop = React.useRef<HTMLDivElement>(null)
const [dropedFile, setDropedFile] = React.useState<File | undefined>()
const { t } = useTranslation(["playground"])
const [dropState, setDropState] = React.useState<
"idle" | "dragging" | "error"
>("idle")
const { chatMode, messages, setHistory, setHistoryId, setMessages } =
useMessage()
const {
chatMode,
streaming,
onSubmit,
messages,
setHistory,
setHistoryId,
setMessages,
selectedModel
} = useMessage()
const bgMsg = useBackgroundMessage()
const setRecentMessagesOnLoad = async () => {
const isEnabled = await copilotResumeLastChat();
const isEnabled = await copilotResumeLastChat()
if (!isEnabled) {
return;
return
}
if (messages.length === 0) {
const recentChat = await getRecentChatFromCopilot()
@@ -92,11 +105,26 @@ const SidepanelChat = () => {
}
}, [])
React.useEffect(() => {
setRecentMessagesOnLoad()
}, [])
React.useEffect(() => {
if (bgMsg && !streaming) {
if (selectedModel) {
onSubmit({
message: bgMsg.text,
messageType: bgMsg.type,
image: ""
})
} else {
notification.error({
message: t("formError.noModel")
})
}
}
}, [bgMsg])
return (
<div
ref={drop}