From 22ab445dea92ca507956cfd62851474bb3a43b74 Mon Sep 17 00:00:00 2001 From: Jordan Wages Date: Fri, 27 Jun 2025 02:12:34 -0500 Subject: [PATCH] Add View Reasoning menu and fix button --- background.js | 29 ++++++++++++++++++++++++++--- resources/reasonButton.js | 2 +- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/background.js b/background.js index 17154b0..5b536a5 100644 --- a/background.js +++ b/background.js @@ -228,12 +228,17 @@ async function clearCacheForMessages(idsInput) { browser.messageDisplayAction.setLabel({ label: "Classify" }); } } - if (browser.messageDisplayScripts?.registerScripts) { + if (browser.messageDisplayScripts) { try { - await browser.messageDisplayScripts.registerScripts([ + const scripts = [ { js: [browser.runtime.getURL("resources/clearCacheButton.js")] }, { js: [browser.runtime.getURL("resources/reasonButton.js")] } - ]); + ]; + if (browser.messageDisplayScripts.registerScripts) { + await browser.messageDisplayScripts.registerScripts(scripts); + } else if (browser.messageDisplayScripts.register) { + await browser.messageDisplayScripts.register(scripts); + } } catch (e) { logger.aiLog("failed to register message display script", { level: 'warn' }, e); } @@ -259,6 +264,18 @@ async function clearCacheForMessages(idsInput) { title: "Clear AI Cache", contexts: ["message_display_action"], }); + browser.menus.create({ + id: "view-ai-reason-list", + title: "View Reasoning", + contexts: ["message_list"], + icons: { "16": "resources/img/brain.png" } + }); + browser.menus.create({ + id: "view-ai-reason-display", + title: "View Reasoning", + contexts: ["message_display_action"], + icons: { "16": "resources/img/brain.png" } + }); if (browser.messageDisplayAction) { browser.messageDisplayAction.onClicked.addListener(async (tab) => { @@ -281,6 +298,12 @@ async function clearCacheForMessages(idsInput) { const ids = info.selectedMessages?.messages?.map(m => m.id) || (info.messageId ? [info.messageId] : []); await clearCacheForMessages(ids); + } else if (info.menuItemId === "view-ai-reason-list" || info.menuItemId === "view-ai-reason-display") { + const id = info.messageId || info.selectedMessages?.messages?.[0]?.id; + if (id) { + const url = browser.runtime.getURL(`reasoning.html?mid=${id}`); + browser.tabs.create({ url }); + } } }); diff --git a/resources/reasonButton.js b/resources/reasonButton.js index 0206ab9..d0b38e7 100644 --- a/resources/reasonButton.js +++ b/resources/reasonButton.js @@ -7,7 +7,7 @@ document.createXULElement('toolbarbutton') : document.createElement('button'); button.id = 'sortana-reason-button'; - button.setAttribute('label', 'Show Reasoning'); + button.setAttribute('label', 'View Reasoning'); button.className = 'toolbarbutton-1'; const icon = browser.runtime.getURL('resources/img/brain.png'); if (button.setAttribute) {