tokencut-proxy 0.1.0__py3-none-any.whl
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.
- tokencut/__init__.py +0 -0
- tokencut/cli.py +127 -0
- tokencut/contracts.py +148 -0
- tokencut/gateway/__init__.py +0 -0
- tokencut/gateway/__main__.py +14 -0
- tokencut/gateway/adapters/__init__.py +1 -0
- tokencut/gateway/adapters/anthropic.py +119 -0
- tokencut/gateway/adapters/common.py +95 -0
- tokencut/gateway/adapters/gemini.py +107 -0
- tokencut/gateway/adapters/openai.py +82 -0
- tokencut/gateway/app.py +366 -0
- tokencut/gateway/brief.py +101 -0
- tokencut/gateway/ccr.py +83 -0
- tokencut/gateway/classify.py +41 -0
- tokencut/gateway/codeview.py +139 -0
- tokencut/gateway/history.py +433 -0
- tokencut/gateway/live.html +135 -0
- tokencut/gateway/media.py +825 -0
- tokencut/gateway/note.py +71 -0
- tokencut/gateway/prompt_router.py +214 -0
- tokencut/gateway/records.py +312 -0
- tokencut/gateway/routing.py +131 -0
- tokencut/gateway/session.py +76 -0
- tokencut/gateway/task_router.py +157 -0
- tokencut/gateway/textcut.py +91 -0
- tokencut/gateway/trimmer.py +256 -0
- tokencut/gateway/usage.py +120 -0
- tokencut/gateway/virtual.py +273 -0
- tokencut/graph/__init__.py +0 -0
- tokencut/graph/builder.py +307 -0
- tokencut/graph/modules.py +149 -0
- tokencut/graph/queries.py +106 -0
- tokencut/ingestion/__init__.py +0 -0
- tokencut/ingestion/base.py +18 -0
- tokencut/ingestion/parser.py +36 -0
- tokencut/ingestion/python_parser.py +275 -0
- tokencut/ingestion/walker.py +68 -0
- tokencut/launch.py +104 -0
- tokencut/litellm_proxy.py +134 -0
- tokencut/pdftool/__init__.py +9 -0
- tokencut/pdftool/__main__.py +115 -0
- tokencut/pdftool/reader.py +97 -0
- tokencut/repoindex/__init__.py +0 -0
- tokencut/repoindex/__main__.py +67 -0
- tokencut/repoindex/bm25.py +63 -0
- tokencut/repoindex/embed.py +93 -0
- tokencut/repoindex/index.py +455 -0
- tokencut/repoindex/mcp.py +145 -0
- tokencut/tokens.py +19 -0
- tokencut/trimming/__init__.py +0 -0
- tokencut/trimming/packing.py +317 -0
- tokencut/trimming/query.py +259 -0
- tokencut/trimming/render.py +65 -0
- tokencut/trimming/scoring.py +117 -0
- tokencut/trimming/variants.py +61 -0
- tokencut/userconfig.py +107 -0
- tokencut/wizard.py +94 -0
- tokencut_proxy-0.1.0.dist-info/METADATA +267 -0
- tokencut_proxy-0.1.0.dist-info/RECORD +62 -0
- tokencut_proxy-0.1.0.dist-info/WHEEL +5 -0
- tokencut_proxy-0.1.0.dist-info/entry_points.txt +2 -0
- tokencut_proxy-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
|
+
<title>TokenCut Live</title>
|
|
7
|
+
<style>
|
|
8
|
+
:root {
|
|
9
|
+
--bg: #f7f7f5; --card: #ffffff; --ink: #1d1d1b; --muted: #6b6b66; --line: #e4e4df;
|
|
10
|
+
--claude: #c96442; --gpt: #10a37f; --good: #2f7d32; --warn: #b26a00;
|
|
11
|
+
}
|
|
12
|
+
@media (prefers-color-scheme: dark) {
|
|
13
|
+
:root { --bg: #161615; --card: #1f1f1d; --ink: #ecece8; --muted: #9b9b94; --line: #2e2e2b; }
|
|
14
|
+
}
|
|
15
|
+
* { box-sizing: border-box; }
|
|
16
|
+
body { margin: 0; background: var(--bg); color: var(--ink);
|
|
17
|
+
font: 15px/1.45 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
18
|
+
main { max-width: 1080px; margin: 0 auto; padding: 24px 16px 48px; }
|
|
19
|
+
header { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px 16px; margin-bottom: 20px; }
|
|
20
|
+
h1 { font-size: 22px; margin: 0; }
|
|
21
|
+
.sub { color: var(--muted); font-size: 13px; }
|
|
22
|
+
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--good);
|
|
23
|
+
margin-right: 6px; vertical-align: middle; }
|
|
24
|
+
.dot.off { background: var(--warn); }
|
|
25
|
+
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
|
|
26
|
+
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }
|
|
27
|
+
.card h2 { margin: 0 0 2px; font-size: 15px; display: flex; align-items: center; gap: 8px; }
|
|
28
|
+
.swatch { width: 10px; height: 10px; border-radius: 3px; }
|
|
29
|
+
.plan { color: var(--muted); font-size: 12px; margin-bottom: 12px; }
|
|
30
|
+
.big { font-size: 30px; font-weight: 650; font-variant-numeric: tabular-nums; }
|
|
31
|
+
.row { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted);
|
|
32
|
+
font-variant-numeric: tabular-nums; padding: 2px 0; }
|
|
33
|
+
.row b { color: var(--ink); font-weight: 600; }
|
|
34
|
+
.bar { height: 6px; background: var(--line); border-radius: 3px; overflow: hidden; margin: 8px 0 10px; }
|
|
35
|
+
.bar span { display: block; height: 100%; background: var(--good); width: 0; transition: width .4s; }
|
|
36
|
+
h3 { font-size: 14px; margin: 28px 0 8px; }
|
|
37
|
+
.feed { background: var(--card); border: 1px solid var(--line); border-radius: 12px; overflow-x: auto; }
|
|
38
|
+
table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
|
|
39
|
+
th, td { text-align: left; padding: 7px 12px; border-bottom: 1px solid var(--line); white-space: nowrap; }
|
|
40
|
+
th { color: var(--muted); font-weight: 500; }
|
|
41
|
+
tr:last-child td { border-bottom: 0; }
|
|
42
|
+
.tag { display: inline-block; padding: 1px 8px; border-radius: 10px; color: #fff; font-size: 12px; }
|
|
43
|
+
.claude { background: var(--claude); } .gpt { background: var(--gpt); } .other { background: var(--muted); }
|
|
44
|
+
.saved { color: var(--good); font-weight: 600; }
|
|
45
|
+
.muted { color: var(--muted); }
|
|
46
|
+
.empty { padding: 20px; color: var(--muted); text-align: center; }
|
|
47
|
+
</style>
|
|
48
|
+
</head>
|
|
49
|
+
<body>
|
|
50
|
+
<main>
|
|
51
|
+
<header>
|
|
52
|
+
<h1>TokenCut Live</h1>
|
|
53
|
+
<span class="sub"><span id="dot" class="dot"></span><span id="status">connecting…</span></span>
|
|
54
|
+
</header>
|
|
55
|
+
|
|
56
|
+
<section class="cards" id="cards"></section>
|
|
57
|
+
|
|
58
|
+
<h3>Latest requests</h3>
|
|
59
|
+
<div class="feed">
|
|
60
|
+
<table>
|
|
61
|
+
<thead><tr><th>Time</th><th>Plan</th><th>Model</th><th>Tokens</th><th>Removed</th>
|
|
62
|
+
<th>Cache read</th><th>What was trimmed</th><th>Latency</th></tr></thead>
|
|
63
|
+
<tbody id="rows"><tr><td colspan="8" class="empty">Waiting for the agent's first request…</td></tr></tbody>
|
|
64
|
+
</table>
|
|
65
|
+
</div>
|
|
66
|
+
</main>
|
|
67
|
+
<script>
|
|
68
|
+
const ROUTES = {
|
|
69
|
+
claude: { name: "Claude", plan: "Claude Pro plan · via Anthropic", css: "claude", color: "var(--claude)" },
|
|
70
|
+
gpt: { name: "GPT / Codex", plan: "ChatGPT plan · via LiteLLM", css: "gpt", color: "var(--gpt)" },
|
|
71
|
+
};
|
|
72
|
+
const fmt = n => (n ?? 0).toLocaleString();
|
|
73
|
+
const pct = (a, b) => b ? Math.round(100 * a / b) : 0;
|
|
74
|
+
const esc = s => String(s ?? "").replace(/[&<>"]/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
|
|
75
|
+
|
|
76
|
+
function card(route, d) {
|
|
77
|
+
const r = ROUTES[route] || { name: route, plan: "", css: "other", color: "var(--muted)" };
|
|
78
|
+
const u = d.billed_usage || {};
|
|
79
|
+
const input = (u.input_tokens || 0) + (u.cache_read_tokens || 0) + (u.cache_write_tokens || 0);
|
|
80
|
+
const p = pct(d.tokens_saved, d.tokens);
|
|
81
|
+
return `<div class="card">
|
|
82
|
+
<h2><span class="swatch" style="background:${r.color}"></span>${esc(r.name)}</h2>
|
|
83
|
+
<div class="plan">${esc(r.plan)}</div>
|
|
84
|
+
<div class="big">${p}%</div>
|
|
85
|
+
<div class="muted" style="font-size:12px">of request tokens removed</div>
|
|
86
|
+
<div class="bar"><span style="width:${Math.min(p, 100)}%"></span></div>
|
|
87
|
+
<div class="row"><span>Requests</span><b>${fmt(d.requests)}</b></div>
|
|
88
|
+
<div class="row"><span>Tokens removed</span><b>${fmt(d.tokens_saved)} / ${fmt(d.tokens)}</b></div>
|
|
89
|
+
<div class="row"><span>Billed input</span><b>${fmt(input)}</b></div>
|
|
90
|
+
<div class="row"><span>Cache reads</span><b>${pct(u.cache_read_tokens, input)}%</b></div>
|
|
91
|
+
</div>`;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function row(r) {
|
|
95
|
+
const route = ROUTES[r.route] ? r.route : "other";
|
|
96
|
+
const label = ROUTES[r.route]?.name || r.route;
|
|
97
|
+
const trims = (r.trims || []).filter(t => t.before > t.after)
|
|
98
|
+
.map(t => `${esc(t.how)} ${fmt(t.before)}→${fmt(t.after)}`).join(", ");
|
|
99
|
+
const ev = r.cache_event ? ` <span class="muted">[${esc(r.cache_event)}]</span>` : "";
|
|
100
|
+
const time = (r.ts || "").slice(11, 19);
|
|
101
|
+
const u = r.usage || {};
|
|
102
|
+
return `<tr><td class="muted">${time}</td>
|
|
103
|
+
<td><span class="tag ${route}">${esc(label)}</span></td>
|
|
104
|
+
<td>${esc(r.model)}</td><td>${fmt(r.tokens)}</td>
|
|
105
|
+
<td class="${r.tokens_saved ? "saved" : "muted"}">${r.tokens_saved ? "−" + fmt(r.tokens_saved) : "0"}${r.applied || !r.tokens_saved ? "" : " (shadow)"}</td>
|
|
106
|
+
<td>${fmt(u.cache_read_tokens)}</td>
|
|
107
|
+
<td>${trims || '<span class="muted">—</span>'}${ev}</td>
|
|
108
|
+
<td class="muted">${r.latency_ms != null ? Math.round(r.latency_ms) + " ms" : ""}</td></tr>`;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
async function refresh() {
|
|
112
|
+
try {
|
|
113
|
+
const [stats, recent, health] = await Promise.all(
|
|
114
|
+
["stats", "recent", "health"].map(p => fetch(`/tokencut/${p}`).then(x => x.json())));
|
|
115
|
+
const routes = { claude: { requests: 0, tokens: 0, tokens_saved: 0, billed_usage: {} },
|
|
116
|
+
...(health.gpt_upstream ? { gpt: { requests: 0, tokens: 0, tokens_saved: 0, billed_usage: {} } } : {}),
|
|
117
|
+
...stats.by_route };
|
|
118
|
+
document.getElementById("cards").innerHTML =
|
|
119
|
+
Object.entries(routes).map(([k, v]) => card(k, v)).join("");
|
|
120
|
+
document.getElementById("rows").innerHTML = recent.length
|
|
121
|
+
? recent.map(row).join("")
|
|
122
|
+
: '<tr><td colspan="8" class="empty">Waiting for the agent\'s first request…</td></tr>';
|
|
123
|
+
document.getElementById("dot").className = "dot";
|
|
124
|
+
document.getElementById("status").textContent =
|
|
125
|
+
`mode ${health.mode} · tier ${health.tier} · GPT route ${health.gpt_upstream ? "on" : "off"}`;
|
|
126
|
+
} catch (e) {
|
|
127
|
+
document.getElementById("dot").className = "dot off";
|
|
128
|
+
document.getElementById("status").textContent = "gateway not reachable";
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
refresh();
|
|
132
|
+
setInterval(refresh, 2000);
|
|
133
|
+
</script>
|
|
134
|
+
</body>
|
|
135
|
+
</html>
|