@opencompress/openclaw 3.0.5 → 3.0.7

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.
Files changed (2) hide show
  1. package/dist/index.js +49 -28
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/config.ts
9
- var VERSION = "3.0.5";
9
+ var VERSION = "3.0.7";
10
10
  var PROXY_PORT = 8401;
11
11
  var PROXY_HOST = "127.0.0.1";
12
12
  var OCC_API = "https://www.opencompress.ai/api";
@@ -491,38 +491,54 @@ function injectConfig(api) {
491
491
  if (!fs.existsSync(configPath)) return;
492
492
  const cfg = JSON.parse(fs.readFileSync(configPath, "utf-8"));
493
493
  let changed = false;
494
+ if (!cfg.agents) cfg.agents = {};
495
+ if (!cfg.agents.defaults) cfg.agents.defaults = {};
496
+ if (!cfg.agents.defaults.models) cfg.agents.defaults.models = {};
494
497
  if (!cfg.models) cfg.models = {};
495
498
  if (!cfg.models.providers) cfg.models.providers = {};
496
- const providers = getProviders(api);
497
- const models = generateModelCatalog(providers);
498
- const firstProvider = Object.values(providers).find((p) => p.api);
499
- const primaryApi = firstProvider?.api || "anthropic-messages";
499
+ const existingModels = Object.keys(cfg.agents.defaults.models).filter((id) => !id.startsWith("opencompress/"));
500
500
  const occKey = getApiKey(api) || "auto-provision-pending";
501
- if (!cfg.models.providers.opencompress || cfg.models.providers.opencompress.baseUrl !== `http://${PROXY_HOST}:${PROXY_PORT}/v1`) {
502
- cfg.models.providers.opencompress = {
503
- baseUrl: `http://${PROXY_HOST}:${PROXY_PORT}/v1`,
501
+ const hasAnthropic = existingModels.some((m) => m.startsWith("anthropic/"));
502
+ const hasOpenAI = existingModels.some((m) => m.startsWith("openai/"));
503
+ const primaryApi = hasAnthropic ? "anthropic-messages" : "openai-completions";
504
+ const compressedModels = [
505
+ {
506
+ id: "opencompress/auto",
507
+ name: "OpenCompress Auto (compressed)",
504
508
  api: primaryApi,
505
- apiKey: occKey,
506
- models: models.map((m) => ({
507
- id: m.id,
508
- name: m.name,
509
- api: primaryApi,
510
- reasoning: m.reasoning ?? false,
511
- input: m.input || ["text"],
512
- cost: m.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
513
- contextWindow: m.contextWindow || 2e5,
514
- maxTokens: m.maxTokens || 8192
515
- }))
516
- };
517
- changed = true;
509
+ reasoning: false,
510
+ input: ["text", "image"],
511
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
512
+ contextWindow: 2e5,
513
+ maxTokens: 8192
514
+ }
515
+ ];
516
+ for (const modelId of existingModels) {
517
+ const compressedId = `opencompress/${modelId}`;
518
+ const provider = modelId.split("/")[0];
519
+ const modelApi = provider === "anthropic" ? "anthropic-messages" : "openai-completions";
520
+ const modelName = modelId.split("/").slice(1).join("/");
521
+ compressedModels.push({
522
+ id: compressedId,
523
+ name: `${modelName} (compressed)`,
524
+ api: modelApi,
525
+ reasoning: modelId.includes("opus") || modelId.includes("o1") || modelId.includes("o3"),
526
+ input: ["text", "image"],
527
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
528
+ contextWindow: 2e5,
529
+ maxTokens: 8192
530
+ });
518
531
  }
519
- if (!cfg.agents) cfg.agents = {};
520
- if (!cfg.agents.defaults) cfg.agents.defaults = {};
521
- if (!cfg.agents.defaults.models) cfg.agents.defaults.models = {};
522
- for (const m of models) {
532
+ cfg.models.providers.opencompress = {
533
+ baseUrl: `http://${PROXY_HOST}:${PROXY_PORT}/v1`,
534
+ api: primaryApi,
535
+ apiKey: occKey,
536
+ models: compressedModels
537
+ };
538
+ changed = true;
539
+ for (const m of compressedModels) {
523
540
  if (!cfg.agents.defaults.models[m.id]) {
524
541
  cfg.agents.defaults.models[m.id] = {};
525
- changed = true;
526
542
  }
527
543
  }
528
544
  if (!cfg.plugins) cfg.plugins = {};
@@ -620,15 +636,20 @@ var plugin = {
620
636
  const balance = Number(s.balanceUsd || s.balance || 0);
621
637
  const calls = s.monthlyApiCalls ?? s.totalCalls ?? 0;
622
638
  const rate = s.avgCompressionRate ? `${(Number(s.avgCompressionRate) * 100).toFixed(1)}%` : "N/A";
639
+ const tokensSaved = Number(s.totalOriginalTokens || 0) - Number(s.totalCompressedTokens || 0);
640
+ const totalCharged = Number(s.month?.totalCharged || 0);
641
+ const totalSaved = Number(s.month?.costSaved || s.totalSavings || 0);
623
642
  return {
624
643
  text: [
625
644
  "```",
626
645
  "OpenCompress Stats",
627
646
  "==================",
628
- `Balance: $${balance.toFixed(2)}`,
647
+ `Balance: $${balance.toFixed(4)}`,
629
648
  `API calls: ${calls}`,
630
649
  `Avg compression: ${rate}`,
631
- `Tokens saved: ${(Number(s.totalOriginalTokens || 0) - Number(s.totalCompressedTokens || 0)).toLocaleString()}`,
650
+ `Tokens saved: ${tokensSaved.toLocaleString()}`,
651
+ `Money saved: $${totalSaved.toFixed(4)}`,
652
+ `Total charged: $${totalCharged.toFixed(4)}`,
632
653
  "```",
633
654
  "",
634
655
  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"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencompress/openclaw",
3
- "version": "3.0.5",
3
+ "version": "3.0.7",
4
4
  "description": "OpenCompress for OpenClaw — save tokens and sharpen quality on any LLM",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",