trimprompt 1.0.26 → 1.0.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/api-proxy.js +1 -0
- package/cache.js +1 -1
- package/ccr.js +1 -0
- package/cli.js +1 -1
- package/dashboard.js +1 -1
- package/executor.js +1 -1
- package/filters/devops.js +1 -1
- package/filters/generic.js +1 -1
- package/filters/git.js +1 -1
- package/filters/go.js +1 -1
- package/filters/index.js +1 -1
- package/filters/js.js +1 -1
- package/filters/python.js +1 -1
- package/filters/rust.js +1 -1
- package/filters/shell.js +1 -1
- package/index.html +448 -11
- package/mcp.js +1 -1
- package/package.json +1 -1
- package/proxy-conv.js +1 -0
- package/proxy-daemon.js +1 -0
- package/proxy-resp.js +1 -0
- package/redactor.js +1 -1
- package/seed.js +1 -1
- package/shims.js +1 -1
- package/simulate.js +1 -1
- package/sync.js +1 -1
- package/tracker.js +1 -1
package/index.html
CHANGED
|
@@ -287,6 +287,174 @@
|
|
|
287
287
|
background: var(--indigo);
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
+
.feature-tag {
|
|
291
|
+
display: inline-block;
|
|
292
|
+
padding: 2px 8px;
|
|
293
|
+
border-radius: 4px;
|
|
294
|
+
font-size: 0.7rem;
|
|
295
|
+
font-weight: 600;
|
|
296
|
+
margin-right: 3px;
|
|
297
|
+
white-space: nowrap;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.csa-row {
|
|
301
|
+
display: flex;
|
|
302
|
+
align-items: center;
|
|
303
|
+
gap: 16px;
|
|
304
|
+
padding: 16px 0;
|
|
305
|
+
border-bottom: 1px solid var(--border);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.csa-row:last-child { border-bottom: none; }
|
|
309
|
+
|
|
310
|
+
.csa-toggle {
|
|
311
|
+
position: relative;
|
|
312
|
+
width: 44px;
|
|
313
|
+
height: 24px;
|
|
314
|
+
flex-shrink: 0;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.csa-toggle input { opacity: 0; width: 0; height: 0; }
|
|
318
|
+
|
|
319
|
+
.csa-toggle .slider {
|
|
320
|
+
position: absolute;
|
|
321
|
+
inset: 0;
|
|
322
|
+
background: rgba(255,255,255,0.12);
|
|
323
|
+
border-radius: 12px;
|
|
324
|
+
cursor: pointer;
|
|
325
|
+
transition: background 0.2s;
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
.csa-toggle .slider::after {
|
|
329
|
+
content: "";
|
|
330
|
+
position: absolute;
|
|
331
|
+
width: 18px;
|
|
332
|
+
height: 18px;
|
|
333
|
+
left: 3px;
|
|
334
|
+
top: 3px;
|
|
335
|
+
background: #fff;
|
|
336
|
+
border-radius: 50%;
|
|
337
|
+
transition: transform 0.2s;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
.csa-toggle input:checked + .slider {
|
|
341
|
+
background: var(--emerald);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
.csa-toggle input:checked + .slider::after {
|
|
345
|
+
transform: translateX(20px);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
.csa-info { flex: 1; min-width: 0; }
|
|
349
|
+
|
|
350
|
+
.csa-info h4 {
|
|
351
|
+
font-family: 'Outfit', sans-serif;
|
|
352
|
+
font-weight: 700;
|
|
353
|
+
font-size: 0.95rem;
|
|
354
|
+
margin-bottom: 3px;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
.csa-info p {
|
|
358
|
+
font-size: 0.78rem;
|
|
359
|
+
color: var(--text-muted);
|
|
360
|
+
margin-bottom: 6px;
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
.csa-badges {
|
|
364
|
+
display: flex;
|
|
365
|
+
gap: 5px;
|
|
366
|
+
flex-wrap: wrap;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
.csa-badge {
|
|
370
|
+
font-size: 0.68rem;
|
|
371
|
+
font-weight: 500;
|
|
372
|
+
padding: 2px 8px;
|
|
373
|
+
border-radius: 4px;
|
|
374
|
+
background: rgba(255,255,255,0.06);
|
|
375
|
+
color: var(--text-muted);
|
|
376
|
+
border: 1px solid rgba(255,255,255,0.08);
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
.csa-stat {
|
|
380
|
+
text-align: right;
|
|
381
|
+
flex-shrink: 0;
|
|
382
|
+
min-width: 90px;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
.csa-stat .csa-val {
|
|
386
|
+
font-family: 'Outfit', sans-serif;
|
|
387
|
+
font-weight: 700;
|
|
388
|
+
font-size: 1.1rem;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
.csa-stat .csa-sub {
|
|
392
|
+
font-size: 0.7rem;
|
|
393
|
+
color: var(--text-muted);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
.csa-category {
|
|
397
|
+
font-family: 'Outfit', sans-serif;
|
|
398
|
+
font-weight: 700;
|
|
399
|
+
font-size: 0.8rem;
|
|
400
|
+
text-transform: uppercase;
|
|
401
|
+
letter-spacing: 0.08em;
|
|
402
|
+
color: var(--text-muted);
|
|
403
|
+
padding: 18px 0 6px;
|
|
404
|
+
border-bottom: 1px solid var(--border);
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
.csa-category:first-child { padding-top: 4px; }
|
|
408
|
+
|
|
409
|
+
.csa-summary {
|
|
410
|
+
display: grid;
|
|
411
|
+
grid-template-columns: repeat(4, 1fr);
|
|
412
|
+
gap: 16px;
|
|
413
|
+
margin-top: 16px;
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
.csa-summary-card {
|
|
417
|
+
background: rgba(255,255,255,0.03);
|
|
418
|
+
border: 1px solid var(--border);
|
|
419
|
+
border-radius: 12px;
|
|
420
|
+
padding: 16px;
|
|
421
|
+
text-align: center;
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
.csa-summary-card .csa-sum-label {
|
|
425
|
+
font-family: 'Outfit', sans-serif;
|
|
426
|
+
font-size: 0.7rem;
|
|
427
|
+
font-weight: 700;
|
|
428
|
+
text-transform: uppercase;
|
|
429
|
+
letter-spacing: 0.06em;
|
|
430
|
+
color: var(--text-muted);
|
|
431
|
+
margin-bottom: 6px;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
.csa-summary-card .csa-sum-val {
|
|
435
|
+
font-family: 'Outfit', sans-serif;
|
|
436
|
+
font-weight: 800;
|
|
437
|
+
font-size: 1.6rem;
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
.csa-status {
|
|
441
|
+
display: inline-block;
|
|
442
|
+
font-size: 0.65rem;
|
|
443
|
+
font-weight: 600;
|
|
444
|
+
padding: 2px 7px;
|
|
445
|
+
border-radius: 4px;
|
|
446
|
+
margin-left: 8px;
|
|
447
|
+
vertical-align: middle;
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
.csa-status.active { background: rgba(16,185,129,0.12); color: #10B981; }
|
|
451
|
+
.csa-status.off { background: rgba(250,199,117,0.12); color: #FAC775; }
|
|
452
|
+
.csa-status.soon { background: rgba(148,163,184,0.10); color: #64748B; }
|
|
453
|
+
|
|
454
|
+
.csa-row.is-soon { opacity: 0.5; }
|
|
455
|
+
.csa-row.is-soon .csa-toggle { pointer-events: none; }
|
|
456
|
+
.csa-row.is-off .csa-toggle input:not(:checked) + .slider { background: rgba(250,199,117,0.25); }
|
|
457
|
+
|
|
290
458
|
/* Inspect Modal */
|
|
291
459
|
.modal-overlay {
|
|
292
460
|
position: fixed;
|
|
@@ -500,6 +668,21 @@
|
|
|
500
668
|
</div>
|
|
501
669
|
</div>
|
|
502
670
|
|
|
671
|
+
<!-- CSA Feature Controls -->
|
|
672
|
+
<div class="history-section" id="csa-section">
|
|
673
|
+
<div class="history-header" style="cursor:pointer;user-select:none;" onclick="toggleCsa()">
|
|
674
|
+
<h2 style="display:flex;align-items:center;gap:10px;">
|
|
675
|
+
<span id="csa-chevron" style="display:inline-block;transition:transform 0.2s;transform:rotate(0deg);font-size:0.8rem;">▶</span>
|
|
676
|
+
CSA Feature Controls
|
|
677
|
+
<span id="csa-count-badge" style="font-size:0.75rem;font-weight:500;color:var(--text-muted);font-family:'Inter',sans-serif;"></span>
|
|
678
|
+
</h2>
|
|
679
|
+
</div>
|
|
680
|
+
<div id="csa-body" style="display:none;">
|
|
681
|
+
<div id="csa-list"></div>
|
|
682
|
+
<div class="csa-summary" id="csa-summary"></div>
|
|
683
|
+
</div>
|
|
684
|
+
</div>
|
|
685
|
+
|
|
503
686
|
<div class="history-section">
|
|
504
687
|
<div class="history-header" style="display: flex; align-items: center; gap: 16px;">
|
|
505
688
|
<h2 style="margin: 0;">Command Execution History</h2>
|
|
@@ -514,6 +697,7 @@
|
|
|
514
697
|
<tr>
|
|
515
698
|
<th>Timestamp</th>
|
|
516
699
|
<th>Command</th>
|
|
700
|
+
<th>Features</th>
|
|
517
701
|
<th>Raw Tokens</th>
|
|
518
702
|
<th>Compressed</th>
|
|
519
703
|
<th>Savings</th>
|
|
@@ -523,7 +707,7 @@
|
|
|
523
707
|
</thead>
|
|
524
708
|
<tbody id="history-table-body">
|
|
525
709
|
<tr>
|
|
526
|
-
<td colspan="
|
|
710
|
+
<td colspan="8" style="text-align: center; color: var(--text-muted);">Loading logs...</td>
|
|
527
711
|
</tr>
|
|
528
712
|
</tbody>
|
|
529
713
|
</table>
|
|
@@ -557,6 +741,234 @@
|
|
|
557
741
|
let savingsChart = null;
|
|
558
742
|
let currentFilter = 'ai';
|
|
559
743
|
|
|
744
|
+
const FEATURE_META = {
|
|
745
|
+
filter: { label: 'Filter', color: '#6366F1', bg: 'rgba(99,102,241,0.12)' },
|
|
746
|
+
redact: { label: 'Redact', color: '#EF4444', bg: 'rgba(239,68,68,0.12)' },
|
|
747
|
+
lock: { label: 'Lock File', color: '#FAC775', bg: 'rgba(250,199,117,0.12)' },
|
|
748
|
+
binary: { label: 'Binary', color: '#F09595', bg: 'rgba(240,149,149,0.12)' },
|
|
749
|
+
skeleton: { label: 'Skeleton', color: '#AFA9EC', bg: 'rgba(175,169,236,0.12)' },
|
|
750
|
+
whitespace: { label: 'Whitespace', color: '#94A3B8', bg: 'rgba(148,163,184,0.12)' },
|
|
751
|
+
cache: { label: 'Cache Hit', color: '#10B981', bg: 'rgba(16,185,129,0.12)' },
|
|
752
|
+
truncate: { label: 'Truncate', color: '#3B82F6', bg: 'rgba(59,130,246,0.12)' },
|
|
753
|
+
conv_compress: { label: 'Proxy', color: '#7F77DD', bg: 'rgba(127,119,221,0.15)' },
|
|
754
|
+
resp_optimize: { label: 'Proxy', color: '#7F77DD', bg: 'rgba(127,119,221,0.15)' },
|
|
755
|
+
};
|
|
756
|
+
|
|
757
|
+
function featureTagHtml(features) {
|
|
758
|
+
if (!features || features.length === 0) return '<span style="color:#475569;font-size:11px;">—</span>';
|
|
759
|
+
return features.map(f => {
|
|
760
|
+
const m = FEATURE_META[f] || { label: f, color: '#94A3B8', bg: 'rgba(148,163,184,0.12)' };
|
|
761
|
+
return `<span class="feature-tag" style="color:${m.color};background:${m.bg};">${m.label}</span>`;
|
|
762
|
+
}).join('');
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// status: 'active' = working, 'off' = in code but off by default, 'soon' = not implemented yet
|
|
766
|
+
const CSA_FEATURES = [
|
|
767
|
+
{ category: 'C — Compression (CLI Output)', features: [
|
|
768
|
+
{ key: 'filter', title: '27 Command filters', desc: 'git, cat, ls, find, grep, docker, kubectl, pytest, jest, cargo, go, pip, npm, ruff', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'on matched commands', status: 'active' },
|
|
769
|
+
{ key: 'ansi_strip', title: 'ANSI strip', desc: 'Remove color codes, cursor sequences from all output', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'on colored output', status: 'active' },
|
|
770
|
+
{ key: 'whitespace', title: 'Whitespace collapse', desc: 'Trailing spaces + 3+ blank lines → 1. Lossless', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'on verbose output', status: 'active' },
|
|
771
|
+
{ key: 'lock', title: 'Lock file detection', desc: 'package-lock.json, yarn.lock, Cargo.lock, go.sum → summary line', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'on lock files', status: 'active' },
|
|
772
|
+
{ key: 'binary', title: 'Binary/minified detection', desc: '.png, .min.js, .wasm, .pdf, 40+ extensions → placeholder', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'on binaries', status: 'active' },
|
|
773
|
+
{ key: 'json_crusher', title: 'SmartCrusher (JSON arrays → tables)', desc: 'Arrays of objects compressed to tabular format. Removes resolved/integrity fields', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'on JSON arrays', status: 'active' },
|
|
774
|
+
{ key: 'skeleton', title: 'Code skeleton (imports + signatures only)', desc: 'Files over 100 lines → show structure only, collapse bodies', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'on large files', status: 'active' },
|
|
775
|
+
{ key: 'ccr', title: 'CCR — Reversible compression', desc: 'Store original in cache, send compressed. Agent can retrieve full via trim retrieve', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statSub: 'deeper compression', status: 'off' },
|
|
776
|
+
]},
|
|
777
|
+
{ category: 'S — Security', features: [
|
|
778
|
+
{ key: 'redact', title: 'Secret redaction (20 patterns)', desc: 'AWS keys, API tokens, JWTs, DB strings auto-blocked', badges: ['Claude','Cursor','Copilot','Gemini','Antigravity'], statKey: 'secrets', statSub: 'secrets blocked', status: 'active' },
|
|
779
|
+
]},
|
|
780
|
+
{ category: 'P — Proxy (Universal AI API Compression)', features: [
|
|
781
|
+
{ key: 'conv_compress', title: 'Conversation history compression', desc: 'Score old messages by importance, drop low-value ones. Via trim proxy', badges: ['Claude Code CLI','Codex CLI','Aider','Copilot CLI','SDK / curl'], statSub: 'on conversation', status: 'active' },
|
|
782
|
+
{ key: 'resp_optimize', title: 'Response length optimization', desc: 'Set optimal max_tokens per request based on task complexity. Via trim proxy', badges: ['Claude Code CLI','Codex CLI','Aider','Copilot CLI','SDK / curl'], statSub: 'on output', status: 'active' },
|
|
783
|
+
], hasProxyToggle: true },
|
|
784
|
+
];
|
|
785
|
+
|
|
786
|
+
let proxyRunning = false;
|
|
787
|
+
// Cache last-rendered proxy HTML so the periodic full rebuild of the CSA list
|
|
788
|
+
// can repaint these async-filled areas instantly instead of flashing empty.
|
|
789
|
+
let lastProxyToggleHtml = '';
|
|
790
|
+
let lastProxySavingsHtml = '';
|
|
791
|
+
|
|
792
|
+
async function updateProxyToggle() {
|
|
793
|
+
const area = document.getElementById('proxy-toggle-area');
|
|
794
|
+
if (!area) return;
|
|
795
|
+
try {
|
|
796
|
+
const resp = await fetch('/api/proxy/status');
|
|
797
|
+
const status = await resp.json();
|
|
798
|
+
proxyRunning = status.running;
|
|
799
|
+
const color = proxyRunning ? 'var(--emerald)' : '#64748B';
|
|
800
|
+
const label = proxyRunning ? `Running on port ${status.port}` : 'Stopped';
|
|
801
|
+
const html = `
|
|
802
|
+
<span style="display:inline-flex;align-items:center;gap:8px;font-family:'Inter',sans-serif;font-size:12px;font-weight:500;text-transform:none;letter-spacing:0;">
|
|
803
|
+
<span style="color:${color};">${label}</span>
|
|
804
|
+
<label class="csa-toggle" style="transform:scale(0.85);">
|
|
805
|
+
<input type="checkbox" ${proxyRunning ? 'checked' : ''} onchange="toggleProxy(this.checked)">
|
|
806
|
+
<span class="slider"></span>
|
|
807
|
+
</label>
|
|
808
|
+
</span>`;
|
|
809
|
+
// Only touch the DOM when the markup actually changed, to avoid flicker.
|
|
810
|
+
if (html !== lastProxyToggleHtml) {
|
|
811
|
+
lastProxyToggleHtml = html;
|
|
812
|
+
area.innerHTML = html;
|
|
813
|
+
}
|
|
814
|
+
} catch { }
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
async function updateProxySavings() {
|
|
818
|
+
const card = document.getElementById('proxy-savings-card');
|
|
819
|
+
if (!card) return;
|
|
820
|
+
try {
|
|
821
|
+
const model = document.getElementById('model-select').value;
|
|
822
|
+
const resp = await fetch('/api/stats/proxy-summary?model=' + encodeURIComponent(model));
|
|
823
|
+
const s = await resp.json();
|
|
824
|
+
const cell = (label, val, color) =>
|
|
825
|
+
`<div style="flex:1;text-align:center;padding:10px 6px;">
|
|
826
|
+
<div style="font-size:18px;font-weight:700;color:${color};font-family:'Inter',sans-serif;">${val}</div>
|
|
827
|
+
<div style="font-size:10px;color:#64748B;text-transform:uppercase;letter-spacing:0.5px;margin-top:2px;">${label}</div>
|
|
828
|
+
</div>`;
|
|
829
|
+
const html = `
|
|
830
|
+
<div style="display:flex;gap:8px;margin:10px 0 14px;background:rgba(127,119,221,0.06);border:1px solid rgba(127,119,221,0.18);border-radius:10px;">
|
|
831
|
+
${cell('Requests', (s.requests || 0).toLocaleString(), '#7F77DD')}
|
|
832
|
+
${cell('Tokens Saved', (s.total_tokens_saved || 0).toLocaleString(), '#10B981')}
|
|
833
|
+
${cell('Saved', '$' + (s.money_saved_usd || 0).toFixed(2), '#10B981')}
|
|
834
|
+
${cell('Reduction', (s.savings_percentage || 0) + '%', 'var(--indigo)')}
|
|
835
|
+
</div>`;
|
|
836
|
+
// Only touch the DOM when the markup actually changed, to avoid flicker.
|
|
837
|
+
if (html !== lastProxySavingsHtml) {
|
|
838
|
+
lastProxySavingsHtml = html;
|
|
839
|
+
card.innerHTML = html;
|
|
840
|
+
}
|
|
841
|
+
} catch { }
|
|
842
|
+
}
|
|
843
|
+
|
|
844
|
+
async function toggleProxy(enable) {
|
|
845
|
+
try {
|
|
846
|
+
if (enable) {
|
|
847
|
+
await fetch('/api/proxy/start', { method: 'POST' });
|
|
848
|
+
} else {
|
|
849
|
+
await fetch('/api/proxy/stop', { method: 'POST' });
|
|
850
|
+
}
|
|
851
|
+
setTimeout(updateProxyToggle, 500);
|
|
852
|
+
} catch {}
|
|
853
|
+
}
|
|
854
|
+
|
|
855
|
+
let csaOpen = false;
|
|
856
|
+
function toggleCsa() {
|
|
857
|
+
csaOpen = !csaOpen;
|
|
858
|
+
document.getElementById('csa-body').style.display = csaOpen ? '' : 'none';
|
|
859
|
+
document.getElementById('csa-chevron').style.transform = csaOpen ? 'rotate(90deg)' : 'rotate(0deg)';
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
let csaToggles = {};
|
|
863
|
+
|
|
864
|
+
async function loadCsaToggles() {
|
|
865
|
+
try {
|
|
866
|
+
const resp = await fetch('/api/config/features');
|
|
867
|
+
const data = await resp.json();
|
|
868
|
+
csaToggles = data;
|
|
869
|
+
} catch { csaToggles = {}; }
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
async function saveCsaToggle(key, enabled) {
|
|
873
|
+
csaToggles[key] = enabled;
|
|
874
|
+
try { await fetch('/api/config/features', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(csaToggles) }); } catch {}
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
function renderCsaSection(logs) {
|
|
878
|
+
const pricePerM = PRICING_TABLE[document.getElementById('model-select').value] || 3.00;
|
|
879
|
+
const totalRaw = logs.reduce((s, l) => s + l.estimated_raw_tokens, 0);
|
|
880
|
+
const totalComp = logs.reduce((s, l) => s + l.estimated_compressed_tokens, 0);
|
|
881
|
+
const totalSaved = logs.reduce((s, l) => s + l.tokens_saved, 0);
|
|
882
|
+
const totalSecrets = logs.reduce((s, l) => s + (l.secrets_found || 0), 0);
|
|
883
|
+
const savedUsd = (totalSaved * pricePerM) / 1000000;
|
|
884
|
+
const reductionPct = totalRaw > 0 ? ((totalSaved / totalRaw) * 100).toFixed(1) : '0.0';
|
|
885
|
+
|
|
886
|
+
const featureCounts = {};
|
|
887
|
+
const featureSavings = {};
|
|
888
|
+
logs.forEach(l => {
|
|
889
|
+
(l.features || []).forEach(f => {
|
|
890
|
+
featureCounts[f] = (featureCounts[f] || 0) + 1;
|
|
891
|
+
featureSavings[f] = (featureSavings[f] || 0) + l.tokens_saved;
|
|
892
|
+
});
|
|
893
|
+
});
|
|
894
|
+
|
|
895
|
+
const list = document.getElementById('csa-list');
|
|
896
|
+
let html = '';
|
|
897
|
+
|
|
898
|
+
CSA_FEATURES.forEach(cat => {
|
|
899
|
+
if (cat.hasProxyToggle) {
|
|
900
|
+
html += `<div class="csa-category" style="display:flex;justify-content:space-between;align-items:center;">${cat.category}<span id="proxy-toggle-area">${lastProxyToggleHtml}</span></div>`;
|
|
901
|
+
html += `<div id="proxy-savings-card">${lastProxySavingsHtml}</div>`;
|
|
902
|
+
} else {
|
|
903
|
+
html += `<div class="csa-category">${cat.category}</div>`;
|
|
904
|
+
}
|
|
905
|
+
cat.features.forEach(f => {
|
|
906
|
+
const isSoon = f.status === 'soon';
|
|
907
|
+
const isOff = f.status === 'off';
|
|
908
|
+
const defaultOn = f.status === 'active';
|
|
909
|
+
const checked = isSoon ? false : (csaToggles[f.key] !== undefined ? csaToggles[f.key] : defaultOn);
|
|
910
|
+
const count = featureCounts[f.key] || 0;
|
|
911
|
+
const statusLabels = { active: 'Active', off: 'Off by default', soon: 'Coming soon' };
|
|
912
|
+
let statVal, statColor;
|
|
913
|
+
if (f.statKey === 'secrets') {
|
|
914
|
+
statVal = totalSecrets.toLocaleString();
|
|
915
|
+
statColor = '#EF4444';
|
|
916
|
+
} else if (isSoon) {
|
|
917
|
+
statVal = '—';
|
|
918
|
+
statColor = '#64748B';
|
|
919
|
+
} else {
|
|
920
|
+
const featureSavedTokens = featureSavings[f.key] || 0;
|
|
921
|
+
const featureSaved = (featureSavedTokens * pricePerM) / 1000000;
|
|
922
|
+
statVal = '$' + featureSaved.toFixed(2);
|
|
923
|
+
statColor = '#10B981';
|
|
924
|
+
}
|
|
925
|
+
const rowClass = isSoon ? 'csa-row is-soon' : isOff ? 'csa-row is-off' : 'csa-row';
|
|
926
|
+
html += `<div class="${rowClass}">
|
|
927
|
+
<label class="csa-toggle">
|
|
928
|
+
<input type="checkbox" ${checked ? 'checked' : ''} ${isSoon ? 'disabled' : ''} onchange="saveCsaToggle('${f.key}', this.checked)">
|
|
929
|
+
<span class="slider"></span>
|
|
930
|
+
</label>
|
|
931
|
+
<div class="csa-info">
|
|
932
|
+
<h4>${f.title}<span class="csa-status ${f.status}">${statusLabels[f.status]}</span></h4>
|
|
933
|
+
<p>${f.desc}</p>
|
|
934
|
+
<div class="csa-badges">${f.badges.map(b => `<span class="csa-badge">${b}</span>`).join('')}</div>
|
|
935
|
+
</div>
|
|
936
|
+
<div class="csa-stat">
|
|
937
|
+
<div class="csa-val" style="color:${statColor};">${statVal}</div>
|
|
938
|
+
<div class="csa-sub">${f.statSub}</div>
|
|
939
|
+
</div>
|
|
940
|
+
</div>`;
|
|
941
|
+
});
|
|
942
|
+
});
|
|
943
|
+
list.innerHTML = html;
|
|
944
|
+
|
|
945
|
+
const activeCount = CSA_FEATURES.reduce((s, c) => s + c.features.filter(f => f.status === 'active').length, 0);
|
|
946
|
+
const totalCount = CSA_FEATURES.reduce((s, c) => s + c.features.length, 0);
|
|
947
|
+
document.getElementById('csa-count-badge').textContent = `${activeCount}/${totalCount} active`;
|
|
948
|
+
|
|
949
|
+
// Proxy toggle + dedicated savings card
|
|
950
|
+
updateProxyToggle();
|
|
951
|
+
updateProxySavings();
|
|
952
|
+
|
|
953
|
+
document.getElementById('csa-summary').innerHTML = `
|
|
954
|
+
<div class="csa-summary-card">
|
|
955
|
+
<div class="csa-sum-label">Tokens Saved</div>
|
|
956
|
+
<div class="csa-sum-val" style="color:var(--emerald);">${totalSaved.toLocaleString()}</div>
|
|
957
|
+
</div>
|
|
958
|
+
<div class="csa-summary-card">
|
|
959
|
+
<div class="csa-sum-label">Total Saved</div>
|
|
960
|
+
<div class="csa-sum-val" style="color:var(--emerald);">$${savedUsd.toFixed(2)}</div>
|
|
961
|
+
</div>
|
|
962
|
+
<div class="csa-summary-card">
|
|
963
|
+
<div class="csa-sum-label">Reduction</div>
|
|
964
|
+
<div class="csa-sum-val" style="color:var(--indigo);">${reductionPct}%</div>
|
|
965
|
+
</div>
|
|
966
|
+
<div class="csa-summary-card">
|
|
967
|
+
<div class="csa-sum-label">Secrets Blocked</div>
|
|
968
|
+
<div class="csa-sum-val" style="color:var(--red);">${totalSecrets.toLocaleString()}</div>
|
|
969
|
+
</div>`;
|
|
970
|
+
}
|
|
971
|
+
|
|
560
972
|
function isAiCommand(log) {
|
|
561
973
|
// New logs have ai_detected field explicitly
|
|
562
974
|
if (log.ai_detected === true) return true;
|
|
@@ -776,6 +1188,9 @@
|
|
|
776
1188
|
// Chart + summary always use AI-only logs
|
|
777
1189
|
renderChart(aiLogs, resolvedModel);
|
|
778
1190
|
|
|
1191
|
+
// CSA Feature Controls
|
|
1192
|
+
renderCsaSection(logs);
|
|
1193
|
+
|
|
779
1194
|
// Security banner — aggregate across all logs
|
|
780
1195
|
let totalSecrets = 0;
|
|
781
1196
|
const allSecretTypes = {};
|
|
@@ -800,29 +1215,32 @@
|
|
|
800
1215
|
secBanner.style.display = 'none';
|
|
801
1216
|
}
|
|
802
1217
|
|
|
803
|
-
const displayLogs = currentFilter === 'ai' ? aiLogs : logs
|
|
1218
|
+
const displayLogs = (currentFilter === 'ai' ? aiLogs : logs)
|
|
1219
|
+
.filter(l => l.tokens_saved > 0);
|
|
804
1220
|
|
|
805
1221
|
const tbody = document.getElementById('history-table-body');
|
|
806
1222
|
if (displayLogs.length === 0) {
|
|
807
1223
|
const msg = currentFilter === 'ai'
|
|
808
1224
|
? 'No AI agent commands detected yet. Commands from Claude Code, Cursor, Copilot etc. will appear here.'
|
|
809
1225
|
: 'No logs recorded yet. Run commands with TrimPrompt to see stats!';
|
|
810
|
-
tbody.innerHTML = `<tr><td colspan="
|
|
1226
|
+
tbody.innerHTML = `<tr><td colspan="8" style="text-align: center; color: var(--text-muted);">${msg}</td></tr>`;
|
|
811
1227
|
return;
|
|
812
1228
|
}
|
|
813
1229
|
|
|
1230
|
+
const INITIAL_LIMIT = 100;
|
|
1231
|
+
const reversed = displayLogs.reverse();
|
|
814
1232
|
tbody.innerHTML = '';
|
|
815
|
-
|
|
1233
|
+
|
|
1234
|
+
function renderRow(log) {
|
|
816
1235
|
const tr = document.createElement('tr');
|
|
817
1236
|
const time = new Date(log.timestamp).toLocaleTimeString();
|
|
818
|
-
|
|
819
|
-
const savingsPct = log.raw_chars > 0
|
|
1237
|
+
const savingsPct = log.raw_chars > 0
|
|
820
1238
|
? ((log.estimated_raw_tokens - log.estimated_compressed_tokens) / log.estimated_raw_tokens * 100).toFixed(1)
|
|
821
1239
|
: '0.0';
|
|
822
|
-
|
|
823
1240
|
tr.innerHTML = `
|
|
824
1241
|
<td>${time}</td>
|
|
825
1242
|
<td style="font-weight: 500;">${log.command}${log.secrets_found ? ' <span style="color:#F09595;font-size:11px;" title="' + log.secrets_found + ' secrets redacted">🛡' + log.secrets_found + '</span>' : ''}</td>
|
|
1243
|
+
<td>${featureTagHtml(log.features)}</td>
|
|
826
1244
|
<td>${log.estimated_raw_tokens.toLocaleString()}</td>
|
|
827
1245
|
<td>${log.estimated_compressed_tokens.toLocaleString()}</td>
|
|
828
1246
|
<td style="color: var(--emerald); font-weight: 600;">${savingsPct}%</td>
|
|
@@ -835,8 +1253,27 @@
|
|
|
835
1253
|
<button class="btn-inspect" data-id="${log.id}" data-cmd="${log.command}" data-sec="${log.secrets_found || 0}" data-types="${(log.secret_types || []).join(',')}" onclick="inspectFromBtn(this)">Inspect</button>
|
|
836
1254
|
</td>
|
|
837
1255
|
`;
|
|
838
|
-
|
|
839
|
-
}
|
|
1256
|
+
return tr;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
reversed.slice(0, INITIAL_LIMIT).forEach(log => tbody.appendChild(renderRow(log)));
|
|
1260
|
+
|
|
1261
|
+
if (reversed.length > INITIAL_LIMIT) {
|
|
1262
|
+
const moreTr = document.createElement('tr');
|
|
1263
|
+
moreTr.id = 'show-more-row';
|
|
1264
|
+
moreTr.innerHTML = `<td colspan="8" style="text-align:center;padding:12px;">
|
|
1265
|
+
<button onclick="document.getElementById('show-more-row').remove();document.querySelectorAll('.hidden-log-row').forEach(r=>r.style.display='')" style="background:rgba(127,119,221,0.15);color:#7F77DD;border:none;padding:8px 24px;border-radius:8px;cursor:pointer;font-size:13px;font-weight:500;">
|
|
1266
|
+
Show ${reversed.length - INITIAL_LIMIT} more entries
|
|
1267
|
+
</button>
|
|
1268
|
+
</td>`;
|
|
1269
|
+
tbody.appendChild(moreTr);
|
|
1270
|
+
reversed.slice(INITIAL_LIMIT).forEach(log => {
|
|
1271
|
+
const tr = renderRow(log);
|
|
1272
|
+
tr.className = 'hidden-log-row';
|
|
1273
|
+
tr.style.display = 'none';
|
|
1274
|
+
tbody.appendChild(tr);
|
|
1275
|
+
});
|
|
1276
|
+
}
|
|
840
1277
|
} catch (err) {
|
|
841
1278
|
console.error('Failed to fetch history logs', err);
|
|
842
1279
|
}
|
|
@@ -1000,8 +1437,8 @@
|
|
|
1000
1437
|
} catch {}
|
|
1001
1438
|
}
|
|
1002
1439
|
|
|
1003
|
-
// Initial load: detect model
|
|
1004
|
-
autoDetectModel().then(() => {
|
|
1440
|
+
// Initial load: detect model + load CSA toggles, then load stats
|
|
1441
|
+
Promise.all([autoDetectModel(), loadCsaToggles()]).then(() => {
|
|
1005
1442
|
loadStats();
|
|
1006
1443
|
loadHistory();
|
|
1007
1444
|
});
|
package/mcp.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
'use strict';function
|
|
1
|
+
'use strict';function a0_0x56e5(_0x1455bc,_0x583648){_0x1455bc=_0x1455bc-0xca;const _0x30ff4a=a0_0x30ff();let _0x56e55f=_0x30ff4a[_0x1455bc];return _0x56e55f;}function a0_0x30ff(){const _0x5a62cb=['pipe','1299739HhnPda','isArray','create','stringify','features_enabled','getOwnPropertyDescriptor','close','writable','proxy:resp-optimize','\x20tokens\x20saved)','854936yALIWt','result','defineProperty','write','conv_compress','4235KOLurk','proxy:conv-compress','default','prototype','tracker','call','./tracker','max_tokens','stdout','hasOwnProperty','4990kUqoJb','inherit','exit','createInterface','error','savedTokens','__setModuleDefault','__esModule','compressConversation','configurable','logExecution','compressOutput','1024992OuIOxp','jsonrpc','mcp-tool-call','./proxy-resp','./filters','trimmedCount','6MwascW','redaction_enabled','content','\x20messages\x20(','line','366550GqJQLj','child_process','\x20messages','\x20trimmed,\x20~','resp_optimize','1fgYPUK','12IIiSgS','mcp\x20tool\x20(id:\x20','431529vlTTjh','get','stdin','text','max_tokens:\x20','end','message','1836693KazVbI','spawn','[TrimPrompt]\x20MCP\x20Server\x20Spawn\x20Error:\x20','length','messages','parse','getOwnPropertyNames','trim','2.0'];a0_0x30ff=function(){return _0x5a62cb;};return a0_0x30ff();}const a0_0x253686=a0_0x56e5;(function(_0x2409a1,_0x3b7bda){const _0x7dcea9=a0_0x56e5,_0xa61ba5=_0x2409a1();while(!![]){try{const _0x5fb63d=-parseInt(_0x7dcea9(0xef))/0x1*(parseInt(_0x7dcea9(0x10d))/0x2)+-parseInt(_0x7dcea9(0xf2))/0x3*(-parseInt(_0x7dcea9(0xf0))/0x4)+-parseInt(_0x7dcea9(0xea))/0x5+-parseInt(_0x7dcea9(0xe5))/0x6*(parseInt(_0x7dcea9(0x103))/0x7)+parseInt(_0x7dcea9(0xdf))/0x8+parseInt(_0x7dcea9(0xf9))/0x9+parseInt(_0x7dcea9(0xd3))/0xa*(parseInt(_0x7dcea9(0x112))/0xb);if(_0x5fb63d===_0x3b7bda)break;else _0xa61ba5['push'](_0xa61ba5['shift']());}catch(_0xaddab){_0xa61ba5['push'](_0xa61ba5['shift']());}}}(a0_0x30ff,0x41c4e));var __createBinding=this&&this['__createBinding']||(Object['create']?function(_0x3fbad1,_0x596a2f,_0x361691,_0x1b2c06){const _0x2e5c7d=a0_0x56e5;if(_0x1b2c06===undefined)_0x1b2c06=_0x361691;var _0xc1940c=Object[_0x2e5c7d(0x108)](_0x596a2f,_0x361691);(!_0xc1940c||(_0x2e5c7d(0xf3)in _0xc1940c?!_0x596a2f[_0x2e5c7d(0xda)]:_0xc1940c[_0x2e5c7d(0x10a)]||_0xc1940c[_0x2e5c7d(0xdc)]))&&(_0xc1940c={'enumerable':!![],'get':function(){return _0x596a2f[_0x361691];}}),Object[_0x2e5c7d(0x10f)](_0x3fbad1,_0x1b2c06,_0xc1940c);}:function(_0x4c4b66,_0x48ff34,_0x9b34a4,_0x5ed9a6){if(_0x5ed9a6===undefined)_0x5ed9a6=_0x9b34a4;_0x4c4b66[_0x5ed9a6]=_0x48ff34[_0x9b34a4];}),__setModuleDefault=this&&this[a0_0x253686(0xd9)]||(Object[a0_0x253686(0x105)]?function(_0x519df6,_0x54282b){const _0x553de8=a0_0x253686;Object['defineProperty'](_0x519df6,_0x553de8(0xcb),{'enumerable':!![],'value':_0x54282b});}:function(_0x3573a8,_0x7296a5){const _0x1a47b2=a0_0x253686;_0x3573a8[_0x1a47b2(0xcb)]=_0x7296a5;}),__importStar=this&&this['__importStar']||(function(){var _0x33117a=function(_0x3bc9ae){const _0x2d10ce=a0_0x56e5;return _0x33117a=Object[_0x2d10ce(0xff)]||function(_0x51b1a4){const _0x5075df=_0x2d10ce;var _0x27f590=[];for(var _0x46f0b4 in _0x51b1a4)if(Object[_0x5075df(0xcc)][_0x5075df(0xd2)][_0x5075df(0xce)](_0x51b1a4,_0x46f0b4))_0x27f590[_0x27f590['length']]=_0x46f0b4;return _0x27f590;},_0x33117a(_0x3bc9ae);};return function(_0x53e35e){const _0x18d3a6=a0_0x56e5;if(_0x53e35e&&_0x53e35e[_0x18d3a6(0xda)])return _0x53e35e;var _0x287eb0={};if(_0x53e35e!=null){for(var _0x184356=_0x33117a(_0x53e35e),_0xbee6da=0x0;_0xbee6da<_0x184356[_0x18d3a6(0xfc)];_0xbee6da++)if(_0x184356[_0xbee6da]!==_0x18d3a6(0xcb))__createBinding(_0x287eb0,_0x53e35e,_0x184356[_0xbee6da]);}return __setModuleDefault(_0x287eb0,_0x53e35e),_0x287eb0;};}());Object[a0_0x253686(0x10f)](exports,'__esModule',{'value':!![]}),exports['runMcpProxy']=runMcpProxy;const child_process_1=require(a0_0x253686(0xeb)),readline=__importStar(require('readline')),filters_1=require(a0_0x253686(0xe3)),tracker_1=require(a0_0x253686(0xcf)),proxy_conv_1=require('./proxy-conv'),proxy_resp_1=require(a0_0x253686(0xe2));function runMcpProxy(_0x5284a8,_0x3f69e1){const _0x11976f=a0_0x253686,_0x140044=(0x0,child_process_1[_0x11976f(0xfa)])(_0x5284a8,_0x3f69e1,{'stdio':[_0x11976f(0x102),_0x11976f(0x102),_0x11976f(0xd4)]}),_0x1dbe06=tracker_1[_0x11976f(0xcd)]['getConfig'](),_0x1e0011=_0x1dbe06[_0x11976f(0x107)]||{},_0x4a9b66=_0x1e0011[_0x11976f(0x111)]!==![],_0x37ec75=_0x1e0011[_0x11976f(0xee)]!==![],_0x1bd6b5=readline['createInterface']({'input':process[_0x11976f(0xf4)],'terminal':![]});_0x1bd6b5['on'](_0x11976f(0xe9),_0x15d249=>{const _0x5d20e6=_0x11976f;try{const _0x17bac0=JSON['parse'](_0x15d249);if(_0x17bac0&&_0x17bac0[_0x5d20e6(0xe0)]===_0x5d20e6(0x101)&&_0x17bac0['method']&&_0x17bac0['params']){const _0x5e28fd=_0x17bac0['params'];if(Array[_0x5d20e6(0x104)](_0x5e28fd[_0x5d20e6(0xfd)])&&_0x5e28fd[_0x5d20e6(0xfd)]['length']>0x0){if(_0x4a9b66){const _0x11750d=(0x0,proxy_conv_1[_0x5d20e6(0xdb)])(_0x5e28fd['messages']);(_0x11750d[_0x5d20e6(0xe4)]>0x0||_0x11750d['savedTokens']>0x0)&&(_0x5e28fd[_0x5d20e6(0xfd)]=_0x11750d[_0x5d20e6(0xfd)],tracker_1[_0x5d20e6(0xcd)][_0x5d20e6(0xdd)](_0x5d20e6(0xca),_0x11750d[_0x5d20e6(0xe4)]+_0x11750d[_0x5d20e6(0xfd)][_0x5d20e6(0xfc)]+_0x5d20e6(0xec),_0x11750d[_0x5d20e6(0xfd)][_0x5d20e6(0xfc)]+_0x5d20e6(0xe8)+_0x11750d['trimmedCount']+_0x5d20e6(0xed)+_0x11750d[_0x5d20e6(0xd8)]+_0x5d20e6(0x10c),0x0,undefined,[_0x5d20e6(0x111)]));}if(_0x37ec75){const _0x4fa83a=(0x0,proxy_resp_1['optimizeMaxTokens'])(_0x5e28fd[_0x5d20e6(0xfd)],_0x5e28fd[_0x5d20e6(0xd0)]);if(_0x4fa83a){const _0x11efa7=_0x5e28fd['max_tokens']||_0x5d20e6(0xcb);_0x5e28fd[_0x5d20e6(0xd0)]=_0x4fa83a[_0x5d20e6(0xd0)],tracker_1[_0x5d20e6(0xcd)][_0x5d20e6(0xdd)](_0x5d20e6(0x10b),_0x5d20e6(0xf6)+_0x11efa7,_0x5d20e6(0xf6)+_0x4fa83a[_0x5d20e6(0xd0)]+'\x20('+_0x4fa83a['complexity']+')',0x0,undefined,[_0x5d20e6(0xee)]);}}}_0x140044[_0x5d20e6(0xf4)]['write'](JSON[_0x5d20e6(0x106)](_0x17bac0)+'\x0a');}else _0x140044[_0x5d20e6(0xf4)]['write'](_0x15d249+'\x0a');}catch{_0x140044['stdin'][_0x5d20e6(0x110)](_0x15d249+'\x0a');}}),_0x1bd6b5['on'](_0x11976f(0x109),()=>{const _0x28509e=_0x11976f;try{_0x140044[_0x28509e(0xf4)][_0x28509e(0xf7)]();}catch{}});const _0x5b9944=readline[_0x11976f(0xd6)]({'input':_0x140044[_0x11976f(0xd1)],'terminal':![]});_0x5b9944['on'](_0x11976f(0xe9),_0x5b0861=>{const _0x49ac07=_0x11976f;try{const _0x4cb247=JSON[_0x49ac07(0xfe)](_0x5b0861);if(_0x4cb247&&_0x4cb247[_0x49ac07(0xe0)]===_0x49ac07(0x101)&&_0x4cb247['id']!==undefined&&_0x4cb247['result']&&Array['isArray'](_0x4cb247[_0x49ac07(0x10e)][_0x49ac07(0xe7)])){let _0x1e087a=![];for(const _0x4c3003 of _0x4cb247['result']['content']){if(_0x4c3003['type']===_0x49ac07(0xf5)&&typeof _0x4c3003['text']==='string'&&_0x4c3003[_0x49ac07(0xf5)][_0x49ac07(0x100)]()[_0x49ac07(0xfc)]>0x0){const _0x2bc16d=_0x4c3003['text'],_0x23036f=(0x0,filters_1[_0x49ac07(0xde)])(_0x49ac07(0xe1),_0x2bc16d,'',tracker_1['tracker']['getConfig']()[_0x49ac07(0xe6)]);tracker_1[_0x49ac07(0xcd)][_0x49ac07(0xdd)](_0x49ac07(0xf1)+_0x4cb247['id']+')',_0x2bc16d,_0x23036f,0x0),_0x4c3003[_0x49ac07(0xf5)]=_0x23036f,_0x1e087a=!![];}}_0x1e087a?process['stdout'][_0x49ac07(0x110)](JSON[_0x49ac07(0x106)](_0x4cb247)+'\x0a'):process[_0x49ac07(0xd1)][_0x49ac07(0x110)](_0x5b0861+'\x0a');}else process['stdout']['write'](_0x5b0861+'\x0a');}catch{process[_0x49ac07(0xd1)][_0x49ac07(0x110)](_0x5b0861+'\x0a');}}),_0x140044['on'](_0x11976f(0x109),_0x27f875=>{process['exit'](_0x27f875||0x0);}),_0x140044['on']('error',_0x172cb4=>{const _0x1e4b06=_0x11976f;console[_0x1e4b06(0xd7)](_0x1e4b06(0xfb)+_0x172cb4[_0x1e4b06(0xf8)]),process[_0x1e4b06(0xd5)](0x1);});}
|
package/package.json
CHANGED
package/proxy-conv.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
'use strict';const a0_0x3b9011=a0_0x5781;function a0_0x5781(_0xe5e63,_0x4e2a3d){_0xe5e63=_0xe5e63-0x174;const _0xc24495=a0_0xc244();let _0x57811a=_0xc24495[_0xe5e63];return _0x57811a;}(function(_0x1b5188,_0x2e1bc5){const _0x48b97b=a0_0x5781,_0x476012=_0x1b5188();while(!![]){try{const _0x6c7994=-parseInt(_0x48b97b(0x179))/0x1+parseInt(_0x48b97b(0x17e))/0x2*(parseInt(_0x48b97b(0x19b))/0x3)+-parseInt(_0x48b97b(0x176))/0x4*(-parseInt(_0x48b97b(0x197))/0x5)+-parseInt(_0x48b97b(0x192))/0x6*(parseInt(_0x48b97b(0x18c))/0x7)+-parseInt(_0x48b97b(0x17a))/0x8+-parseInt(_0x48b97b(0x185))/0x9+parseInt(_0x48b97b(0x181))/0xa;if(_0x6c7994===_0x2e1bc5)break;else _0x476012['push'](_0x476012['shift']());}catch(_0x656b8d){_0x476012['push'](_0x476012['shift']());}}}(a0_0xc244,0x3f6dd));Object[a0_0x3b9011(0x199)](exports,a0_0x3b9011(0x196),{'value':!![]}),exports[a0_0x3b9011(0x189)]=compressConversation;const ROLE_WEIGHT={'system':0x1,'user':0.8,'assistant':0.5,'tool':0.3};function estimateTokens(_0x508002){const _0x45960f=a0_0x3b9011;return Math[_0x45960f(0x190)](_0x508002[_0x45960f(0x184)]/0x4);}function blockText(_0x532bd9){const _0x206475=a0_0x3b9011;if(!_0x532bd9||typeof _0x532bd9!=='object')return'';if(_0x532bd9[_0x206475(0x193)]===_0x206475(0x186)&&typeof _0x532bd9[_0x206475(0x186)]===_0x206475(0x188))return _0x532bd9['text'];if(_0x532bd9[_0x206475(0x193)]===_0x206475(0x183)){if(typeof _0x532bd9[_0x206475(0x178)]===_0x206475(0x188))return _0x532bd9[_0x206475(0x178)];if(Array[_0x206475(0x187)](_0x532bd9['content']))return _0x532bd9[_0x206475(0x178)][_0x206475(0x195)](blockText)['filter'](Boolean)[_0x206475(0x180)]('\x0a');}return'';}function a0_0xc244(){const _0x2a3ade=['\x20chars\x20trimmed\x20by\x20TrimPrompt\x20...]','ceil','system','6NhTyRk','type','score','map','__esModule','2232335gYZPld','split','defineProperty','push','3FskofY','\x20lines\x20trimmed\x20by\x20TrimPrompt\x20...]\x0a','\x0a[...\x20','tokens','4HwHaJC','msg','content','459798vrnynl','2821728BZdjpU','forEach','filter','\x20chars\x20trimmed\x20...]','757312Mknllr','originalIndex','join','4634530GxANrT','\x20lines\x20trimmed\x20...]','tool_result','length','1793682SUIkBf','text','isArray','string','compressConversation','role','slice','118713omOPxg','reduce','indexOf'];a0_0xc244=function(){return _0x2a3ade;};return a0_0xc244();}function messageText(_0x3f178a){const _0x565a04=a0_0x3b9011;if(typeof _0x3f178a[_0x565a04(0x178)]===_0x565a04(0x188))return _0x3f178a[_0x565a04(0x178)];if(Array[_0x565a04(0x187)](_0x3f178a[_0x565a04(0x178)]))return _0x3f178a[_0x565a04(0x178)][_0x565a04(0x195)](blockText)[_0x565a04(0x17c)](Boolean)[_0x565a04(0x180)]('\x0a');return'';}function summarizeText(_0x373514){const _0x47dc74=a0_0x3b9011,_0x16417c=estimateTokens(_0x373514),_0x5af39f=_0x373514[_0x47dc74(0x198)]('\x0a');if(_0x16417c>0x7d0){if(_0x5af39f[_0x47dc74(0x184)]>0xa){const _0x45857c=_0x5af39f[_0x47dc74(0x18b)](0x0,0x5)[_0x47dc74(0x180)]('\x0a'),_0x5de910=_0x5af39f[_0x47dc74(0x18b)](-0x5)[_0x47dc74(0x180)]('\x0a');return _0x45857c+_0x47dc74(0x174)+(_0x5af39f['length']-0xa)+_0x47dc74(0x19c)+_0x5de910;}return _0x373514[_0x47dc74(0x18b)](0x0,0x7d0)+('\x0a[...\x20'+(_0x373514['length']-0x7d0)+_0x47dc74(0x18f));}if(_0x16417c>0x1f4){if(_0x5af39f[_0x47dc74(0x184)]>0xa)return _0x5af39f[_0x47dc74(0x18b)](0x0,0xa)['join']('\x0a')+(_0x47dc74(0x174)+(_0x5af39f[_0x47dc74(0x184)]-0xa)+_0x47dc74(0x182));return _0x373514[_0x47dc74(0x18b)](0x0,0x320)+(_0x47dc74(0x174)+(_0x373514[_0x47dc74(0x184)]-0x320)+_0x47dc74(0x17d));}return _0x373514;}function summarizeBlock(_0x390294){const _0x54c149=a0_0x3b9011;if(!_0x390294||typeof _0x390294!=='object')return _0x390294;if(_0x390294[_0x54c149(0x193)]===_0x54c149(0x186)&&typeof _0x390294['text']===_0x54c149(0x188))return{..._0x390294,'text':summarizeText(_0x390294[_0x54c149(0x186)])};if(_0x390294[_0x54c149(0x193)]===_0x54c149(0x183)){if(typeof _0x390294[_0x54c149(0x178)]===_0x54c149(0x188))return{..._0x390294,'content':summarizeText(_0x390294[_0x54c149(0x178)])};if(Array['isArray'](_0x390294[_0x54c149(0x178)])){const _0x4e4d7d=largestBlockIndex(_0x390294[_0x54c149(0x178)]);if(_0x4e4d7d>=0x0){const _0x295de4=_0x390294[_0x54c149(0x178)][_0x54c149(0x195)]((_0x2d9568,_0xeda2c4)=>_0xeda2c4===_0x4e4d7d?summarizeBlock(_0x2d9568):_0x2d9568);return{..._0x390294,'content':_0x295de4};}}}return _0x390294;}function largestBlockIndex(_0x16573d){const _0xf16cb0=a0_0x3b9011;let _0x5f0581=-0x1,_0x5d0294=-0x1;return _0x16573d[_0xf16cb0(0x17b)]((_0x3209fe,_0x4d4e2f)=>{const _0x25210a=_0xf16cb0,_0x1558ca=blockText(_0x3209fe)[_0x25210a(0x184)];_0x1558ca>_0x5d0294&&(_0x5d0294=_0x1558ca,_0x5f0581=_0x4d4e2f);}),_0x5d0294>0x0?_0x5f0581:-0x1;}function scoreMessage(_0x2fb575,_0x4ca464,_0x1bb7e4){const _0x3eb14d=a0_0x3b9011,_0x1f6e5e=ROLE_WEIGHT[_0x2fb575[_0x3eb14d(0x18a)]]||0.4,_0x1949ea=(_0x4ca464+0x1)/_0x1bb7e4,_0x4e5fff=messageText(_0x2fb575),_0x40b5c1=estimateTokens(_0x4e5fff),_0x1e7a62=_0x40b5c1>0x7d0?0.6:_0x40b5c1>0x1f4?0.8:0x1;return _0x1f6e5e*(0.3+0.7*_0x1949ea)*_0x1e7a62;}function summarizeMessage(_0x5ebd2f){const _0x579729=a0_0x3b9011,_0x49048b=estimateTokens(messageText(_0x5ebd2f));if(_0x49048b<=0x1f4)return _0x5ebd2f;if(typeof _0x5ebd2f[_0x579729(0x178)]===_0x579729(0x188))return{..._0x5ebd2f,'content':summarizeText(_0x5ebd2f[_0x579729(0x178)])};if(Array[_0x579729(0x187)](_0x5ebd2f['content'])){const _0x763d89=largestBlockIndex(_0x5ebd2f['content']);if(_0x763d89>=0x0){const _0x38a5af=_0x5ebd2f[_0x579729(0x178)][_0x579729(0x195)]((_0x304426,_0x507ead)=>_0x507ead===_0x763d89?summarizeBlock(_0x304426):_0x304426);return{..._0x5ebd2f,'content':_0x38a5af};}}return _0x5ebd2f;}function compressConversation(_0x5bcde8,_0x304c08){const _0x392d91=a0_0x3b9011,_0x4347b6={'messages':_0x5bcde8,'trimmedCount':0x0,'savedTokens':0x0};if(!_0x5bcde8||!Array[_0x392d91(0x187)](_0x5bcde8)||_0x5bcde8['length']<=0x6)return _0x4347b6;try{return _compressConversation(_0x5bcde8,_0x304c08);}catch{return _0x4347b6;}}function _compressConversation(_0x371bcb,_0x1df764){const _0x9ec340=a0_0x3b9011,_0x34a88c=_0x1df764||0x13880,_0x3fb227=0x4,_0x70f4d=_0x371bcb['filter'](_0x516c44=>_0x516c44[_0x9ec340(0x18a)]===_0x9ec340(0x191)),_0x4ae54f=_0x371bcb[_0x9ec340(0x17c)](_0x1065bf=>_0x1065bf[_0x9ec340(0x18a)]!=='system'),_0x5d07c7=_0x4ae54f[_0x9ec340(0x18b)](-_0x3fb227),_0x159421=_0x4ae54f[_0x9ec340(0x18b)](0x0,-_0x3fb227),_0x3f71c9=_0x159421['map']((_0x3071ab,_0xfdeb1f)=>({'msg':_0x3071ab,'score':scoreMessage(_0x3071ab,_0xfdeb1f,_0x159421[_0x9ec340(0x184)]),'tokens':estimateTokens(messageText(_0x3071ab))})),_0x4f4809=_0x3f71c9[_0x9ec340(0x18d)]((_0x13f6e7,_0x5a80e6)=>_0x13f6e7+_0x5a80e6['tokens'],0x0),_0x3b78db=_0x5d07c7['reduce']((_0x382d35,_0x2dbd84)=>_0x382d35+estimateTokens(messageText(_0x2dbd84)),0x0),_0x5e5ebc=_0x70f4d['reduce']((_0x323f57,_0x3b0631)=>_0x323f57+estimateTokens(messageText(_0x3b0631)),0x0),_0x5e6d25=_0x34a88c-_0x3b78db-_0x5e5ebc;if(_0x4f4809<=_0x5e6d25){let _0x5e71d3=0x0;const _0x44bdd5=_0x3f71c9[_0x9ec340(0x195)](_0x520c19=>{const _0x20bd4f=_0x9ec340;if(_0x520c19[_0x20bd4f(0x175)]>0x1f4){const _0x5f55fa=summarizeMessage(_0x520c19[_0x20bd4f(0x177)]),_0x30fa62=estimateTokens(messageText(_0x5f55fa));if(_0x30fa62<_0x520c19['tokens'])return _0x5e71d3+=_0x520c19[_0x20bd4f(0x175)]-_0x30fa62,_0x5f55fa;}return _0x520c19[_0x20bd4f(0x177)];});return{'messages':[..._0x70f4d,..._0x44bdd5,..._0x5d07c7],'trimmedCount':0x0,'savedTokens':_0x5e71d3};}_0x3f71c9['sort']((_0x15c85b,_0x324620)=>_0x324620['score']-_0x15c85b[_0x9ec340(0x194)]);let _0x3ce681=0x0,_0x16177c=0x0,_0x3ecb85=0x0;const _0x517b36=[];for(const _0x213d1a of _0x3f71c9){if(_0x3ce681+_0x213d1a['tokens']<=_0x5e6d25){if(_0x213d1a['tokens']>0x3e8){const _0x468fa4=summarizeMessage(_0x213d1a[_0x9ec340(0x177)]),_0x4e4561=estimateTokens(messageText(_0x468fa4));_0x3ecb85+=_0x213d1a[_0x9ec340(0x175)]-_0x4e4561,_0x3ce681+=_0x4e4561,_0x517b36[_0x9ec340(0x19a)]({'msg':_0x468fa4,'originalIndex':_0x159421[_0x9ec340(0x18e)](_0x213d1a[_0x9ec340(0x177)])});}else _0x3ce681+=_0x213d1a[_0x9ec340(0x175)],_0x517b36[_0x9ec340(0x19a)]({'msg':_0x213d1a[_0x9ec340(0x177)],'originalIndex':_0x159421[_0x9ec340(0x18e)](_0x213d1a[_0x9ec340(0x177)])});}else _0x16177c++,_0x3ecb85+=_0x213d1a[_0x9ec340(0x175)];}_0x517b36['sort']((_0x40374a,_0xbbe108)=>_0x40374a[_0x9ec340(0x17f)]-_0xbbe108[_0x9ec340(0x17f)]);const _0x470723=[..._0x70f4d,..._0x517b36[_0x9ec340(0x195)](_0x4f4d05=>_0x4f4d05[_0x9ec340(0x177)]),..._0x5d07c7];return{'messages':_0x470723,'trimmedCount':_0x16177c,'savedTokens':_0x3ecb85};}
|