@opencompress/opencompress 1.6.4 → 1.6.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 +53 -2
  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/index.ts
9
- var VERSION = "1.6.4";
9
+ var VERSION = "1.6.6";
10
10
  var DEFAULT_BASE_URL = "https://www.opencompress.ai/api";
11
11
  function getApiKey(api) {
12
12
  const auth = api.config.auth;
@@ -377,7 +377,7 @@ var plugin = {
377
377
  name: "OpenCompress",
378
378
  description: "5-layer prompt compression \u2014 53% input reduction, 62% latency cut, 96% quality",
379
379
  version: VERSION,
380
- async register(api) {
380
+ register(api) {
381
381
  const baseUrl = api.pluginConfig?.baseUrl || DEFAULT_BASE_URL;
382
382
  const existingHeaders = api.config.models?.providers?.opencompress?.headers;
383
383
  const existingUpstreamKey = existingHeaders?.["X-Upstream-Key"];
@@ -572,6 +572,57 @@ var plugin = {
572
572
  }
573
573
  });
574
574
  api.logger.info("Registered /compress-byok command");
575
+ const os = __require("os");
576
+ const fs = __require("fs");
577
+ const path = __require("path");
578
+ const logDir = path.join(os.homedir(), ".openclaw", "opencompress-logs");
579
+ try {
580
+ fs.mkdirSync(logDir, { recursive: true });
581
+ } catch {
582
+ }
583
+ api.on("llm_input", async (event) => {
584
+ try {
585
+ const ts = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
586
+ const systemPromptLen = event.systemPrompt?.length || 0;
587
+ const historyLen = Array.isArray(event.historyMessages) ? event.historyMessages.length : 0;
588
+ const promptLen = event.prompt?.length || 0;
589
+ const systemTokens = Math.ceil(systemPromptLen / 4);
590
+ const historyText = JSON.stringify(event.historyMessages || []);
591
+ const historyTokens = Math.ceil(historyText.length / 4);
592
+ const promptTokens = Math.ceil(promptLen / 4);
593
+ const totalTokens = systemTokens + historyTokens + promptTokens;
594
+ const entry = {
595
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
596
+ runId: event.runId,
597
+ sessionId: event.sessionId,
598
+ provider: event.provider,
599
+ model: event.model,
600
+ imagesCount: event.imagesCount || 0,
601
+ tokenEstimate: {
602
+ systemPrompt: systemTokens,
603
+ history: historyTokens,
604
+ currentPrompt: promptTokens,
605
+ total: totalTokens
606
+ },
607
+ charLengths: {
608
+ systemPrompt: systemPromptLen,
609
+ history: historyText.length,
610
+ currentPrompt: promptLen
611
+ },
612
+ historyMessageCount: historyLen,
613
+ systemPrompt: event.systemPrompt,
614
+ historyMessages: event.historyMessages,
615
+ prompt: event.prompt
616
+ };
617
+ const filename = `${ts}_${event.model || "unknown"}.json`;
618
+ fs.writeFileSync(
619
+ path.join(logDir, filename),
620
+ JSON.stringify(entry, null, 2) + "\n"
621
+ );
622
+ } catch {
623
+ }
624
+ });
625
+ api.logger.info(`LLM input logging enabled \u2192 ${logDir}`);
575
626
  }
576
627
  };
577
628
  var index_default = plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencompress/opencompress",
3
- "version": "1.6.4",
3
+ "version": "1.6.6",
4
4
  "description": "OpenCompress plugin for OpenClaw — automatic 5-layer prompt compression for any LLM",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",