Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.
JavaScript aianthropiccross-platformgeminigroqlinuxmacosnvidiaopen-sourceopenaiparakeetspeech-to-texttranscribewhisperwindows
fix(dictionary): treat agent names as present ignoring case (#1639)
Henry Su23fd77d51a2e
diff --git a/src/components/DictionaryView.tsx b/src/components/DictionaryView.tsxindex c54a3d396..abd54b8a5 100644--- a/src/components/DictionaryView.tsx+++ b/src/components/DictionaryView.tsx@@ -37,10 +37,12 @@ export default function DictionaryView() {const pendingImportCount = useMemo(() => parseDictionaryImportText(bulkText).length, [bulkText]);- const userWords = useMemo(- () => customDictionary.filter((w) => w !== agentName),- [customDictionary, agentName]- );+ // Same membership rule as agentNameDictionaryChanges: a stored spelling that+ // differs only by case is still the agent name's entry, so keep it hidden.+ const userWords = useMemo(() => {+ const agentWord = agentName.trim().toLowerCase();+ return customDictionary.filter((w) => w.trim().toLowerCase() !== agentWord);+ }, [customDictionary, agentName]);const searchQuery = newWord.trim().toLowerCase();const visibleWords = useMemo(diff --git a/src/helpers/agentNameDictionary.js b/src/helpers/agentNameDictionary.jsindex f4e93a67e..c66197779 100644--- a/src/helpers/agentNameDictionary.js+++ b/src/helpers/agentNameDictionary.js@@ -1,3 +1,8 @@+function findStoredWord(words, word) {+ const needle = word.toLowerCase();+ return words.find((w) => typeof w === "string" && w.trim().toLowerCase() === needle);+}+/*** Work out which dictionary changes an agent name requires: drop a* renamed-away name, add the current one.@@ -15,10 +20,12 @@ export function agentNameDictionaryChanges(dictionary, newName, oldName) {const words = Array.isArray(dictionary) ? dictionary : [];const trimmedNew = typeof newName === "string" ? newName.trim() : "";const trimmedOld = typeof oldName === "string" ? oldName.trim() : "";+ const storedNew = trimmedNew ? findStoredWord(words, trimmedNew) : undefined;+ const storedOld = trimmedOld ? findStoredWord(words, trimmedOld) : undefined;return {- add: trimmedNew && !words.includes(trimmedNew) ? [trimmedNew] : [],+ add: trimmedNew && !storedNew ? [trimmedNew] : [],remove:- trimmedOld && trimmedOld !== trimmedNew && words.includes(trimmedOld) ? [trimmedOld] : [],+ storedOld && storedOld.trim().toLowerCase() !== trimmedNew.toLowerCase() ? [storedOld] : [],};}diff --git a/test/helpers/agentNameDictionary.test.js b/test/helpers/agentNameDictionary.test.jsindex 6cfa9357d..b8a78ae6c 100644--- a/test/helpers/agentNameDictionary.test.js+++ b/test/helpers/agentNameDictionary.test.js@@ -55,6 +55,46 @@ test("never names a word outside the agent name itself", async () => {assert.deepEqual([...add, ...remove].sort(), ["Jarvis", "OpenWhispr"]);});+test("does not add a case-variant of an agent name already in the dictionary", async () => {+ const { agentNameDictionaryChanges } = await load();+ assert.deepEqual(agentNameDictionaryChanges(["openwhispr", "Alice"], "OpenWhispr"), {+ add: [],+ remove: [],+ });+});++test("removes the stored spelling when renaming away from a case-variant", async () => {+ const { agentNameDictionaryChanges } = await load();+ assert.deepEqual(agentNameDictionaryChanges(["openwhispr", "Alice"], "Jarvis", "OpenWhispr"), {+ add: ["Jarvis"],+ remove: ["openwhispr"],+ });+});++test("does not recase an existing agent name when only capitalization changes", async () => {+ const { agentNameDictionaryChanges } = await load();+ assert.deepEqual(agentNameDictionaryChanges(["OpenWhispr"], "openwhispr", "OpenWhispr"), {+ add: [],+ remove: [],+ });+});++test("does not remove a padded stored agent name when the name is unchanged", async () => {+ const { agentNameDictionaryChanges } = await load();+ assert.deepEqual(agentNameDictionaryChanges([" OpenWhispr "], "OpenWhispr", "OpenWhispr"), {+ add: [],+ remove: [],+ });+});++test("removes the padded stored spelling when renaming away", async () => {+ const { agentNameDictionaryChanges } = await load();+ assert.deepEqual(agentNameDictionaryChanges([" OpenWhispr ", "Alice"], "Jarvis", "OpenWhispr"), {+ add: ["Jarvis"],+ remove: [" OpenWhispr "],+ });+});+test("does not remove agent name when only surrounding whitespace changes", async () => {const { agentNameDictionaryChanges } = await load();assert.deepEqual(agentNameDictionaryChanges(["OpenWhispr"], " OpenWhispr ", "OpenWhispr"), {