diff --git a/package.json b/package.json index bc29c86..06feb95 100644 --- a/package.json +++ b/package.json @@ -77,24 +77,8 @@ "activeTab", "scripting", "declarativeNetRequest", - "declarativeNetRequestFeedback" - ], - "commands": { - "open-ai-sidebar": { - "suggested_key": { - "default": "Ctrl+Shift+0", - "mac": "Command+Shift+0" - }, - "description": "Open AI Sidebar for Page Assist" - }, - "_execute_action": { - "suggested_key": { - "windows": "Ctrl+Shift+0", - "mac": "Command+Shift+0", - "chromeos": "Ctrl+Shift+0", - "linux": "Ctrl+Shift+0" - } - } - } + "declarativeNetRequestFeedback", + "action" + ] } } diff --git a/src/background.ts b/src/background.ts index c781a4c..e67032f 100644 --- a/src/background.ts +++ b/src/background.ts @@ -1,6 +1,5 @@ export {} - chrome.runtime.onMessage.addListener(async (message) => { if (message.type === "sidepanel") { chrome.tabs.query({ active: true, currentWindow: true }, async (tabs) => { @@ -11,3 +10,12 @@ chrome.runtime.onMessage.addListener(async (message) => { }) } }) + +chrome.action.onClicked.addListener((tab) => { + chrome.tabs.create({url: chrome.runtime.getURL("options.html")}); +}); + +// listen to commadns +chrome.commands.onCommand.addListener((command) => { + console.log('Command', command) +}) \ No newline at end of file diff --git a/src/chain/chat-with-website.ts b/src/chain/chat-with-website.ts index 9a2793a..09e638d 100644 --- a/src/chain/chat-with-website.ts +++ b/src/chain/chat-with-website.ts @@ -14,12 +14,13 @@ import { RunnableMap, RunnableSequence, } from "langchain/schema/runnable"; +import type { ChatHistory } from "~store"; type RetrievalChainInput = { chat_history: string; question: string; }; -export function groupMessagesByConversation(messages: any[]) { +export function groupMessagesByConversation(messages: ChatHistory) { if (messages.length % 2 !== 0) { messages.pop(); } diff --git a/src/components/Common/SaveButton.tsx b/src/components/Common/SaveButton.tsx new file mode 100644 index 0000000..cf6e950 --- /dev/null +++ b/src/components/Common/SaveButton.tsx @@ -0,0 +1,33 @@ +import { useState } from "react" + +type Props = { + onClick: () => void + disabled?: boolean + className?: string + text?: string + textOnSave?: string +} + +export const SaveButton = ({ + onClick, + disabled, + className, + text = "Save", + textOnSave = "Saved" +}: Props) => { + const [clickedSave, setClickedSave] = useState(false) + return ( + + ) +} diff --git a/src/components/Sidepanel/Settings/body.tsx b/src/components/Sidepanel/Settings/body.tsx index a447916..285df55 100644 --- a/src/components/Sidepanel/Settings/body.tsx +++ b/src/components/Sidepanel/Settings/body.tsx @@ -11,6 +11,7 @@ import { import { Skeleton, Radio } from "antd" import { useDarkMode } from "~hooks/useDarkmode" +import { SaveButton } from "~components/Common/SaveButton" export const SettingsBody = () => { const [ollamaURL, setOllamaURL] = React.useState("") @@ -78,13 +79,11 @@ export const SettingsBody = () => { placeholder="Enter Ollama URL here" />
- + />
@@ -109,13 +108,11 @@ export const SettingsBody = () => { onChange={(e) => setSystemPrompt(e.target.value)} />
- + />
)} @@ -144,13 +141,11 @@ export const SettingsBody = () => {
- + />
)} diff --git a/src/hooks/useMessage.tsx b/src/hooks/useMessage.tsx index 6279cf2..ff30084 100644 --- a/src/hooks/useMessage.tsx +++ b/src/hooks/useMessage.tsx @@ -17,7 +17,7 @@ import { getHtmlOfCurrentTab } from "~libs/get-html" import { PageAssistHtmlLoader } from "~loader/html" import { RecursiveCharacterTextSplitter } from "langchain/text_splitter" import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama" -import { createChatWithWebsiteChain } from "~chain/chat-with-website" +import { createChatWithWebsiteChain, groupMessagesByConversation } from "~chain/chat-with-website" import { MemoryVectorStore } from "langchain/vectorstores/memory" export type BotResponse = { @@ -205,7 +205,8 @@ export const useMessage = () => { try { const chunks = await chain.stream({ - question: sanitizedQuestion + question: sanitizedQuestion, + chat_history: groupMessagesByConversation(history), }) let count = 0 for await (const chunk of chunks) { diff --git a/src/option.tsx b/src/options.tsx similarity index 100% rename from src/option.tsx rename to src/options.tsx diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 0a06549..5a55597 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -2,8 +2,13 @@ import { Route, Routes } from "react-router-dom" import { SidepanelChat } from "./sidepanel-chat" import { useDarkMode } from "~hooks/useDarkmode" import { SidepanelSettings } from "./sidepanel-settings" +import { OptionIndex } from "./option-index" -export const Routing = () => +export const OptionRouting = () => ( + + } /> + +) export const SidepanelRouting = () => { const { mode } = useDarkMode() diff --git a/src/routes/option-index.tsx b/src/routes/option-index.tsx new file mode 100644 index 0000000..3cb3271 --- /dev/null +++ b/src/routes/option-index.tsx @@ -0,0 +1,10 @@ +import { SettingsBody } from "~components/Sidepanel/Settings/body" +import { SidepanelSettingsHeader } from "~components/Sidepanel/Settings/header" + +export const OptionIndex = () => { + return ( +
+ hey +
+ ) +}