@opencompress/openclaw 3.0.0 → 3.0.1
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 +172 -66
- package/dist/index.d.ts +3 -1
- package/dist/index.js +118 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,108 +1,214 @@
|
|
|
1
|
-
|
|
1
|
+
<p align="center">
|
|
2
|
+
<br />
|
|
3
|
+
<br />
|
|
4
|
+
<strong><code>🗜️ OpenCompress</code></strong>
|
|
5
|
+
<br />
|
|
6
|
+
<em>for OpenClaw</em>
|
|
7
|
+
<br />
|
|
8
|
+
<br />
|
|
9
|
+
</p>
|
|
2
10
|
|
|
3
|
-
|
|
11
|
+
<h3 align="center">Your keys. Your models. Fewer tokens. Better quality.</h3>
|
|
4
12
|
|
|
5
|
-
|
|
13
|
+
<br />
|
|
6
14
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
15
|
+
<p align="center">
|
|
16
|
+
<a href="https://www.npmjs.com/package/@opencompress/openclaw"><img src="https://img.shields.io/npm/v/@opencompress/openclaw?style=flat-square&color=000&label=npm" alt="npm" /></a>
|
|
17
|
+
|
|
18
|
+
<a href="https://github.com/open-compress/opencompress-openclaw"><img src="https://img.shields.io/github/stars/open-compress/opencompress-openclaw?style=flat-square&color=000&label=stars" alt="stars" /></a>
|
|
19
|
+
|
|
20
|
+
<a href="https://github.com/open-compress/opencompress-openclaw/blob/main/LICENSE"><img src="https://img.shields.io/badge/license-MIT-000?style=flat-square" alt="license" /></a>
|
|
21
|
+
|
|
22
|
+
<a href="https://openclaw.ai"><img src="https://img.shields.io/badge/OpenClaw-plugin-000?style=flat-square" alt="OpenClaw" /></a>
|
|
23
|
+
</p>
|
|
10
24
|
|
|
11
|
-
|
|
25
|
+
<br />
|
|
12
26
|
|
|
13
|
-
|
|
14
|
-
- **62%** latency improvement
|
|
15
|
-
- **96%** quality preservation (SQuALITY benchmark)
|
|
27
|
+
---
|
|
16
28
|
|
|
17
|
-
|
|
29
|
+
<p align="center">
|
|
30
|
+
OpenCompress is an <a href="https://openclaw.ai">OpenClaw</a> plugin that optimizes LLM input and output using a state-of-the-art multi-stage compression pipeline. It reduces token usage and improves response quality, automatically, on every call. Works with any provider you already use: Anthropic, OpenAI, Google, OpenRouter, and any OpenAI-compatible API.
|
|
31
|
+
</p>
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
<br />
|
|
36
|
+
|
|
37
|
+
We don't sell tokens. We don't resell API access.
|
|
38
|
+
|
|
39
|
+
You use your own keys, your own models, your own account. Billed directly by Anthropic, OpenAI, or whoever you choose. We compress the traffic so you get charged less and your agent thinks clearer.
|
|
40
|
+
|
|
41
|
+
Compression doesn't just save money. It removes the noise. Leaner prompts mean the model focuses on what matters. Shorter context, better answers, better code.
|
|
42
|
+
|
|
43
|
+
No vendor lock-in. Uninstall anytime. Everything goes back to exactly how it was.
|
|
44
|
+
|
|
45
|
+
<br />
|
|
46
|
+
|
|
47
|
+
---
|
|
48
|
+
|
|
49
|
+
<br />
|
|
50
|
+
|
|
51
|
+
### How it works
|
|
18
52
|
|
|
19
|
-
```bash
|
|
20
|
-
openclaw plugins install @opencompress/opencompress
|
|
21
53
|
```
|
|
54
|
+
┌──────────────────────────────┐
|
|
55
|
+
│ Your OpenClaw Agent │
|
|
56
|
+
│ │
|
|
57
|
+
│ model: opencompress/auto │
|
|
58
|
+
└──────────────┬───────────────┘
|
|
59
|
+
│
|
|
60
|
+
▼
|
|
61
|
+
┌──────────────────────────────┐
|
|
62
|
+
│ Local Proxy (:8401) │
|
|
63
|
+
│ │
|
|
64
|
+
│ reads your provider key │
|
|
65
|
+
│ from OpenClaw config │
|
|
66
|
+
└──────────────┬───────────────┘
|
|
67
|
+
│
|
|
68
|
+
▼
|
|
69
|
+
┌──────────────────────────────┐
|
|
70
|
+
│ opencompress.ai │
|
|
71
|
+
│ │
|
|
72
|
+
│ compress → forward │
|
|
73
|
+
│ your key in header │
|
|
74
|
+
│ never stored │
|
|
75
|
+
└──────────────┬───────────────┘
|
|
76
|
+
│
|
|
77
|
+
▼
|
|
78
|
+
┌──────────────────────────────┐
|
|
79
|
+
│ Your LLM Provider │
|
|
80
|
+
│ (Anthropic / OpenAI) │
|
|
81
|
+
│ │
|
|
82
|
+
│ sees fewer tokens │
|
|
83
|
+
│ charges you less │
|
|
84
|
+
└──────────────────────────────┘
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
<br />
|
|
22
88
|
|
|
23
|
-
|
|
89
|
+
---
|
|
24
90
|
|
|
25
|
-
|
|
91
|
+
<br />
|
|
26
92
|
|
|
27
|
-
|
|
93
|
+
### Install
|
|
28
94
|
|
|
29
95
|
```bash
|
|
96
|
+
openclaw plugins install @opencompress/openclaw
|
|
30
97
|
openclaw onboard opencompress
|
|
98
|
+
openclaw gateway restart
|
|
31
99
|
```
|
|
32
100
|
|
|
33
|
-
|
|
101
|
+
Select **`opencompress/auto`** as your model. Done.
|
|
34
102
|
|
|
35
|
-
|
|
36
|
-
|---|---|
|
|
37
|
-
| `sk-proj-` or `sk-` | OpenAI |
|
|
38
|
-
| `sk-ant-` | Anthropic |
|
|
39
|
-
| `sk-or-` | OpenRouter |
|
|
40
|
-
| `AIza...` | Google AI |
|
|
103
|
+
<br />
|
|
41
104
|
|
|
42
|
-
|
|
105
|
+
### Models
|
|
43
106
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
### 2. Use it
|
|
47
|
-
|
|
48
|
-
Switch to the OpenCompress provider:
|
|
107
|
+
Every provider you already have gets a compressed mirror:
|
|
49
108
|
|
|
50
109
|
```
|
|
51
|
-
/
|
|
110
|
+
opencompress/auto → your default, compressed
|
|
111
|
+
opencompress/anthropic/claude-sonnet-4 → Claude Sonnet, compressed
|
|
112
|
+
opencompress/anthropic/claude-opus-4-6 → Claude Opus, compressed
|
|
113
|
+
opencompress/openai/gpt-5.4 → GPT-5.4, compressed
|
|
52
114
|
```
|
|
53
115
|
|
|
54
|
-
|
|
116
|
+
Switch back to the original model anytime to disable compression.
|
|
117
|
+
|
|
118
|
+
<br />
|
|
55
119
|
|
|
56
|
-
###
|
|
120
|
+
### Commands
|
|
57
121
|
|
|
58
122
|
```
|
|
59
|
-
/compress-
|
|
60
|
-
/compress
|
|
61
|
-
/compress-byok sk-or-your-openrouter-key # Connect OpenRouter
|
|
62
|
-
/compress-byok off # Switch back to router mode
|
|
123
|
+
/compress-stats view savings, balance, token metrics
|
|
124
|
+
/compress show status and available models
|
|
63
125
|
```
|
|
64
126
|
|
|
65
|
-
|
|
127
|
+
<br />
|
|
66
128
|
|
|
67
|
-
|
|
68
|
-
|---------|-------------|
|
|
69
|
-
| `/compress-stats` | Show compression savings (calls, tokens saved, cost saved) |
|
|
70
|
-
| `/compress-byok <key>` | Connect or switch your LLM provider key |
|
|
71
|
-
| `/compress-byok off` | Disconnect your key (switch to router fallback) |
|
|
129
|
+
---
|
|
72
130
|
|
|
73
|
-
|
|
131
|
+
<br />
|
|
74
132
|
|
|
75
|
-
|
|
133
|
+
### What we believe
|
|
76
134
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
| **Anthropic** | `claude-sonnet-4-6`, `claude-opus-4-6`, `claude-haiku-4-5-20251001` |
|
|
81
|
-
| **Google** | `gemini-2.5-pro`, `gemini-2.5-flash`, `google/gemini-2.5-pro-preview` |
|
|
82
|
-
| **DeepSeek** | `deepseek/deepseek-chat-v3-0324`, `deepseek/deepseek-reasoner` |
|
|
83
|
-
| **Meta** | `meta-llama/llama-4-maverick`, `meta-llama/llama-4-scout` |
|
|
84
|
-
| **Qwen** | `qwen/qwen3-235b-a22b`, `qwen/qwen3-32b` |
|
|
85
|
-
| **Mistral** | `mistralai/mistral-large-2411` |
|
|
135
|
+
<table>
|
|
136
|
+
<tr>
|
|
137
|
+
<td width="50%">
|
|
86
138
|
|
|
87
|
-
|
|
139
|
+
**Your keys are yours.**
|
|
88
140
|
|
|
89
|
-
|
|
141
|
+
We read your API key from OpenClaw's config at runtime, pass it in a per-request header, and discard it immediately. We never store, log, or cache your provider credentials. Ever.
|
|
90
142
|
|
|
91
|
-
|
|
143
|
+
</td>
|
|
144
|
+
<td width="50%">
|
|
92
145
|
|
|
93
|
-
|
|
146
|
+
**Your prompts are yours.**
|
|
94
147
|
|
|
95
|
-
|
|
96
|
-
|-----|---------|-------------|
|
|
97
|
-
| `apiKey` | — | Your `sk-occ-...` key (set during onboard) |
|
|
98
|
-
| `baseUrl` | `https://www.opencompress.ai/api` | Custom API endpoint |
|
|
148
|
+
Prompts are compressed in-memory and forwarded. Nothing is stored, logged, or used for training. The only thing we record is token counts for billing, original vs compressed. That's it.
|
|
99
149
|
|
|
100
|
-
|
|
150
|
+
</td>
|
|
151
|
+
</tr>
|
|
152
|
+
<tr>
|
|
153
|
+
<td>
|
|
101
154
|
|
|
102
|
-
|
|
103
|
-
|
|
155
|
+
**Zero lock-in.**
|
|
156
|
+
|
|
157
|
+
We don't replace your provider. We don't wrap your billing. If you uninstall, your agents keep working exactly as before. Same keys, same models, same everything.
|
|
158
|
+
|
|
159
|
+
</td>
|
|
160
|
+
<td>
|
|
161
|
+
|
|
162
|
+
**Failure is invisible.**
|
|
163
|
+
|
|
164
|
+
If our service goes down, your requests fall back directly to your provider. No errors, no downtime, no interruption. You just temporarily lose the compression savings.
|
|
165
|
+
|
|
166
|
+
</td>
|
|
167
|
+
</tr>
|
|
168
|
+
</table>
|
|
169
|
+
|
|
170
|
+
<br />
|
|
171
|
+
|
|
172
|
+
---
|
|
173
|
+
|
|
174
|
+
<br />
|
|
175
|
+
|
|
176
|
+
### Supported providers
|
|
177
|
+
|
|
178
|
+
```
|
|
179
|
+
Anthropic Claude Sonnet, Opus, Haiku anthropic-messages
|
|
180
|
+
OpenAI GPT-5.x, o-series openai-completions
|
|
181
|
+
Google Gemini openai-compat
|
|
182
|
+
OpenRouter 400+ models openai-completions
|
|
183
|
+
Any OpenAI-compatible endpoint openai-completions
|
|
104
184
|
```
|
|
105
185
|
|
|
106
|
-
|
|
186
|
+
<br />
|
|
187
|
+
|
|
188
|
+
### Pricing
|
|
189
|
+
|
|
190
|
+
Free credit on signup. No credit card. Pay only for the tokens you save.
|
|
191
|
+
|
|
192
|
+
**[Dashboard →](https://www.opencompress.ai/dashboard)**
|
|
193
|
+
|
|
194
|
+
<br />
|
|
195
|
+
|
|
196
|
+
---
|
|
197
|
+
|
|
198
|
+
<br />
|
|
199
|
+
|
|
200
|
+
<p align="center">
|
|
201
|
+
<a href="https://www.opencompress.ai">opencompress.ai</a>
|
|
202
|
+
·
|
|
203
|
+
<a href="https://www.npmjs.com/package/@opencompress/openclaw">npm</a>
|
|
204
|
+
·
|
|
205
|
+
<a href="https://github.com/open-compress/opencompress-openclaw">github</a>
|
|
206
|
+
</p>
|
|
207
|
+
|
|
208
|
+
<p align="center">
|
|
209
|
+
<sub>MIT License · OpenCompress</sub>
|
|
210
|
+
</p>
|
|
211
|
+
|
|
212
|
+
<br />
|
|
107
213
|
|
|
108
|
-
|
|
214
|
+
<!-- SEO: OpenClaw plugin, LLM token compression, save LLM tokens, reduce token cost, prompt compression, token optimization, reduce OpenClaw token usage, save API costs, LLM cost reduction, compress prompts, token savings, reduce AI costs, BYOK compression, OpenAI cost reduction, Anthropic cost reduction, Claude token savings, GPT token optimization, context compression, agentic compression, save money on LLM, reduce LLM bill, compress LLM context, openclaw cost savings -->
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* OpenCompress
|
|
2
|
+
* OpenCompress for OpenClaw
|
|
3
3
|
*
|
|
4
4
|
* Registers as an OpenClaw Provider. Users select opencompress/* models.
|
|
5
5
|
* Local HTTP proxy compresses requests via opencompress.ai, then forwards
|
|
6
6
|
* to the user's upstream provider. Keys never leave your machine.
|
|
7
|
+
*
|
|
8
|
+
* Auto-provisions API key on first load. No onboard step needed.
|
|
7
9
|
*/
|
|
8
10
|
type ModelApi = "openai-completions" | "openai-responses" | "anthropic-messages" | "google-generative-ai";
|
|
9
11
|
type ModelDefinitionConfig = {
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
2
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
3
|
+
}) : x)(function(x) {
|
|
4
|
+
if (typeof require !== "undefined") return require.apply(this, arguments);
|
|
5
|
+
throw Error('Dynamic require of "' + x + '" is not supported');
|
|
6
|
+
});
|
|
7
|
+
|
|
1
8
|
// src/config.ts
|
|
2
|
-
var VERSION = "3.0.
|
|
9
|
+
var VERSION = "3.0.1";
|
|
3
10
|
var PROXY_PORT = 8401;
|
|
4
11
|
var PROXY_HOST = "127.0.0.1";
|
|
5
12
|
var OCC_API = "https://www.opencompress.ai/api";
|
|
@@ -84,6 +91,37 @@ function startProxy(getProviders2, getOccKey) {
|
|
|
84
91
|
res.end(JSON.stringify({ status: "ok", version: "2.0.0" }));
|
|
85
92
|
return;
|
|
86
93
|
}
|
|
94
|
+
if (req.url === "/provision" && req.method === "POST") {
|
|
95
|
+
try {
|
|
96
|
+
const provRes = await fetch(`${OCC_API}/v1/provision`, {
|
|
97
|
+
method: "POST",
|
|
98
|
+
headers: { "Content-Type": "application/json" },
|
|
99
|
+
body: "{}"
|
|
100
|
+
});
|
|
101
|
+
const data = await provRes.text();
|
|
102
|
+
res.writeHead(provRes.status, { "Content-Type": "application/json" });
|
|
103
|
+
res.end(data);
|
|
104
|
+
} catch (err) {
|
|
105
|
+
res.writeHead(502, { "Content-Type": "application/json" });
|
|
106
|
+
res.end(JSON.stringify({ error: { message: String(err) } }));
|
|
107
|
+
}
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (req.url === "/stats" && req.method === "GET") {
|
|
111
|
+
const authHeader = req.headers["authorization"] || "";
|
|
112
|
+
try {
|
|
113
|
+
const statsRes = await fetch(`${OCC_API}/user/stats`, {
|
|
114
|
+
headers: { Authorization: authHeader }
|
|
115
|
+
});
|
|
116
|
+
const data = await statsRes.text();
|
|
117
|
+
res.writeHead(statsRes.status, { "Content-Type": "application/json" });
|
|
118
|
+
res.end(data);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
res.writeHead(502, { "Content-Type": "application/json" });
|
|
121
|
+
res.end(JSON.stringify({ error: { message: String(err) } }));
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
87
125
|
if (req.method !== "POST") {
|
|
88
126
|
res.writeHead(405);
|
|
89
127
|
res.end("Method not allowed");
|
|
@@ -263,14 +301,64 @@ function readBody(req) {
|
|
|
263
301
|
}
|
|
264
302
|
|
|
265
303
|
// src/index.ts
|
|
304
|
+
var _cachedKey;
|
|
266
305
|
function getApiKey(api) {
|
|
306
|
+
if (_cachedKey) return _cachedKey;
|
|
267
307
|
const auth = api.config.auth;
|
|
268
308
|
const fromConfig = auth?.profiles?.opencompress?.credentials?.["api-key"]?.apiKey;
|
|
269
|
-
if (fromConfig)
|
|
270
|
-
|
|
271
|
-
|
|
309
|
+
if (fromConfig) {
|
|
310
|
+
_cachedKey = fromConfig;
|
|
311
|
+
return fromConfig;
|
|
312
|
+
}
|
|
313
|
+
if (process.env.OPENCOMPRESS_API_KEY) {
|
|
314
|
+
_cachedKey = process.env.OPENCOMPRESS_API_KEY;
|
|
315
|
+
return _cachedKey;
|
|
316
|
+
}
|
|
317
|
+
if (api.pluginConfig?.apiKey) {
|
|
318
|
+
_cachedKey = api.pluginConfig.apiKey;
|
|
319
|
+
return _cachedKey;
|
|
320
|
+
}
|
|
321
|
+
try {
|
|
322
|
+
const fs = __require("fs");
|
|
323
|
+
const os = __require("os");
|
|
324
|
+
const path = __require("path");
|
|
325
|
+
const keyPath = path.join(os.homedir(), ".openclaw", "opencompress", "api-key");
|
|
326
|
+
if (fs.existsSync(keyPath)) {
|
|
327
|
+
const key = fs.readFileSync(keyPath, "utf-8").trim();
|
|
328
|
+
if (key.startsWith("sk-occ-")) {
|
|
329
|
+
_cachedKey = key;
|
|
330
|
+
return key;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} catch {
|
|
334
|
+
}
|
|
272
335
|
return void 0;
|
|
273
336
|
}
|
|
337
|
+
async function autoProvision(api) {
|
|
338
|
+
try {
|
|
339
|
+
const res = await fetch(`http://${PROXY_HOST}:${PROXY_PORT}/provision`, {
|
|
340
|
+
method: "POST"
|
|
341
|
+
});
|
|
342
|
+
if (!res.ok) return void 0;
|
|
343
|
+
const data = await res.json();
|
|
344
|
+
const key = data.apiKey;
|
|
345
|
+
if (!key) return void 0;
|
|
346
|
+
try {
|
|
347
|
+
const fs = __require("fs");
|
|
348
|
+
const os = __require("os");
|
|
349
|
+
const path = __require("path");
|
|
350
|
+
const dir = path.join(os.homedir(), ".openclaw", "opencompress");
|
|
351
|
+
fs.mkdirSync(dir, { recursive: true });
|
|
352
|
+
fs.writeFileSync(path.join(dir, "api-key"), key, { mode: 384 });
|
|
353
|
+
} catch {
|
|
354
|
+
}
|
|
355
|
+
_cachedKey = key;
|
|
356
|
+
api.logger.info(`OpenCompress: auto-provisioned API key (${data.freeCredit} free credit)`);
|
|
357
|
+
return key;
|
|
358
|
+
} catch {
|
|
359
|
+
return void 0;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
274
362
|
function getProviders(api) {
|
|
275
363
|
return api.config.models?.providers || {};
|
|
276
364
|
}
|
|
@@ -298,7 +386,7 @@ function createProvider(api) {
|
|
|
298
386
|
kind: "custom",
|
|
299
387
|
run: async (ctx) => {
|
|
300
388
|
ctx.prompter.note(
|
|
301
|
-
"
|
|
389
|
+
"OpenCompress compresses LLM input and output to save tokens and improve quality.\nYour existing API keys stay on your machine. We just make the traffic smaller."
|
|
302
390
|
);
|
|
303
391
|
const spinner = ctx.prompter.progress("Creating your account...");
|
|
304
392
|
try {
|
|
@@ -313,19 +401,17 @@ function createProvider(api) {
|
|
|
313
401
|
}
|
|
314
402
|
const data = await res.json();
|
|
315
403
|
spinner.stop("Account created!");
|
|
404
|
+
_cachedKey = data.apiKey;
|
|
316
405
|
return {
|
|
317
406
|
profiles: [{
|
|
318
407
|
profileId: "default",
|
|
319
408
|
credential: { apiKey: data.apiKey }
|
|
320
409
|
}],
|
|
321
410
|
notes: [
|
|
322
|
-
"
|
|
323
|
-
|
|
411
|
+
"OpenCompress ready!",
|
|
412
|
+
`${data.freeCredit} free credit. No credit card needed.`,
|
|
324
413
|
"",
|
|
325
|
-
"Select any opencompress/* model to enable compression."
|
|
326
|
-
"Your existing provider keys are used automatically.",
|
|
327
|
-
"",
|
|
328
|
-
"Dashboard: https://www.opencompress.ai/dashboard"
|
|
414
|
+
"Select any opencompress/* model to enable compression."
|
|
329
415
|
]
|
|
330
416
|
};
|
|
331
417
|
} catch (err) {
|
|
@@ -340,7 +426,7 @@ function createProvider(api) {
|
|
|
340
426
|
var plugin = {
|
|
341
427
|
id: "opencompress",
|
|
342
428
|
name: "OpenCompress",
|
|
343
|
-
description: "Save tokens and sharpen quality on any LLM
|
|
429
|
+
description: "Save tokens and sharpen quality on any LLM. Use your existing providers.",
|
|
344
430
|
version: VERSION,
|
|
345
431
|
register(api) {
|
|
346
432
|
api.registerProvider(createProvider(api));
|
|
@@ -358,7 +444,10 @@ var plugin = {
|
|
|
358
444
|
stopProxy();
|
|
359
445
|
}
|
|
360
446
|
});
|
|
361
|
-
setTimeout(() => {
|
|
447
|
+
setTimeout(async () => {
|
|
448
|
+
if (!getApiKey(api)) {
|
|
449
|
+
await autoProvision(api);
|
|
450
|
+
}
|
|
362
451
|
try {
|
|
363
452
|
startProxy(
|
|
364
453
|
() => getProviders(api),
|
|
@@ -366,14 +455,17 @@ var plugin = {
|
|
|
366
455
|
);
|
|
367
456
|
} catch {
|
|
368
457
|
}
|
|
369
|
-
},
|
|
458
|
+
}, 1500);
|
|
370
459
|
api.registerCommand({
|
|
371
|
-
name: "
|
|
460
|
+
name: "compress_stats",
|
|
372
461
|
description: "Show OpenCompress savings and balance",
|
|
373
462
|
handler: async () => {
|
|
374
|
-
|
|
463
|
+
let key = getApiKey(api);
|
|
375
464
|
if (!key) {
|
|
376
|
-
|
|
465
|
+
key = await autoProvision(api) || void 0;
|
|
466
|
+
}
|
|
467
|
+
if (!key) {
|
|
468
|
+
return { text: "Could not provision API key. Check your network connection." };
|
|
377
469
|
}
|
|
378
470
|
try {
|
|
379
471
|
const res = await fetch(`${OCC_API}/user/stats`, {
|
|
@@ -387,15 +479,15 @@ var plugin = {
|
|
|
387
479
|
return {
|
|
388
480
|
text: [
|
|
389
481
|
"```",
|
|
390
|
-
"
|
|
391
|
-
"
|
|
482
|
+
"OpenCompress Stats",
|
|
483
|
+
"==================",
|
|
392
484
|
`Balance: $${balance.toFixed(2)}`,
|
|
393
485
|
`API calls: ${calls}`,
|
|
394
486
|
`Avg compression: ${rate}`,
|
|
395
487
|
`Tokens saved: ${(Number(s.totalOriginalTokens || 0) - Number(s.totalCompressedTokens || 0)).toLocaleString()}`,
|
|
396
488
|
"```",
|
|
397
489
|
"",
|
|
398
|
-
balance < 0.5 ?
|
|
490
|
+
balance < 0.5 ? `Low balance. Link your account for $10 bonus: https://www.opencompress.ai/dashboard?link=${encodeURIComponent(key)}` : "Dashboard: https://www.opencompress.ai/dashboard"
|
|
399
491
|
].join("\n")
|
|
400
492
|
};
|
|
401
493
|
} catch (err) {
|
|
@@ -407,20 +499,23 @@ var plugin = {
|
|
|
407
499
|
name: "compress",
|
|
408
500
|
description: "Show OpenCompress status and available models",
|
|
409
501
|
handler: async () => {
|
|
410
|
-
|
|
502
|
+
let key = getApiKey(api);
|
|
503
|
+
if (!key) {
|
|
504
|
+
key = await autoProvision(api) || void 0;
|
|
505
|
+
}
|
|
411
506
|
const providers = getProviders(api);
|
|
412
507
|
const models = generateModelCatalog(providers);
|
|
413
508
|
return {
|
|
414
509
|
text: [
|
|
415
510
|
"**OpenCompress**",
|
|
416
511
|
"",
|
|
417
|
-
`API key: ${key ? `${key.slice(0,
|
|
512
|
+
`API key: ${key ? `${key.slice(0, 15)}...` : "provisioning failed"}`,
|
|
418
513
|
`Proxy: http://${PROXY_HOST}:${PROXY_PORT}`,
|
|
419
514
|
"",
|
|
420
515
|
"**Compressed models:**",
|
|
421
516
|
...models.map((m) => ` ${m.id}`),
|
|
422
517
|
"",
|
|
423
|
-
"
|
|
518
|
+
"Use `/model opencompress/auto` to enable compression."
|
|
424
519
|
].join("\n")
|
|
425
520
|
};
|
|
426
521
|
}
|