@opencompress/opencompress 1.6.3 → 1.6.5
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/dist/index.js +57 -6
- 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.
|
|
9
|
+
var VERSION = "1.6.5";
|
|
10
10
|
var DEFAULT_BASE_URL = "https://www.opencompress.ai/api";
|
|
11
11
|
function getApiKey(api) {
|
|
12
12
|
const auth = api.config.auth;
|
|
@@ -443,10 +443,10 @@ var plugin = {
|
|
|
443
443
|
}
|
|
444
444
|
const stats = await res.json();
|
|
445
445
|
const calls = stats.totalCalls ?? 0;
|
|
446
|
-
const savings = stats.totalSavings
|
|
447
|
-
const rate = stats.avgCompressionRate ? `${(stats.avgCompressionRate * 100).toFixed(1)}%` : "N/A";
|
|
448
|
-
const origTokens = stats.totalOriginalTokens
|
|
449
|
-
const compTokens = stats.totalCompressedTokens
|
|
446
|
+
const savings = Number(stats.totalSavings || 0).toFixed(4);
|
|
447
|
+
const rate = stats.avgCompressionRate ? `${(Number(stats.avgCompressionRate) * 100).toFixed(1)}%` : "N/A";
|
|
448
|
+
const origTokens = Number(stats.totalOriginalTokens || 0).toLocaleString();
|
|
449
|
+
const compTokens = Number(stats.totalCompressedTokens || 0).toLocaleString();
|
|
450
450
|
return {
|
|
451
451
|
text: [
|
|
452
452
|
"```",
|
|
@@ -498,7 +498,7 @@ var plugin = {
|
|
|
498
498
|
" `/compress-byok sk-or-xxx` \u2014 Connect OpenRouter key",
|
|
499
499
|
" `/compress-byok off` \u2014 Switch back to router mode",
|
|
500
500
|
"",
|
|
501
|
-
data ? `**Balance:** $${data.balance.toFixed(2)}` : ""
|
|
501
|
+
data ? `**Balance:** $${Number(data.balance || 0).toFixed(2)}` : ""
|
|
502
502
|
].join("\n")
|
|
503
503
|
};
|
|
504
504
|
}
|
|
@@ -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;
|