Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

fix(dictionary): normalize untrimmed agent names in agentNameDictionaryChanges (#1442)

Henry Su0e4f1a0d0bea
diff --git a/src/helpers/agentNameDictionary.js b/src/helpers/agentNameDictionary.js
index 65911f979..f4e93a67e 100644
--- a/src/helpers/agentNameDictionary.js
+++ b/src/helpers/agentNameDictionary.js
@@ -13,10 +13,12 @@
*/
export function agentNameDictionaryChanges(dictionary, newName, oldName) {
const words = Array.isArray(dictionary) ? dictionary : [];
- const trimmed = newName.trim();
+ const trimmedNew = typeof newName === "string" ? newName.trim() : "";
+ const trimmedOld = typeof oldName === "string" ? oldName.trim() : "";
return {
- add: trimmed && !words.includes(trimmed) ? [trimmed] : [],
- remove: oldName && oldName !== newName && words.includes(oldName) ? [oldName] : [],
+ add: trimmedNew && !words.includes(trimmedNew) ? [trimmedNew] : [],
+ remove:
+ trimmedOld && trimmedOld !== trimmedNew && words.includes(trimmedOld) ? [trimmedOld] : [],
};
}
diff --git a/test/helpers/agentNameDictionary.test.js b/test/helpers/agentNameDictionary.test.js
index ef12b9cbd..6cfa9357d 100644
--- a/test/helpers/agentNameDictionary.test.js
+++ b/test/helpers/agentNameDictionary.test.js
@@ -54,3 +54,22 @@ test("never names a word outside the agent name itself", async () => {
const { add, remove } = agentNameDictionaryChanges(dictionary, "Jarvis", "OpenWhispr");
assert.deepEqual([...add, ...remove].sort(), ["Jarvis", "OpenWhispr"]);
});
+
+test("does not remove agent name when only surrounding whitespace changes", async () => {
+ const { agentNameDictionaryChanges } = await load();
+ assert.deepEqual(agentNameDictionaryChanges(["OpenWhispr"], " OpenWhispr ", "OpenWhispr"), {
+ add: [],
+ remove: [],
+ });
+});
+
+test("removes previous agent name when oldName contains surrounding whitespace", async () => {
+ const { agentNameDictionaryChanges } = await load();
+ assert.deepEqual(
+ agentNameDictionaryChanges(["OpenWhispr", "Alice"], "Jarvis", " OpenWhispr "),
+ {
+ add: ["Jarvis"],
+ remove: ["OpenWhispr"],
+ }
+ );
+});