From d8ace5795023352b00798f2829c69a42a4f9c1e9 Mon Sep 17 00:00:00 2001 From: Andrew Nguonly Date: Sat, 17 Aug 2024 11:54:11 -0700 Subject: [PATCH] Pull request for app version `1.0.16` (#187) --- __tests__/contentConfig.test.ts | 12 ++++++++++++ manifest.json | 2 +- package.json | 2 +- src/components/ChatBar.tsx | 27 +++++++++++++++++++++++++-- src/contentConfig.ts | 4 +++- 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/__tests__/contentConfig.test.ts b/__tests__/contentConfig.test.ts index 071cce3..0f8a2c4 100644 --- a/__tests__/contentConfig.test.ts +++ b/__tests__/contentConfig.test.ts @@ -61,4 +61,16 @@ describe("getContentConfig", () => { const config = getContentConfig(url, contentConfig); expect(config?.chunkSize).toEqual(503); }); + + test("should match subdomain", () => { + const url = new URL("https://sub.domain.com"); + const config = getContentConfig(url, contentConfig); + expect(config?.chunkSize).toEqual(501); + }); + + test("should match sub subdomain", () => { + const url = new URL("https://sub.sub.domain.com"); + const config = getContentConfig(url, contentConfig); + expect(config?.chunkSize).toEqual(501); + }); }); diff --git a/manifest.json b/manifest.json index 1646a16..f302c94 100644 --- a/manifest.json +++ b/manifest.json @@ -1,5 +1,5 @@ { - "version": "1.0.15", + "version": "1.0.16", "manifest_version": 3, "name": "Lumos", "description": "An LLM co-pilot for browsing the web, powered by local LLMs. Your prompts never leave the browser.", diff --git a/package.json b/package.json index 6781467..3342c9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "lumos", - "version": "1.0.15", + "version": "1.0.16", "private": true, "dependencies": { "@chatscope/chat-ui-kit-react": "^1.10.1", diff --git a/src/components/ChatBar.tsx b/src/components/ChatBar.tsx index 5f6a7b9..9f8ee98 100644 --- a/src/components/ChatBar.tsx +++ b/src/components/ChatBar.tsx @@ -1,4 +1,10 @@ -import { ChangeEvent, useEffect, useRef, useState } from "react"; +import { + ChangeEvent, + ClipboardEvent, + useEffect, + useRef, + useState, +} from "react"; import { Avatar, @@ -440,7 +446,9 @@ const ChatBar: React.FC = () => { case "c": // copy last message if (messages.length === 0) return; - navigator.clipboard.writeText(messages[messages.length - 1].message); + navigator.clipboard.writeText( + messages[messages.length - 1].message.trim(), + ); setShowSnackbar(true); setSnackbarMessage("Copied!"); break; @@ -474,6 +482,20 @@ const ChatBar: React.FC = () => { } }; + /** + * This function is needed to prevent HTML elements (e.g. background color) + * from being copied to the clipboard. Only plain text should be copied to + * the clipboard. + */ + const handleMessageOnCopy = (event: ClipboardEvent) => { + event.preventDefault(); + + const selectedText = window.getSelection()?.toString() || ""; + if (selectedText !== "") { + navigator.clipboard.writeText(selectedText); + } + }; + const appendNonUserMessage = ( currentMessages: LumosMessage[], sender: string, @@ -685,6 +707,7 @@ const ChatBar: React.FC = () => { }} type="custom" style={messageStyle} + onCopy={handleMessageOnCopy} > { - const searchPath = `${url.hostname}${url.pathname}`; + const domainParts = url.hostname.split("."); + const topLevelDomain = `${domainParts[domainParts.length - 2]}.${domainParts[domainParts.length - 1]}`; + const searchPath = `${topLevelDomain}${url.pathname}`; // Order keys (paths) of contentConfig in reverse order and check if any // key is a substring of searchPath. This will find the longest matching