@opencompress/openclaw 3.0.4 → 3.0.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.
Files changed (2) hide show
  1. package/dist/index.js +92 -3
  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.4";
9
+ var VERSION = "3.0.6";
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";
@@ -482,6 +482,89 @@ function createProvider(api) {
482
482
  ]
483
483
  };
484
484
  }
485
+ function injectConfig(api) {
486
+ try {
487
+ const fs = __require("fs");
488
+ const os = __require("os");
489
+ const path = __require("path");
490
+ const configPath = path.join(os.homedir(), ".openclaw", "openclaw.json");
491
+ if (!fs.existsSync(configPath)) return;
492
+ const cfg = JSON.parse(fs.readFileSync(configPath, "utf-8"));
493
+ let changed = false;
494
+ if (!cfg.models) cfg.models = {};
495
+ 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";
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`,
504
+ 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;
518
+ }
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) {
523
+ if (!cfg.agents.defaults.models[m.id]) {
524
+ cfg.agents.defaults.models[m.id] = {};
525
+ changed = true;
526
+ }
527
+ }
528
+ if (!cfg.plugins) cfg.plugins = {};
529
+ const allow = cfg.plugins.allow || [];
530
+ if (!allow.includes("opencompress")) {
531
+ cfg.plugins.allow = [...allow, "opencompress"];
532
+ changed = true;
533
+ }
534
+ if (changed) {
535
+ fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2) + "\n");
536
+ api.logger.info("OpenCompress: injected provider + models into config");
537
+ }
538
+ const agentsDir = path.join(os.homedir(), ".openclaw", "agents");
539
+ if (fs.existsSync(agentsDir)) {
540
+ for (const agent of fs.readdirSync(agentsDir)) {
541
+ const authPath = path.join(agentsDir, agent, "agent", "auth-profiles.json");
542
+ const authDir = path.dirname(authPath);
543
+ if (!fs.existsSync(authDir)) continue;
544
+ let profiles = { version: 1, profiles: {} };
545
+ if (fs.existsSync(authPath)) {
546
+ try {
547
+ profiles = JSON.parse(fs.readFileSync(authPath, "utf-8"));
548
+ } catch {
549
+ }
550
+ }
551
+ if (!profiles.profiles["opencompress:default"]) {
552
+ profiles.profiles["opencompress:default"] = {
553
+ type: "api_key",
554
+ provider: "opencompress",
555
+ key: occKey
556
+ };
557
+ fs.writeFileSync(authPath, JSON.stringify(profiles, null, 2) + "\n");
558
+ }
559
+ }
560
+ }
561
+ if (api.config.models?.providers) {
562
+ api.config.models.providers.opencompress = cfg.models.providers.opencompress;
563
+ }
564
+ } catch (err) {
565
+ api.logger.warn(`OpenCompress: config injection failed: ${err}`);
566
+ }
567
+ }
485
568
  var plugin = {
486
569
  id: "opencompress",
487
570
  name: "OpenCompress",
@@ -490,6 +573,7 @@ var plugin = {
490
573
  register(api) {
491
574
  injectEnvVars(api);
492
575
  api.registerProvider(createProvider(api));
576
+ injectConfig(api);
493
577
  api.logger.info(`OpenCompress v${VERSION} registered`);
494
578
  api.registerService({
495
579
  id: "opencompress-proxy",
@@ -536,15 +620,20 @@ var plugin = {
536
620
  const balance = Number(s.balanceUsd || s.balance || 0);
537
621
  const calls = s.monthlyApiCalls ?? s.totalCalls ?? 0;
538
622
  const rate = s.avgCompressionRate ? `${(Number(s.avgCompressionRate) * 100).toFixed(1)}%` : "N/A";
623
+ const tokensSaved = Number(s.totalOriginalTokens || 0) - Number(s.totalCompressedTokens || 0);
624
+ const totalCharged = Number(s.month?.totalCharged || 0);
625
+ const totalSaved = Number(s.month?.costSaved || s.totalSavings || 0);
539
626
  return {
540
627
  text: [
541
628
  "```",
542
629
  "OpenCompress Stats",
543
630
  "==================",
544
- `Balance: $${balance.toFixed(2)}`,
631
+ `Balance: $${balance.toFixed(4)}`,
545
632
  `API calls: ${calls}`,
546
633
  `Avg compression: ${rate}`,
547
- `Tokens saved: ${(Number(s.totalOriginalTokens || 0) - Number(s.totalCompressedTokens || 0)).toLocaleString()}`,
634
+ `Tokens saved: ${tokensSaved.toLocaleString()}`,
635
+ `Money saved: $${totalSaved.toFixed(4)}`,
636
+ `Total charged: $${totalCharged.toFixed(4)}`,
548
637
  "```",
549
638
  "",
550
639
  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.4",
3
+ "version": "3.0.6",
4
4
  "description": "OpenCompress for OpenClaw — save tokens and sharpen quality on any LLM",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",