Compare commits
11 commits
codex/add-
...
main
Author | SHA1 | Date | |
---|---|---|---|
c622c07c66 | |||
33003365fb |
|||
9cad2674e3 | |||
d3ee2f128f |
|||
bcac4ad017 | |||
d1ddfc4ad8 |
|||
841a697c69 | |||
45125f634d |
|||
55ccf083c8 | |||
d2de1818ca | |||
587f070886 |
7 changed files with 2351 additions and 16 deletions
|
@ -16,7 +16,7 @@ message meets a specified criterion.
|
||||||
- **Advanced parameters** – tune generation settings like temperature, top‑p and more from the options page.
|
- **Advanced parameters** – tune generation settings like temperature, top‑p and more from the options page.
|
||||||
- **Markdown conversion** – optionally convert HTML bodies to Markdown before sending them to the AI service.
|
- **Markdown conversion** – optionally convert HTML bodies to Markdown before sending them to the AI service.
|
||||||
- **Debug logging** – optional colorized logs help troubleshoot interactions with the AI service.
|
- **Debug logging** – optional colorized logs help troubleshoot interactions with the AI service.
|
||||||
- **Debug tab** – view the last request payload sent to the AI service.
|
- **Debug tab** – view the last request payload and a diff between the unaltered message text and the final prompt.
|
||||||
- **Light/Dark themes** – automatically match Thunderbird's appearance with optional manual override.
|
- **Light/Dark themes** – automatically match Thunderbird's appearance with optional manual override.
|
||||||
- **Automatic rules** – create rules that tag, move, copy, forward, reply, delete, archive, mark read/unread or flag/unflag messages based on AI classification. Rules can optionally apply only to unread messages and can ignore messages outside a chosen age range.
|
- **Automatic rules** – create rules that tag, move, copy, forward, reply, delete, archive, mark read/unread or flag/unflag messages based on AI classification. Rules can optionally apply only to unread messages and can ignore messages outside a chosen age range.
|
||||||
- **Rule ordering** – drag rules to prioritize them and optionally stop processing after a match.
|
- **Rule ordering** – drag rules to prioritize them and optionally stop processing after a match.
|
||||||
|
@ -141,6 +141,8 @@ uses the following third party libraries:
|
||||||
- MIT License
|
- MIT License
|
||||||
- [turndown v7.2.0](https://github.com/mixmark-io/turndown/tree/v7.2.0)
|
- [turndown v7.2.0](https://github.com/mixmark-io/turndown/tree/v7.2.0)
|
||||||
- MIT License
|
- MIT License
|
||||||
|
- [diff](https://github.com/google/diff-match-patch/blob/62f2e689f498f9c92dbc588c58750addec9b1654/javascript/diff_match_patch_uncompressed.js)
|
||||||
|
- Apache-2.0 license
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
|
|
|
@ -108,6 +108,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "img", "img", "{F266602F-175
|
||||||
EndProject
|
EndProject
|
||||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "js", "js", "{21D2A42C-3F85-465C-9141-C106AFD92B68}"
|
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "js", "js", "{21D2A42C-3F85-465C-9141-C106AFD92B68}"
|
||||||
ProjectSection(SolutionItems) = preProject
|
ProjectSection(SolutionItems) = preProject
|
||||||
|
resources\js\diff_match_patch_uncompressed.js = resources\js\diff_match_patch_uncompressed.js
|
||||||
resources\js\turndown.js = resources\js\turndown.js
|
resources\js\turndown.js = resources\js\turndown.js
|
||||||
EndProjectSection
|
EndProjectSection
|
||||||
EndProject
|
EndProject
|
||||||
|
|
|
@ -33,6 +33,7 @@ let userTheme = 'auto';
|
||||||
let currentTheme = 'light';
|
let currentTheme = 'light';
|
||||||
let detectSystemTheme;
|
let detectSystemTheme;
|
||||||
let errorPending = false;
|
let errorPending = false;
|
||||||
|
let showDebugTab = false;
|
||||||
const ERROR_NOTIFICATION_ID = 'sortana-error';
|
const ERROR_NOTIFICATION_ID = 'sortana-error';
|
||||||
|
|
||||||
function normalizeRules(rules) {
|
function normalizeRules(rules) {
|
||||||
|
@ -209,17 +210,38 @@ function collectText(part, bodyParts, attachments) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function buildEmailText(full) {
|
function collectRawText(part, bodyParts, attachments) {
|
||||||
|
if (part.parts && part.parts.length) {
|
||||||
|
for (const p of part.parts) collectRawText(p, bodyParts, attachments);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const ct = (part.contentType || "text/plain").toLowerCase();
|
||||||
|
const cd = (part.headers?.["content-disposition"]?.[0] || "").toLowerCase();
|
||||||
|
const body = String(part.body || "");
|
||||||
|
if (cd.includes("attachment") || !ct.startsWith("text/")) {
|
||||||
|
const nameMatch = /filename\s*=\s*"?([^";]+)/i.exec(cd) || /name\s*=\s*"?([^";]+)/i.exec(part.headers?.["content-type"]?.[0] || "");
|
||||||
|
const name = nameMatch ? nameMatch[1] : "";
|
||||||
|
attachments.push(`${name} (${ct}, ${part.size || byteSize(body)} bytes)`);
|
||||||
|
} else if (ct.startsWith("text/html")) {
|
||||||
|
const doc = new DOMParser().parseFromString(body, 'text/html');
|
||||||
|
bodyParts.push(doc.body.textContent || "");
|
||||||
|
} else {
|
||||||
|
bodyParts.push(body);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function buildEmailText(full, applyTransforms = true) {
|
||||||
const bodyParts = [];
|
const bodyParts = [];
|
||||||
const attachments = [];
|
const attachments = [];
|
||||||
collectText(full, bodyParts, attachments);
|
const collect = applyTransforms ? collectText : collectRawText;
|
||||||
|
collect(full, bodyParts, attachments);
|
||||||
const headers = Object.entries(full.headers || {})
|
const headers = Object.entries(full.headers || {})
|
||||||
.map(([k, v]) => `${k}: ${v.join(' ')}`)
|
.map(([k, v]) => `${k}: ${v.join(' ')}`)
|
||||||
.join('\n');
|
.join('\n');
|
||||||
const attachInfo = `Attachments: ${attachments.length}` +
|
const attachInfo = `Attachments: ${attachments.length}` +
|
||||||
(attachments.length ? "\n" + attachments.map(a => ` - ${a}`).join('\n') : "");
|
(attachments.length ? "\n" + attachments.map(a => ` - ${a}`).join('\n') : "");
|
||||||
let combined = `${headers}\n${attachInfo}\n\n${bodyParts.join('\n')}`.trim();
|
let combined = `${headers}\n${attachInfo}\n\n${bodyParts.join('\n')}`.trim();
|
||||||
if (tokenReduction) {
|
if (applyTransforms && tokenReduction) {
|
||||||
const seen = new Set();
|
const seen = new Set();
|
||||||
combined = combined.split('\n').filter(l => {
|
combined = combined.split('\n').filter(l => {
|
||||||
if (seen.has(l)) return false;
|
if (seen.has(l)) return false;
|
||||||
|
@ -227,7 +249,7 @@ function buildEmailText(full) {
|
||||||
return true;
|
return true;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
}
|
}
|
||||||
return sanitizeString(combined);
|
return applyTransforms ? sanitizeString(combined) : combined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTimingStats(elapsed) {
|
function updateTimingStats(elapsed) {
|
||||||
|
@ -261,6 +283,7 @@ async function processMessage(id) {
|
||||||
updateActionIcon();
|
updateActionIcon();
|
||||||
try {
|
try {
|
||||||
const full = await messenger.messages.getFull(id);
|
const full = await messenger.messages.getFull(id);
|
||||||
|
const originalText = buildEmailText(full, false);
|
||||||
let text = buildEmailText(full);
|
let text = buildEmailText(full);
|
||||||
if (tokenReduction && maxTokens > 0) {
|
if (tokenReduction && maxTokens > 0) {
|
||||||
const limit = Math.floor(maxTokens * 0.9);
|
const limit = Math.floor(maxTokens * 0.9);
|
||||||
|
@ -268,6 +291,9 @@ async function processMessage(id) {
|
||||||
text = text.slice(0, limit);
|
text = text.slice(0, limit);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (showDebugTab) {
|
||||||
|
await storage.local.set({ lastFullText: originalText, lastPromptText: text });
|
||||||
|
}
|
||||||
let hdr;
|
let hdr;
|
||||||
let currentTags = [];
|
let currentTags = [];
|
||||||
let alreadyRead = false;
|
let alreadyRead = false;
|
||||||
|
@ -425,7 +451,7 @@ async function clearCacheForMessages(idsInput) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const store = await storage.local.get(["endpoint", "templateName", "customTemplate", "customSystemPrompt", "aiParams", "debugLogging", "htmlToMarkdown", "stripUrlParams", "altTextImages", "collapseWhitespace", "tokenReduction", "aiRules", "theme", "errorPending"]);
|
const store = await storage.local.get(["endpoint", "templateName", "customTemplate", "customSystemPrompt", "aiParams", "debugLogging", "htmlToMarkdown", "stripUrlParams", "altTextImages", "collapseWhitespace", "tokenReduction", "aiRules", "theme", "errorPending", "showDebugTab"]);
|
||||||
logger.setDebug(store.debugLogging);
|
logger.setDebug(store.debugLogging);
|
||||||
await AiClassifier.setConfig(store);
|
await AiClassifier.setConfig(store);
|
||||||
userTheme = store.theme || 'auto';
|
userTheme = store.theme || 'auto';
|
||||||
|
@ -440,6 +466,7 @@ async function clearCacheForMessages(idsInput) {
|
||||||
maxTokens = parseInt(store.aiParams.max_tokens) || maxTokens;
|
maxTokens = parseInt(store.aiParams.max_tokens) || maxTokens;
|
||||||
}
|
}
|
||||||
errorPending = store.errorPending === true;
|
errorPending = store.errorPending === true;
|
||||||
|
showDebugTab = store.showDebugTab === true;
|
||||||
const savedStats = await storage.local.get('classifyStats');
|
const savedStats = await storage.local.get('classifyStats');
|
||||||
if (savedStats.classifyStats && typeof savedStats.classifyStats === 'object') {
|
if (savedStats.classifyStats && typeof savedStats.classifyStats === 'object') {
|
||||||
Object.assign(timingStats, savedStats.classifyStats);
|
Object.assign(timingStats, savedStats.classifyStats);
|
||||||
|
@ -494,6 +521,9 @@ async function clearCacheForMessages(idsInput) {
|
||||||
tokenReduction = changes.tokenReduction.newValue === true;
|
tokenReduction = changes.tokenReduction.newValue === true;
|
||||||
logger.aiLog("tokenReduction updated from storage change", { debug: true }, tokenReduction);
|
logger.aiLog("tokenReduction updated from storage change", { debug: true }, tokenReduction);
|
||||||
}
|
}
|
||||||
|
if (changes.showDebugTab) {
|
||||||
|
showDebugTab = changes.showDebugTab.newValue === true;
|
||||||
|
}
|
||||||
if (changes.errorPending) {
|
if (changes.errorPending) {
|
||||||
errorPending = changes.errorPending.newValue === true;
|
errorPending = changes.errorPending.newValue === true;
|
||||||
updateActionIcon();
|
updateActionIcon();
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Sortana",
|
"name": "Sortana",
|
||||||
"version": "2.1.2",
|
"version": "2.2.0",
|
||||||
"default_locale": "en-US",
|
"default_locale": "en-US",
|
||||||
"applications": {
|
"applications": {
|
||||||
"gecko": {
|
"gecko": {
|
||||||
"id": "ai-filter@jordanwages",
|
"id": "ai-filter@jordanwages",
|
||||||
"strict_min_version": "128.0",
|
"strict_min_version": "128.0",
|
||||||
"strict_max_version": "139.*"
|
"strict_max_version": "140.*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"icons": {
|
"icons": {
|
||||||
|
|
|
@ -31,6 +31,10 @@
|
||||||
.tag {
|
.tag {
|
||||||
--bulma-tag-h: 318;
|
--bulma-tag-h: 318;
|
||||||
}
|
}
|
||||||
|
#diff-display {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
font-family: monospace;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
@ -150,6 +154,11 @@
|
||||||
<input type="checkbox" id="token-reduction"> Aggressive token reduction
|
<input type="checkbox" id="token-reduction"> Aggressive token reduction
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<label class="checkbox">
|
||||||
|
<input type="checkbox" id="show-debug-tab"> Show debug information
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label class="label" for="max_tokens">Max tokens</label>
|
<label class="label" for="max_tokens">Max tokens</label>
|
||||||
<div class="control">
|
<div class="control">
|
||||||
|
@ -216,11 +225,6 @@
|
||||||
<input class="input" type="number" step="0.01" id="tfs">
|
<input class="input" type="number" step="0.01" id="tfs">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
|
||||||
<label class="checkbox">
|
|
||||||
<input type="checkbox" id="show-debug-tab"> Advanced Options
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -286,9 +290,14 @@
|
||||||
<span>Debug</span>
|
<span>Debug</span>
|
||||||
</h2>
|
</h2>
|
||||||
<pre id="payload-display"></pre>
|
<pre id="payload-display"></pre>
|
||||||
|
<div id="diff-container" class="mt-4 is-hidden">
|
||||||
|
<label class="label">Prompt diff</label>
|
||||||
|
<div id="diff-display" class="box content is-family-monospace"></div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<script src="../resources/js/diff_match_patch_uncompressed.js"></script>
|
||||||
<script src="options.js"></script>
|
<script src="options.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -21,7 +21,9 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
'aiCache',
|
'aiCache',
|
||||||
'theme',
|
'theme',
|
||||||
'showDebugTab',
|
'showDebugTab',
|
||||||
'lastPayload'
|
'lastPayload',
|
||||||
|
'lastFullText',
|
||||||
|
'lastPromptText'
|
||||||
]);
|
]);
|
||||||
const tabButtons = document.querySelectorAll('#main-tabs li');
|
const tabButtons = document.querySelectorAll('#main-tabs li');
|
||||||
const tabs = document.querySelectorAll('.tab-content');
|
const tabs = document.querySelectorAll('.tab-content');
|
||||||
|
@ -67,8 +69,31 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
|
|
||||||
await applyTheme(themeSelect.value);
|
await applyTheme(themeSelect.value);
|
||||||
const payloadDisplay = document.getElementById('payload-display');
|
const payloadDisplay = document.getElementById('payload-display');
|
||||||
if (defaults.lastPayload) {
|
const diffDisplay = document.getElementById('diff-display');
|
||||||
payloadDisplay.textContent = JSON.stringify(defaults.lastPayload, null, 2);
|
const diffContainer = document.getElementById('diff-container');
|
||||||
|
|
||||||
|
let lastFullText = defaults.lastFullText || '';
|
||||||
|
let lastPromptText = defaults.lastPromptText || '';
|
||||||
|
let lastPayload = defaults.lastPayload ? JSON.stringify(defaults.lastPayload, null, 2) : '';
|
||||||
|
|
||||||
|
if (lastPayload) {
|
||||||
|
payloadDisplay.textContent = lastPayload;
|
||||||
|
}
|
||||||
|
if (lastFullText && lastPromptText && diff_match_patch) {
|
||||||
|
const dmp = new diff_match_patch();
|
||||||
|
dmp.Diff_EditCost = 4;
|
||||||
|
const diffs = dmp.diff_main(lastFullText, lastPromptText);
|
||||||
|
dmp.diff_cleanupEfficiency(diffs);
|
||||||
|
const hasDiff = diffs.some(d => d[0] !== 0);
|
||||||
|
if (hasDiff) {
|
||||||
|
diffDisplay.innerHTML = dmp.diff_prettyHtml(diffs);
|
||||||
|
diffContainer.classList.remove('is-hidden');
|
||||||
|
} else {
|
||||||
|
diffDisplay.innerHTML = '';
|
||||||
|
diffContainer.classList.add('is-hidden');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
diffContainer.classList.add('is-hidden');
|
||||||
}
|
}
|
||||||
themeSelect.addEventListener('change', async () => {
|
themeSelect.addEventListener('change', async () => {
|
||||||
markDirty();
|
markDirty();
|
||||||
|
@ -719,6 +744,38 @@ document.addEventListener('DOMContentLoaded', async () => {
|
||||||
} catch {
|
} catch {
|
||||||
cacheCountEl.textContent = '?';
|
cacheCountEl.textContent = '?';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (debugTabToggle.checked) {
|
||||||
|
const latest = await storage.local.get(['lastPayload', 'lastFullText', 'lastPromptText']);
|
||||||
|
const payloadStr = latest.lastPayload ? JSON.stringify(latest.lastPayload, null, 2) : '';
|
||||||
|
if (payloadStr !== lastPayload) {
|
||||||
|
lastPayload = payloadStr;
|
||||||
|
payloadDisplay.textContent = payloadStr;
|
||||||
|
}
|
||||||
|
if (latest.lastFullText !== lastFullText || latest.lastPromptText !== lastPromptText) {
|
||||||
|
lastFullText = latest.lastFullText || '';
|
||||||
|
lastPromptText = latest.lastPromptText || '';
|
||||||
|
if (lastFullText && lastPromptText && diff_match_patch) {
|
||||||
|
const dmp = new diff_match_patch();
|
||||||
|
dmp.Diff_EditCost = 4;
|
||||||
|
const diffs = dmp.diff_main(lastFullText, lastPromptText);
|
||||||
|
dmp.diff_cleanupEfficiency(diffs);
|
||||||
|
const hasDiff = diffs.some(d => d[0] !== 0);
|
||||||
|
if (hasDiff) {
|
||||||
|
diffDisplay.innerHTML = dmp.diff_prettyHtml(diffs);
|
||||||
|
diffContainer.classList.remove('is-hidden');
|
||||||
|
} else {
|
||||||
|
diffDisplay.innerHTML = '';
|
||||||
|
diffContainer.classList.add('is-hidden');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
diffDisplay.innerHTML = '';
|
||||||
|
diffContainer.classList.add('is-hidden');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {}
|
||||||
}
|
}
|
||||||
|
|
||||||
refreshMaintenance();
|
refreshMaintenance();
|
||||||
|
|
2236
resources/js/diff_match_patch_uncompressed.js
Normal file
2236
resources/js/diff_match_patch_uncompressed.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue