Feature : RTK compress

This commit is contained in:
decolua
2026-04-22 15:36:51 +07:00
parent e1a219dba6
commit 8de9aae90c
26 changed files with 1612 additions and 0 deletions
@@ -25,6 +25,7 @@ export default function APIPageClient({ machineId }) {
const [requireLogin, setRequireLogin] = useState(true);
const [hasPassword, setHasPassword] = useState(true);
const [tunnelDashboardAccess, setTunnelDashboardAccess] = useState(false);
const [rtkEnabled, setRtkEnabledState] = useState(false);
// Cloudflare Tunnel state
const [tunnelChecking, setTunnelChecking] = useState(true);
@@ -80,6 +81,7 @@ export default function APIPageClient({ machineId }) {
setRequireLogin(data.requireLogin !== false);
setHasPassword(data.hasPassword || false);
setTunnelDashboardAccess(data.tunnelDashboardAccess || false);
setRtkEnabledState(data.rtkEnabled || false);
}
if (statusRes.ok) {
const data = await statusRes.json();
@@ -167,6 +169,19 @@ export default function APIPageClient({ machineId }) {
}
};
const handleRtkEnabled = async (value) => {
try {
const res = await fetch("/api/settings", {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ rtkEnabled: value }),
});
if (res.ok) setRtkEnabledState(value);
} catch (error) {
console.log("Error updating rtkEnabled:", error);
}
};
const fetchData = async () => {
try {
const keysRes = await fetch("/api/keys");
@@ -798,6 +813,42 @@ export default function APIPageClient({ machineId }) {
)}
</Card>
{/* Token Saver (RTK) */}
<Card id="rtk">
<div className="flex items-center justify-between mb-2">
<div className="flex items-center gap-2">
<h2 className="text-lg font-semibold">Token Saver</h2>
<span className="px-2 py-0.5 text-xs font-medium rounded-full bg-amber-500/15 text-amber-600 dark:text-amber-400 border border-amber-500/30">
Experimental
</span>
</div>
</div>
<div className="flex items-center justify-between pt-2">
<div className="pr-4">
<p className="font-medium">Compress tool output</p>
<p className="text-sm text-text-muted">
Auto-compress git diff / status / grep / find / ls / tree / logs in <code>tool_result</code> before sending to LLM. Check server console for <code>[RTK] saved ...</code> log.
</p>
<p className="text-xs text-text-muted mt-1">
Inspired by{" "}
<a
href="https://github.com/rtk-ai/rtk"
target="_blank"
rel="noopener noreferrer"
className="underline hover:text-primary"
>
RTK (Rust Token Killer)
</a>
{" "} ported to JavaScript. This feature is still under testing; disable it if you notice unexpected results.
</p>
</div>
<Toggle
checked={rtkEnabled}
onChange={() => handleRtkEnabled(!rtkEnabled)}
/>
</div>
</Card>
{/* API Keys */}
<Card id="require-api-key">
<div className="flex items-center justify-between mb-4">