@sliday/tamp 0.2.7 → 0.2.9
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/config.js +1 -0
- package/index.js +2 -2
- package/package.json +1 -1
- package/stats.js +10 -5
package/config.js
CHANGED
package/index.js
CHANGED
|
@@ -105,10 +105,10 @@ function pipeRequest(req, res, upstreamUrl, prefixChunks) {
|
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
return http.createServer(async (req, res) => {
|
|
108
|
-
if (config.log) console.error(`[tamp] ${req.method} ${req.url}`)
|
|
109
108
|
const provider = detectProvider(req.method, req.url)
|
|
110
109
|
|
|
111
110
|
if (!provider) {
|
|
111
|
+
if (config.log) console.error(`[tamp] ${req.method} ${req.url}`)
|
|
112
112
|
const upstreamUrl = new URL(req.url, config.upstream)
|
|
113
113
|
return pipeRequest(req, res, upstreamUrl)
|
|
114
114
|
}
|
|
@@ -181,7 +181,7 @@ return http.createServer(async (req, res) => {
|
|
|
181
181
|
|
|
182
182
|
if (config.log) {
|
|
183
183
|
session.record(stats)
|
|
184
|
-
console.error(formatRequestLog(stats, session, provider.name, req.url, textBody.length))
|
|
184
|
+
console.error(formatRequestLog(stats, session, provider.name, req.url, textBody.length, config.tokenCost))
|
|
185
185
|
}
|
|
186
186
|
} catch (err) {
|
|
187
187
|
if (config.log) console.error(`[tamp] passthrough (parse error): ${err.message}`)
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"providers.js",
|
|
10
10
|
"stats.js"
|
|
11
11
|
],
|
|
12
|
-
"version": "0.2.
|
|
12
|
+
"version": "0.2.9",
|
|
13
13
|
"description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 33.9% fewer input tokens.",
|
|
14
14
|
"type": "module",
|
|
15
15
|
"main": "index.js",
|
package/stats.js
CHANGED
|
@@ -9,20 +9,21 @@ const c = {
|
|
|
9
9
|
red: '\x1b[31m',
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export function formatRequestLog(stats, session, providerName, url, bodySize) {
|
|
12
|
+
export function formatRequestLog(stats, session, providerName, url, bodySize, tokenCost) {
|
|
13
13
|
const compressed = stats.filter(s => s.method)
|
|
14
14
|
const label = providerName || 'anthropic'
|
|
15
15
|
const path = url || '/v1/messages'
|
|
16
16
|
const sizeInfo = bodySize ? ` ${c.dim}${fmtSize(bodySize)}${c.reset}` : ''
|
|
17
17
|
|
|
18
18
|
if (!compressed.length && !stats.length) {
|
|
19
|
-
return `[tamp] ${c.cyan}${label}${c.reset} ${path}${sizeInfo} ${c.dim}—
|
|
19
|
+
return `[tamp] ${c.cyan}${label}${c.reset} ${path}${sizeInfo} ${c.dim}— passthrough${c.reset}`
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
if (!compressed.length) {
|
|
23
23
|
const skipCount = stats.filter(s => s.skipped).length
|
|
24
|
+
const n = stats.length
|
|
24
25
|
const reason = skipCount ? `${skipCount} skipped` : 'nothing to compress'
|
|
25
|
-
return `[tamp] ${c.cyan}${label}${c.reset} ${path}${sizeInfo} ${c.dim}— ${
|
|
26
|
+
return `[tamp] ${c.cyan}${label}${c.reset} ${path}${sizeInfo} ${c.dim}— ${n} block${n !== 1 ? 's' : ''}, ${reason}${c.reset}`
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
const totalOrig = compressed.reduce((a, s) => a + s.originalLen, 0)
|
|
@@ -34,7 +35,8 @@ export function formatRequestLog(stats, session, providerName, url, bodySize) {
|
|
|
34
35
|
const tokSaved = totalOrigTok - totalCompTok
|
|
35
36
|
|
|
36
37
|
const lines = []
|
|
37
|
-
|
|
38
|
+
const n = compressed.length
|
|
39
|
+
lines.push(`[tamp] ${c.cyan}${label}${c.reset} ${path}${sizeInfo} ${c.green}— ${n} block${n !== 1 ? 's' : ''} compressed, -${pct}%${c.reset}`)
|
|
38
40
|
|
|
39
41
|
for (const s of compressed) {
|
|
40
42
|
const sPct = (((s.originalLen - s.compressedLen) / s.originalLen) * 100).toFixed(1)
|
|
@@ -49,7 +51,10 @@ export function formatRequestLog(stats, session, providerName, url, bodySize) {
|
|
|
49
51
|
if (session) {
|
|
50
52
|
const t = session.getTotals()
|
|
51
53
|
const sessionPct = t.totalOriginal > 0 ? (((t.totalSaved) / t.totalOriginal) * 100).toFixed(1) : '0.0'
|
|
52
|
-
|
|
54
|
+
const costPerM = tokenCost || 3
|
|
55
|
+
const dollarsSaved = (t.totalTokensSaved / 1_000_000) * costPerM
|
|
56
|
+
const moneyInfo = t.totalTokensSaved > 0 ? ` ${c.green}$${dollarsSaved.toFixed(4)} saved${c.reset} ${c.dim}@ $${costPerM}/Mtok${c.reset}` : ''
|
|
57
|
+
lines.push(`[tamp] ${c.magenta}session${c.reset} ${fmtSize(t.totalSaved)} chars, ${t.totalTokensSaved} tokens saved across ${t.compressionCount} blocks ${c.dim}(${sessionPct}% avg)${c.reset}${moneyInfo}`)
|
|
53
58
|
}
|
|
54
59
|
|
|
55
60
|
return lines.join('\n')
|