"use client"; // Compression Hub — the single place to understand and control compression. // // IMPORTANT (hydration): this component deliberately does NOT use `useTranslations`. // The previous combos redesign failed to hydrate on the production build; the only // structural difference from the engine pages (which hydrate fine) was a page-level // `useTranslations("contextCombos")`. To stay on the proven-good path, strings here // remain literal English text, exactly like `EngineConfigPage`. // // Phase 2: this Hub is now a thin overview. The master toggle, mode selector, and the // reorderable per-layer pipeline live in the panel at /dashboard/context/settings and // in the named-combo editor. Here we expose a single active-profile selector // (Default-from-panel | a named combo) + a read-only preview. import { useCallback, useEffect, useState } from "react"; // ── Types ───────────────────────────────────────────────────────────────────── type CompressionMode = "off" | "lite" | "standard" | "aggressive" | "ultra" | "rtk" | "stacked"; interface CompressionSettings { enabled: boolean; defaultMode: CompressionMode; activeComboId?: string | null; contextEditing?: { enabled: boolean }; [key: string]: unknown; } interface NamedCombo { id: string; name: string; pipeline: { engine: string; intensity?: string }[]; } // ── Sub-components ────────────────────────────────────────────────────────────── function Toggle({ checked, onChange, ariaLabel, }: { checked: boolean; onChange: () => void; ariaLabel: string; }) { return ( ); } // ── Main component ────────────────────────────────────────────────────────────── export default function CompressionHub() { const [settings, setSettings] = useState(null); const [combos, setCombos] = useState([]); const [loading, setLoading] = useState(true); const [explainerOpen, setExplainerOpen] = useState(false); const [error, setError] = useState(null); // ── Initial load (parallel) ────────────────────────────────────────────────── useEffect(() => { let cancelled = false; async function load() { setLoading(true); const asJson = (r: Response) => (r.ok ? r.json() : null); const [settingsData, combosData] = await Promise.all([ fetch("/api/settings/compression") .then(asJson) .catch(() => null), fetch("/api/context/combos") .then(asJson) .catch(() => null), ]); if (cancelled) return; if (settingsData) { setSettings(settingsData as CompressionSettings); } else { setSettings({ enabled: false, defaultMode: "off", contextEditing: { enabled: false } }); } if (Array.isArray(combosData?.combos)) { setCombos(combosData.combos as NamedCombo[]); } setLoading(false); } void load(); return () => { cancelled = true; }; }, []); // ── Settings mutations ─────────────────────────────────────────────────────── const saveSettings = useCallback( async (patch: Partial) => { if (!settings) return; const next = { ...settings, ...patch }; setSettings(next); setError(null); try { const res = await fetch("/api/settings/compression", { method: "PUT", headers: { "Content-Type": "application/json" }, body: JSON.stringify(next), }); if (!res.ok) { setSettings(settings); // revert setError("Failed to save settings."); } } catch { setSettings(settings); setError("Failed to save settings."); } }, [settings] ); // ── Derived state ───────────────────────────────────────────────────────────── if (loading) { return (
Loading...
); } const activeCombo = combos.find((c) => c.id === settings?.activeComboId) ?? null; const activePipelineText = activeCombo ? activeCombo.pipeline.map((s) => s.engine).join(" → ") : ""; return (
{/* ── Header ── */}

Compression Hub

Pick which compression profile runs globally.

{error && (

{error}

)} {/* ── Explainer ── */} {explainerOpen && (

Compression reduces tokens and cost by rewriting history before it is sent to the provider while preserving meaning.

  1. Active profile: chooses which compression profile runs globally — the panel-derived Default or one of your saved named combos.
  2. Default (from panel): derived from the master switch and per-engine toggles you configure in Compression Settings.
  3. Named combos: saved pipelines you build in the named-combo editor. Selecting one makes it the active profile for every request.
  4. Preview: shows which engines the active profile runs, in order.
)} {/* ── Active profile ── */}

Pick which compression profile runs globally — the panel-derived Default or a saved named combo.

{activeCombo ? ( Runs: {activePipelineText} ) : ( Default — configured in{" "} Compression Settings . )}
{/* ── Compressão delegada ao provedor ── */}

Compressão delegada ao provedor

Context Editing (Claude)

Deixa o próprio provedor limpar blocos antigos de tool-use no servidor, sem reescrever a mensagem.

saveSettings({ contextEditing: { enabled: !settings?.contextEditing?.enabled } }) } ariaLabel="Context Editing" />
info Hoje disponível apenas para Claude (Anthropic). É um modo delegado: o próprio provedor limpa blocos antigos de tool-use no servidor — não reescrevemos a mensagem. Não afeta outros provedores.
); }