Remove experiment APIs and content script
This commit is contained in:
parent
6dee051ca1
commit
f4103c4100
8 changed files with 3 additions and 301 deletions
|
@ -25,17 +25,8 @@ let AiClassifier;
|
|||
try {
|
||||
const store = await browser.storage.local.get(["endpoint", "templateName", "customTemplate", "customSystemPrompt", "aiParams", "debugLogging"]);
|
||||
logger.setDebug(store.debugLogging);
|
||||
await browser.aiFilter.initConfig(store);
|
||||
AiClassifier.setConfig(store);
|
||||
logger.aiLog("configuration loaded", {debug: true}, store);
|
||||
try {
|
||||
await browser.DomContentScript.registerWindow(
|
||||
"chrome://messenger/content/FilterEditor.xhtml",
|
||||
"resource://aifilter/content/filterEditor.js"
|
||||
);
|
||||
logger.aiLog("registered FilterEditor content script", {debug: true});
|
||||
} catch (e) {
|
||||
logger.aiLog("failed to register content script", {level: 'error'}, e);
|
||||
}
|
||||
} catch (err) {
|
||||
logger.aiLog("failed to load config", {level: 'error'}, err);
|
||||
}
|
||||
|
@ -51,8 +42,8 @@ browser.runtime.onMessage.addListener(async (msg) => {
|
|||
logger.aiLog("aiFilter:test – criterion", {debug: true}, criterion);
|
||||
|
||||
try {
|
||||
logger.aiLog("Calling browser.aiFilter.classify()", {debug: true});
|
||||
const result = await browser.aiFilter.classify(text, criterion);
|
||||
logger.aiLog("Calling AiClassifier.classifyText()", {debug: true});
|
||||
const result = await AiClassifier.classifyText(text, criterion);
|
||||
logger.aiLog("classify() returned", {debug: true}, result);
|
||||
return { match: result };
|
||||
}
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
(function() {
|
||||
function patch(container) {
|
||||
if (!container || container.getAttribute("ai-filter-patched") === "true") {
|
||||
return;
|
||||
}
|
||||
while (container.firstChild) {
|
||||
container.firstChild.remove();
|
||||
}
|
||||
let frag = window.MozXULElement.parseXULToFragment(
|
||||
`<html:input class="search-value-textbox flexinput ai-filter-textbox" inherits="disabled"
|
||||
onchange="this.parentNode.setAttribute('value', this.value); this.parentNode.value=this.value;">
|
||||
</html:input>`
|
||||
);
|
||||
container.appendChild(frag);
|
||||
if (container.hasAttribute("value")) {
|
||||
container.firstChild.value = container.getAttribute("value");
|
||||
}
|
||||
container.classList.add("flexelementcontainer");
|
||||
container.setAttribute("ai-filter-patched", "true");
|
||||
}
|
||||
|
||||
function check(node) {
|
||||
if (!(node instanceof Element)) {
|
||||
return;
|
||||
}
|
||||
if (
|
||||
node.classList.contains("search-value-custom") &&
|
||||
node.getAttribute("searchAttribute") === "aifilter#classification"
|
||||
) {
|
||||
patch(node);
|
||||
}
|
||||
node
|
||||
.querySelectorAll('.search-value-custom[searchAttribute="aifilter#classification"]')
|
||||
.forEach(patch);
|
||||
}
|
||||
|
||||
const observer = new MutationObserver(mutations => {
|
||||
for (let mutation of mutations) {
|
||||
if (mutation.type === "childList") {
|
||||
mutation.addedNodes.forEach(check);
|
||||
} else if (mutation.type === "attributes") {
|
||||
check(mutation.target);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
const termList = document.getElementById("searchTermList") || document;
|
||||
observer.observe(termList, { childList: true, attributes: true, subtree: true });
|
||||
check(termList);
|
||||
})();
|
|
@ -1,80 +0,0 @@
|
|||
|
||||
|
||||
var { AppConstants } = ChromeUtils.importESModule("resource://gre/modules/AppConstants.sys.mjs");
|
||||
var DomContent_ESM = parseInt(AppConstants.MOZ_APP_VERSION, 10) >= 128;
|
||||
|
||||
var { ExtensionCommon } = ChromeUtils.importESModule(
|
||||
"resource://gre/modules/ExtensionCommon.sys.mjs"
|
||||
);
|
||||
|
||||
var { ExtensionUtils } = DomContent_ESM
|
||||
? ChromeUtils.importESModule("resource://gre/modules/ExtensionUtils.sys.mjs")
|
||||
: ChromeUtils.import("resource://gre/modules/ExtensionUtils.jsm");
|
||||
|
||||
var { ExtensionError } = ExtensionUtils;
|
||||
|
||||
var registeredWindows = new Map();
|
||||
|
||||
var DomContentScript = class extends ExtensionCommon.ExtensionAPI {
|
||||
constructor(extension) {
|
||||
super(extension);
|
||||
|
||||
this._windowListener = {
|
||||
// nsIWindowMediatorListener functions
|
||||
onOpenWindow(appWindow) {
|
||||
// A new window has opened.
|
||||
let domWindow = appWindow.docShell.domWindow;
|
||||
|
||||
/**
|
||||
* Set up listeners to run the callbacks on the given window.
|
||||
*
|
||||
* @param aWindow {nsIDOMWindow} The window to set up.
|
||||
* @param aID {String} Optional. ID of the new caller that has registered right now.
|
||||
*/
|
||||
domWindow.addEventListener(
|
||||
"DOMContentLoaded",
|
||||
function() {
|
||||
// do stuff
|
||||
let windowChromeURL = domWindow.document.location.href;
|
||||
if (registeredWindows.has(windowChromeURL)) {
|
||||
let jsPath = registeredWindows.get(windowChromeURL);
|
||||
Services.scriptloader.loadSubScript(jsPath, domWindow, "UTF-8");
|
||||
}
|
||||
},
|
||||
{ once: true }
|
||||
);
|
||||
},
|
||||
|
||||
onCloseWindow(appWindow) {
|
||||
// One of the windows has closed.
|
||||
let domWindow = appWindow.docShell.domWindow; // we don't need to do anything (script only loads once)
|
||||
},
|
||||
};
|
||||
|
||||
Services.wm.addListener(this._windowListener);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
onShutdown(isAppShutdown) {
|
||||
if (isAppShutdown) {
|
||||
return; // the application gets unloaded anyway
|
||||
}
|
||||
Services.wm.removeListener(this._windowListener);
|
||||
}
|
||||
|
||||
getAPI(context) {
|
||||
/** API IMPLEMENTATION **/
|
||||
return {
|
||||
DomContentScript: {
|
||||
// only returns something, if a user pref value is set
|
||||
registerWindow: async function (windowUrl,jsPath) {
|
||||
registeredWindows.set(windowUrl,jsPath);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
[
|
||||
{
|
||||
"namespace": "DomContentScript",
|
||||
"functions": [
|
||||
{
|
||||
"name": "registerWindow",
|
||||
"type": "function",
|
||||
"async": true,
|
||||
"description": "Register a script for onDOMContentLoaded",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "windowUrl",
|
||||
"type": "string",
|
||||
"description": "chrome URL of the window "
|
||||
},
|
||||
{
|
||||
"name": "jsPath",
|
||||
"type": "string",
|
||||
"description": "chrome URL of the script"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -1,89 +0,0 @@
|
|||
var { ExtensionCommon } = ChromeUtils.importESModule("resource://gre/modules/ExtensionCommon.sys.mjs");
|
||||
var { Services } = globalThis || ChromeUtils.importESModule("resource://gre/modules/Services.sys.mjs");
|
||||
var { MailServices } = ChromeUtils.importESModule("resource:///modules/MailServices.sys.mjs");
|
||||
var AiClassifier;
|
||||
|
||||
var aiLog = (...args) => console.log("[ai-filter][api]", ...args);
|
||||
var setDebug = () => {};
|
||||
|
||||
console.log("[ai-filter][api] Experiment API module loading");
|
||||
|
||||
var resProto = Cc["@mozilla.org/network/protocol;1?name=resource"]
|
||||
.getService(Ci.nsISubstitutingProtocolHandler);
|
||||
|
||||
function registerResourceUrl(extension, namespace) {
|
||||
aiLog(`[api] registerResourceUrl called for namespace="${namespace}"`, {debug: true});
|
||||
if (resProto.hasSubstitution(namespace)) {
|
||||
aiLog(`[api] namespace="${namespace}" already registered, skipping`, {debug: true});
|
||||
return;
|
||||
}
|
||||
let uri = Services.io.newURI(".", null, extension.rootURI);
|
||||
aiLog(`[api] setting substitution for "${namespace}" → ${uri.spec}`, {debug: true});
|
||||
resProto.setSubstitutionWithFlags(namespace, uri, resProto.ALLOW_CONTENT_ACCESS);
|
||||
}
|
||||
|
||||
var AIFilterMod;
|
||||
|
||||
var aiFilter = class extends ExtensionCommon.ExtensionAPI {
|
||||
async onStartup() {
|
||||
let { extension } = this;
|
||||
|
||||
registerResourceUrl(extension, "aifilter");
|
||||
|
||||
// Import logger using the resource URL we just registered
|
||||
let loggerMod = ChromeUtils.import("resource://aifilter/modules/logger.jsm");
|
||||
aiLog = loggerMod.aiLog;
|
||||
setDebug = loggerMod.setDebug;
|
||||
|
||||
// Now that the resource URL is registered, import the classifier
|
||||
AiClassifier = ChromeUtils.importESModule("resource://aifilter/modules/AiClassifier.js");
|
||||
aiLog("[api] onStartup()", {debug: true});
|
||||
|
||||
|
||||
try {
|
||||
aiLog("[api] importing ExpressionSearchFilter.jsm", {debug: true});
|
||||
AIFilterMod = ChromeUtils.import("resource://aifilter/modules/ExpressionSearchFilter.jsm");
|
||||
aiLog("[api] ExpressionSearchFilter.jsm import succeeded", {debug: true});
|
||||
}
|
||||
catch (err) {
|
||||
aiLog("[api] failed to import ExpressionSearchFilter.jsm", {level: 'error'}, err);
|
||||
}
|
||||
}
|
||||
|
||||
onShutdown(isAppShutdown) {
|
||||
aiLog("[api] onShutdown()", {debug: true}, isAppShutdown);
|
||||
if (!isAppShutdown && resProto.hasSubstitution("aifilter")) {
|
||||
aiLog("[api] removing substitution for namespace='aifilter'", {debug: true});
|
||||
resProto.setSubstitution("aifilter", null);
|
||||
}
|
||||
}
|
||||
|
||||
getAPI(context) {
|
||||
aiLog("[api] getAPI()", {debug: true});
|
||||
return {
|
||||
aiFilter: {
|
||||
initConfig: async (config) => {
|
||||
try {
|
||||
AiClassifier.setConfig(config);
|
||||
if (typeof config.debugLogging === "boolean") {
|
||||
setDebug(config.debugLogging);
|
||||
}
|
||||
aiLog("[api] configuration applied", {debug: true}, config);
|
||||
} catch (err) {
|
||||
aiLog("[api] failed to apply config", {level: 'error'}, err);
|
||||
}
|
||||
},
|
||||
classify: async (text, criterion) => {
|
||||
aiLog("[api] classify() called", {debug: true}, text, criterion);
|
||||
try {
|
||||
return await AiClassifier.classifyText(text, criterion);
|
||||
}
|
||||
catch (err) {
|
||||
aiLog("[api] error in classify()", {level: 'error'}, err);
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
|
@ -1,25 +0,0 @@
|
|||
[
|
||||
{
|
||||
"namespace": "aiFilter",
|
||||
"functions": [
|
||||
{
|
||||
"name": "initConfig",
|
||||
"type": "function",
|
||||
"async": true,
|
||||
"parameters": [
|
||||
{ "name": "config", "type": "any" }
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "classify",
|
||||
"type": "function",
|
||||
"parameters": [
|
||||
{
|
||||
"name": "msg",
|
||||
"type": "any"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
|
@ -19,25 +19,6 @@
|
|||
"128": "resources/img/logo128.png"
|
||||
},
|
||||
"background": { "scripts": [ "background.js" ] },
|
||||
"experiment_apis": {
|
||||
"aiFilter": {
|
||||
"schema": "experiment/schema.json",
|
||||
"parent": {
|
||||
"scopes": [ "addon_parent" ],
|
||||
"paths": [ [ "aiFilter" ] ],
|
||||
"script": "experiment/api.js",
|
||||
"events": [ "startup" ]
|
||||
}
|
||||
},
|
||||
"DomContentScript": {
|
||||
"schema": "experiment/DomContentScript/schema.json",
|
||||
"parent": {
|
||||
"scopes": [ "addon_parent" ],
|
||||
"paths": [ [ "DomContentScript" ] ],
|
||||
"script": "experiment/DomContentScript/implementation.js"
|
||||
}
|
||||
}
|
||||
},
|
||||
"options_ui": {
|
||||
"page": "options/options.html",
|
||||
"open_in_tab": true
|
||||
|
|
|
@ -88,7 +88,6 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
const debugLogging = debugToggle.checked;
|
||||
await browser.storage.local.set({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt, aiParams: aiParamsSave, debugLogging });
|
||||
try {
|
||||
await browser.aiFilter.initConfig({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt, aiParams: aiParamsSave, debugLogging });
|
||||
AiClassifier.setConfig({ endpoint, templateName, customTemplate: customTemplateText, customSystemPrompt, aiParams: aiParamsSave, debugLogging });
|
||||
logger.setDebug(debugLogging);
|
||||
} catch (e) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue