@sliday/tamp 0.4.3 → 0.4.4
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/compress.js +3 -2
- package/index.js +47 -2
- package/package.json +1 -1
- package/stats.js +2 -1
package/compress.js
CHANGED
|
@@ -195,9 +195,9 @@ async function textpressCompress(text, config) {
|
|
|
195
195
|
|
|
196
196
|
// --- Core compression ---
|
|
197
197
|
export function compressText(text, config) {
|
|
198
|
-
if (text.length < config.minSize) return null
|
|
198
|
+
if (text.length < config.minSize) { if (config.log !== false) process.stderr.write(`[tamp] skip: too small (${text.length} < ${config.minSize})\n`); return null }
|
|
199
199
|
const cls = classifyContent(text)
|
|
200
|
-
if (cls === 'toon') return null
|
|
200
|
+
if (cls === 'toon') { if (config.log !== false) process.stderr.write(`[tamp] skip: classified as toon (first 80: ${text.slice(0, 80).replace(/\n/g, '\\n')})\n`); return null }
|
|
201
201
|
|
|
202
202
|
if (cls === 'text') {
|
|
203
203
|
let processed = text
|
|
@@ -220,6 +220,7 @@ export function compressText(text, config) {
|
|
|
220
220
|
if (config.stages.includes('textpress')) {
|
|
221
221
|
return { async: true, asyncMethod: 'textpress', text: processed, cls }
|
|
222
222
|
}
|
|
223
|
+
if (config.log !== false) process.stderr.write(`[tamp] skip: text not compressible (${config.stages.includes('llmlingua') && !config.llmLinguaUrl ? 'no llmlingua sidecar' : 'whitespace savings < 10%'})\n`)
|
|
223
224
|
return null
|
|
224
225
|
}
|
|
225
226
|
|
package/index.js
CHANGED
|
@@ -88,10 +88,29 @@ function pipeRequest(req, res, upstreamUrl, prefixChunks) {
|
|
|
88
88
|
|
|
89
89
|
return http.createServer(async (req, res) => {
|
|
90
90
|
// Health check endpoint
|
|
91
|
-
if (req.url === '/health' && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
91
|
+
if ((req.url === '/health' || req.url === '/health?text') && (req.method === 'GET' || req.method === 'HEAD')) {
|
|
92
92
|
const totals = session.getTotals()
|
|
93
|
+
if (req.url === '/health?text') {
|
|
94
|
+
const ratio = totals.totalOriginal > 0 ? (totals.totalSaved * 100 / totals.totalOriginal).toFixed(1) + '%' : 'n/a'
|
|
95
|
+
const sidecarStatus = config.stages.includes('llmlingua') ? (sidecarAvailable ? 'ok' : 'not running') : 'n/a'
|
|
96
|
+
const lines = [`Tamp v${config.version} | ${config.stages.length} stages active | sidecar: ${sidecarStatus}`]
|
|
97
|
+
if (totals.requestCount === 0) {
|
|
98
|
+
lines.push('No requests yet this session')
|
|
99
|
+
} else {
|
|
100
|
+
lines.push(`Requests: ${totals.requestCount} | Blocks: ${totals.compressionCount}`)
|
|
101
|
+
lines.push(`Tokens saved: ${totals.totalTokensSaved} | Chars: ${totals.totalSaved}/${totals.totalOriginal} (${ratio})`)
|
|
102
|
+
if (totals.totalTokensSaved > 0) {
|
|
103
|
+
const son = (totals.totalTokensSaved * 3 / 1e6).toFixed(4)
|
|
104
|
+
const opus = (totals.totalTokensSaved * 15 / 1e6).toFixed(4)
|
|
105
|
+
lines.push(`Est. savings: $${son} (Sonnet $3/Mtok) | $${opus} (Opus $15/Mtok)`)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const body = lines.join('\n') + '\n'
|
|
109
|
+
res.writeHead(200, { 'Content-Type': 'text/plain', 'Content-Length': Buffer.byteLength(body) })
|
|
110
|
+
return res.end(req.method === 'HEAD' ? undefined : body)
|
|
111
|
+
}
|
|
93
112
|
const body = JSON.stringify({
|
|
94
|
-
status: 'ok', version: config.version, stages: config.stages,
|
|
113
|
+
status: 'ok', version: config.version, stages: config.stages, sidecar: sidecarAvailable,
|
|
95
114
|
session: {
|
|
96
115
|
requests: totals.requestCount,
|
|
97
116
|
tokensSaved: totals.totalTokensSaved,
|
|
@@ -217,6 +236,28 @@ function createRequestLogger(config) {
|
|
|
217
236
|
}
|
|
218
237
|
}
|
|
219
238
|
|
|
239
|
+
const SIDECAR_PORT = 8788
|
|
240
|
+
const SIDECAR_URL = `http://localhost:${SIDECAR_PORT}`
|
|
241
|
+
|
|
242
|
+
let sidecarAvailable = false
|
|
243
|
+
|
|
244
|
+
function probeSidecar(config) {
|
|
245
|
+
const req = http.get(`${SIDECAR_URL}/health`, { timeout: 2000 }, (res) => {
|
|
246
|
+
if (res.statusCode === 200) {
|
|
247
|
+
sidecarAvailable = true
|
|
248
|
+
if (!config.llmLinguaUrl) config.llmLinguaUrl = SIDECAR_URL
|
|
249
|
+
console.error(`[tamp] llmlingua sidecar: ok (${config.llmLinguaUrl})`)
|
|
250
|
+
}
|
|
251
|
+
res.resume()
|
|
252
|
+
})
|
|
253
|
+
req.on('error', () => {
|
|
254
|
+
sidecarAvailable = false
|
|
255
|
+
console.error('[tamp] \u26a0 llmlingua stage enabled but sidecar not running \u2014 text blocks won\u2019t compress')
|
|
256
|
+
console.error('[tamp] start with: uv run --with fastapi --with uvicorn --with llmlingua --with mlx uvicorn server:app --host 0.0.0.0 --port 8788 --app-dir sidecar')
|
|
257
|
+
})
|
|
258
|
+
req.on('timeout', () => { req.destroy() })
|
|
259
|
+
}
|
|
260
|
+
|
|
220
261
|
const isMain = !process.argv[1]?.includes('node_modules') && process.argv[1] === new URL(import.meta.url).pathname
|
|
221
262
|
|
|
222
263
|
if (isMain) {
|
|
@@ -225,5 +266,9 @@ if (isMain) {
|
|
|
225
266
|
console.error(`[tamp] proxy listening on http://localhost:${config.port}`)
|
|
226
267
|
console.error(`[tamp] upstream: ${config.upstream}`)
|
|
227
268
|
console.error(`[tamp] stages: ${config.stages.join(', ')}`)
|
|
269
|
+
|
|
270
|
+
if (config.stages.includes('llmlingua')) {
|
|
271
|
+
probeSidecar(config)
|
|
272
|
+
}
|
|
228
273
|
})
|
|
229
274
|
}
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"providers.js",
|
|
11
11
|
"stats.js"
|
|
12
12
|
],
|
|
13
|
-
"version": "0.4.
|
|
13
|
+
"version": "0.4.4",
|
|
14
14
|
"description": "Token compression proxy for coding agents. Works with Claude Code, Aider, Cursor, Cline, Windsurf. 52.6% fewer input tokens.",
|
|
15
15
|
"type": "module",
|
|
16
16
|
"main": "index.js",
|
package/stats.js
CHANGED
|
@@ -22,7 +22,8 @@ export function formatRequestLog(stats, session, providerName, url, bodySize, to
|
|
|
22
22
|
if (!compressed.length) {
|
|
23
23
|
const skipCount = stats.filter(s => s.skipped).length
|
|
24
24
|
const n = stats.length
|
|
25
|
-
const
|
|
25
|
+
const reasons = [...new Set(stats.filter(s => s.skipped).map(s => s.skipped))].join(', ')
|
|
26
|
+
const reason = skipCount ? `${skipCount} skipped (${reasons})` : 'nothing to compress'
|
|
26
27
|
return `[tamp] ${c.cyan}${label}${c.reset} ${path}${sizeInfo} ${c.dim}— ${n} block${n !== 1 ? 's' : ''}, ${reason}${c.reset}`
|
|
27
28
|
}
|
|
28
29
|
|