Changeset 0.22.8 (#150)

This commit is contained in:
2026-03-04 16:06:12 +00:00
parent 389e47b0f9
commit 7e26a2a261
114 changed files with 3700 additions and 7572 deletions

View File

@@ -25,14 +25,14 @@ const Tokens = {
return total;
},
// Estimate tokens for a set of attachments (staged or sent).
// Estimate tokens for a set of files (staged or sent).
// Images: ~765 tokens (base tile estimate, reasonable cross-provider).
// Documents with extracted text: text length / 4.
// Other/unknown: raw size / 4 (rough fallback).
estimateAttachments(attachments) {
if (!attachments?.length) return 0;
estimateFiles(files) {
if (!files?.length) return 0;
let total = 0;
for (const att of attachments) {
for (const att of files) {
if (att.content_type?.startsWith('image/')) {
total += 765; // base tile estimate
} else if (att.extracted_text) {
@@ -83,16 +83,16 @@ function updateInputTokens() {
// Show relative to available context
const chat = App.chats.find(c => c.id === App.currentChatId);
const convTokens = Tokens.estimateConversation(chat?.messages || [], App.settings.systemPrompt);
// Include staged attachment estimates
const attTokens = Tokens.estimateAttachments(
(App.stagedAttachments || []).filter(a => a.status !== 'error').map(a => ({
// Include staged file estimates
const fileTokens = Tokens.estimateFiles(
(App.stagedFiles || []).filter(a => a.status !== 'error').map(a => ({
content_type: a.contentType,
size_bytes: a.sizeBytes,
}))
);
const totalWithInput = convTokens + inputTokens + attTokens;
const totalWithInput = convTokens + inputTokens + fileTokens;
const pct = totalWithInput / budget.maxContext;
const attLabel = attTokens > 0 ? ` +${Tokens.format(attTokens)} files` : '';
const attLabel = fileTokens > 0 ? ` +${Tokens.format(fileTokens)} files` : '';
el.textContent = `~${Tokens.format(inputTokens)} tokens${attLabel} · ${Tokens.format(totalWithInput)} / ${Tokens.format(budget.maxContext)} context`;
el.className = 'input-token-count' + (pct > 0.9 ? ' danger' : pct > 0.75 ? ' warning' : '');
} else {