@opencompress/opencompress 1.5.1 → 1.5.2

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.d.ts CHANGED
@@ -29,6 +29,7 @@ type ModelProviderConfig = {
29
29
  headers?: Record<string, string>;
30
30
  authHeader?: boolean;
31
31
  models: ModelDefinitionConfig[];
32
+ [key: string]: unknown;
32
33
  };
33
34
  type AuthProfileCredential = {
34
35
  apiKey?: string;
package/dist/index.js CHANGED
@@ -10,7 +10,30 @@ var VERSION = "1.0.0";
10
10
  var DEFAULT_BASE_URL = "https://www.opencompress.ai/api";
11
11
  function getApiKey(api) {
12
12
  const auth = api.config.auth;
13
- return auth?.profiles?.opencompress?.credentials?.["api-key"]?.apiKey;
13
+ const fromConfig = auth?.profiles?.opencompress?.credentials?.["api-key"]?.apiKey;
14
+ if (fromConfig) return fromConfig;
15
+ if (process.env.OPENCOMPRESS_API_KEY) return process.env.OPENCOMPRESS_API_KEY;
16
+ try {
17
+ const os = __require("os");
18
+ const fs = __require("fs");
19
+ const path = __require("path");
20
+ const agentsDir = path.join(os.homedir(), ".openclaw", "agents");
21
+ if (!fs.existsSync(agentsDir)) return void 0;
22
+ const agentDirs = fs.readdirSync(agentsDir);
23
+ for (const agent of agentDirs) {
24
+ const authPath = path.join(agentsDir, agent, "agent", "auth-profiles.json");
25
+ if (!fs.existsSync(authPath)) continue;
26
+ try {
27
+ const profiles = JSON.parse(fs.readFileSync(authPath, "utf-8"));
28
+ const ocProfile = profiles?.profiles?.["opencompress:default"];
29
+ if (ocProfile?.key) return ocProfile.key;
30
+ } catch {
31
+ continue;
32
+ }
33
+ }
34
+ } catch {
35
+ }
36
+ return void 0;
14
37
  }
15
38
  var FALLBACK_MODELS = [
16
39
  { id: "gpt-4o", name: "GPT-4o", reasoning: false, input: ["text", "image"], cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }, contextWindow: 128e3, maxTokens: 16384 },
@@ -34,10 +57,14 @@ function readExistingModels(api) {
34
57
  const providerModels = providerConfig.models || [];
35
58
  for (const m of providerModels) {
36
59
  if (m.name?.includes("\u2192")) continue;
37
- if (seen.has(m.id)) continue;
38
- seen.add(m.id);
60
+ const rawId = m.id.includes("/") ? m.id.split("/").slice(1).join("/") : m.id;
61
+ if (seen.has(rawId)) continue;
62
+ seen.add(rawId);
63
+ const upstreamId = m.id.startsWith(`${providerId}/`) ? rawId : m.id;
39
64
  models.push({
40
65
  ...m,
66
+ id: upstreamId,
67
+ name: m.name || upstreamId,
41
68
  // Zero out cost — billing handled by OpenCompress proxy
42
69
  cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 }
43
70
  });
@@ -45,10 +72,11 @@ function readExistingModels(api) {
45
72
  }
46
73
  return models.length > 0 ? models : null;
47
74
  }
48
- function buildProviderModels(baseUrl, upstreamKey, upstreamBaseUrl, models) {
75
+ function buildProviderModels(baseUrl, upstreamKey, upstreamBaseUrl, models, apiKey) {
49
76
  const config = {
50
77
  baseUrl: `${baseUrl}/v1`,
51
78
  api: "openai-completions",
79
+ apiKey: apiKey || void 0,
52
80
  models: models || FALLBACK_MODELS
53
81
  };
54
82
  if (upstreamKey || upstreamBaseUrl) {
@@ -85,6 +113,9 @@ function persistModelsConfig(providerModels) {
85
113
  api: providerModels.api || "openai-completions",
86
114
  models: configSafeModels
87
115
  };
116
+ if (providerModels.apiKey) {
117
+ configEntry.apiKey = providerModels.apiKey;
118
+ }
88
119
  if (providerModels.headers) {
89
120
  configEntry.headers = providerModels.headers;
90
121
  }
@@ -195,7 +226,7 @@ var opencompressProvider = {
195
226
  });
196
227
  } catch {
197
228
  }
198
- const onboardModels = buildProviderModels(DEFAULT_BASE_URL, llmKey, upstreamBaseUrl);
229
+ const onboardModels = buildProviderModels(DEFAULT_BASE_URL, llmKey, upstreamBaseUrl, void 0, data.apiKey);
199
230
  const modelCount = FALLBACK_MODELS.length;
200
231
  persistModelsConfig(onboardModels);
201
232
  persistAuthProfile(data.apiKey);
@@ -238,8 +269,9 @@ var plugin = {
238
269
  const existingHeaders = api.config.models?.providers?.opencompress?.headers;
239
270
  const existingUpstreamKey = existingHeaders?.["X-Upstream-Key"];
240
271
  const existingUpstreamBaseUrl = existingHeaders?.["X-Upstream-Base-Url"];
272
+ const existingApiKey = api.config.models?.providers?.opencompress?.apiKey || getApiKey(api);
241
273
  const existingModels = readExistingModels(api);
242
- const providerModels = buildProviderModels(baseUrl, existingUpstreamKey, existingUpstreamBaseUrl, existingModels || void 0);
274
+ const providerModels = buildProviderModels(baseUrl, existingUpstreamKey, existingUpstreamBaseUrl, existingModels || void 0, existingApiKey);
243
275
  opencompressProvider.models = providerModels;
244
276
  api.registerProvider(opencompressProvider);
245
277
  if (!api.config.models) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencompress/opencompress",
3
- "version": "1.5.1",
3
+ "version": "1.5.2",
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",