@opencompress/opencompress 1.6.6 → 1.6.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 +24 -24
  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.6";
9
+ var VERSION = "1.6.7";
10
10
  var DEFAULT_BASE_URL = "https://www.opencompress.ai/api";
11
11
  function getApiKey(api) {
12
12
  const auth = api.config.auth;
@@ -580,46 +580,46 @@ var plugin = {
580
580
  fs.mkdirSync(logDir, { recursive: true });
581
581
  } catch {
582
582
  }
583
- api.on("llm_input", async (event) => {
583
+ api.on("llm_input", (...args) => {
584
584
  try {
585
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;
586
+ const event = args[0] || {};
587
+ const systemPromptLen = typeof event.systemPrompt === "string" ? event.systemPrompt.length : 0;
588
+ const historyMessages = Array.isArray(event.historyMessages) ? event.historyMessages : [];
589
+ const promptLen = typeof event.prompt === "string" ? event.prompt.length : 0;
589
590
  const systemTokens = Math.ceil(systemPromptLen / 4);
590
- const historyText = JSON.stringify(event.historyMessages || []);
591
+ const historyText = JSON.stringify(historyMessages);
591
592
  const historyTokens = Math.ceil(historyText.length / 4);
592
593
  const promptTokens = Math.ceil(promptLen / 4);
593
594
  const totalTokens = systemTokens + historyTokens + promptTokens;
594
595
  const entry = {
595
596
  timestamp: (/* @__PURE__ */ new Date()).toISOString(),
597
+ _argCount: args.length,
598
+ _eventKeys: Object.keys(event),
596
599
  runId: event.runId,
597
600
  sessionId: event.sessionId,
598
601
  provider: event.provider,
599
602
  model: event.model,
600
603
  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,
604
+ tokenEstimate: { systemPrompt: systemTokens, history: historyTokens, currentPrompt: promptTokens, total: totalTokens },
605
+ charLengths: { systemPrompt: systemPromptLen, history: historyText.length, currentPrompt: promptLen },
606
+ historyMessageCount: historyMessages.length,
613
607
  systemPrompt: event.systemPrompt,
614
608
  historyMessages: event.historyMessages,
615
609
  prompt: event.prompt
616
610
  };
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 {
611
+ const model = typeof event.model === "string" ? event.model.replace(/\//g, "_") : "unknown";
612
+ const filename = `${ts}_${model}.json`;
613
+ fs.writeFileSync(path.join(logDir, filename), JSON.stringify(entry, null, 2) + "\n");
614
+ } catch (err) {
615
+ try {
616
+ const errFile = path.join(logDir, `error_${Date.now()}.txt`);
617
+ fs.writeFileSync(errFile, `${err}
618
+ ${err.stack || ""}
619
+ args: ${JSON.stringify(args?.map((a) => typeof a))}
620
+ `);
621
+ } catch {
622
+ }
623
623
  }
624
624
  });
625
625
  api.logger.info(`LLM input logging enabled \u2192 ${logDir}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencompress/opencompress",
3
- "version": "1.6.6",
3
+ "version": "1.6.7",
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",