@sliday/tamp 0.4.5 → 0.4.6
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/README.md +1 -1
- package/compress.js +1 -1
- package/index.js +20 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Tamp
|
|
2
2
|
|
|
3
|
-
**Token compression proxy for coding agents.** 52.6% fewer
|
|
3
|
+
**Token compression proxy for coding agents.** 52.6% fewer tokens, zero code changes. Works with Claude Code, Aider, Cursor, Cline, Windsurf, 🦞 [OpenClaw](https://openclaw.app), and any OpenAI-compatible agent.
|
|
4
4
|
|
|
5
5
|
```
|
|
6
6
|
npx @sliday/tamp
|
package/compress.js
CHANGED
|
@@ -269,7 +269,7 @@ async function compressWithLLMLingua(text, config) {
|
|
|
269
269
|
const res = await fetch(config.llmLinguaUrl + '/compress', {
|
|
270
270
|
method: 'POST',
|
|
271
271
|
headers: { 'Content-Type': 'application/json' },
|
|
272
|
-
body: JSON.stringify({ text, rate: 0.
|
|
272
|
+
body: JSON.stringify({ text, rate: config.llmLinguaRate || 0.7 }),
|
|
273
273
|
signal: controller.signal,
|
|
274
274
|
})
|
|
275
275
|
if (!res.ok) return null
|
package/index.js
CHANGED
|
@@ -162,18 +162,27 @@ return http.createServer(async (req, res) => {
|
|
|
162
162
|
const encoding = (req.headers['content-encoding'] || '').toLowerCase()
|
|
163
163
|
let textBody
|
|
164
164
|
let decompressed = false
|
|
165
|
+
|
|
166
|
+
// Safety limit: decompressed body must not exceed 5× maxBody
|
|
167
|
+
// Prevents compression bomb DoS (small gzip → huge expansion)
|
|
168
|
+
const MAX_DECOMPRESSED = config.maxBody * 5
|
|
169
|
+
|
|
165
170
|
try {
|
|
166
171
|
if (encoding === 'gzip') {
|
|
167
|
-
textBody = zlib.gunzipSync(rawBody)
|
|
172
|
+
textBody = zlib.gunzipSync(rawBody, { maxOutputLength: MAX_DECOMPRESSED })
|
|
168
173
|
decompressed = true
|
|
169
174
|
} else if (encoding === 'deflate') {
|
|
170
|
-
textBody = zlib.inflateSync(rawBody)
|
|
175
|
+
textBody = zlib.inflateSync(rawBody, { maxOutputLength: MAX_DECOMPRESSED })
|
|
171
176
|
decompressed = true
|
|
172
177
|
} else if (encoding === 'br') {
|
|
173
|
-
textBody = zlib.brotliDecompressSync(rawBody)
|
|
178
|
+
textBody = zlib.brotliDecompressSync(rawBody, { maxOutputLength: MAX_DECOMPRESSED })
|
|
174
179
|
decompressed = true
|
|
175
180
|
} else if (encoding === 'zstd') {
|
|
176
|
-
|
|
181
|
+
const decompressedBytes = fzstd.decompress(new Uint8Array(rawBody))
|
|
182
|
+
if (decompressedBytes.length > MAX_DECOMPRESSED) {
|
|
183
|
+
throw new Error('zstd decompression exceeded size limit')
|
|
184
|
+
}
|
|
185
|
+
textBody = Buffer.from(decompressedBytes)
|
|
177
186
|
decompressed = true
|
|
178
187
|
} else if (encoding && encoding !== 'identity') {
|
|
179
188
|
// Unknown encoding — can't decompress, passthrough as-is
|
|
@@ -190,6 +199,13 @@ return http.createServer(async (req, res) => {
|
|
|
190
199
|
return
|
|
191
200
|
}
|
|
192
201
|
|
|
202
|
+
// Double-check decompressed size
|
|
203
|
+
if (textBody.length > MAX_DECOMPRESSED) {
|
|
204
|
+
log('[tamp] passthrough (decompressed body too large)')
|
|
205
|
+
forwardRequest(req.method, upstreamUrl, headers, rawBody, res)
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
|
|
193
209
|
try {
|
|
194
210
|
const parsed = JSON.parse(textBody.toString('utf-8'))
|
|
195
211
|
|
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.6",
|
|
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",
|