Compare commits
No commits in common. "main" and "codex/reorganize-debug-options-and-improve-diff-display" have entirely different histories.
main
...
codex/reor
3 changed files with 8 additions and 29 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 and a diff between the unaltered message text and the final prompt.
|
- **Debug tab** – view the last request payload and message diff with live updates.
|
||||||
- **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.
|
||||||
|
|
|
@ -210,38 +210,17 @@ function collectText(part, bodyParts, attachments) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectRawText(part, bodyParts, attachments) {
|
function buildEmailText(full) {
|
||||||
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 = [];
|
||||||
const collect = applyTransforms ? collectText : collectRawText;
|
collectText(full, bodyParts, attachments);
|
||||||
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 (applyTransforms && tokenReduction) {
|
if (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;
|
||||||
|
@ -249,7 +228,7 @@ function buildEmailText(full, applyTransforms = true) {
|
||||||
return true;
|
return true;
|
||||||
}).join('\n');
|
}).join('\n');
|
||||||
}
|
}
|
||||||
return applyTransforms ? sanitizeString(combined) : combined;
|
return sanitizeString(combined);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateTimingStats(elapsed) {
|
function updateTimingStats(elapsed) {
|
||||||
|
@ -283,8 +262,8 @@ 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);
|
||||||
|
const originalText = text;
|
||||||
if (tokenReduction && maxTokens > 0) {
|
if (tokenReduction && maxTokens > 0) {
|
||||||
const limit = Math.floor(maxTokens * 0.9);
|
const limit = Math.floor(maxTokens * 0.9);
|
||||||
if (text.length > limit) {
|
if (text.length > limit) {
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Sortana",
|
"name": "Sortana",
|
||||||
"version": "2.2.0",
|
"version": "2.1.2",
|
||||||
"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": "140.*"
|
"strict_max_version": "139.*"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"icons": {
|
"icons": {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue