@opencompress/openclaw 3.0.1 → 3.0.3

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 +80 -18
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -6,13 +6,34 @@ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require
6
6
  });
7
7
 
8
8
  // src/config.ts
9
- var VERSION = "3.0.1";
9
+ var VERSION = "3.0.3";
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";
13
13
  var PROVIDER_ID = "opencompress";
14
14
 
15
15
  // src/models.ts
16
+ var BUILTIN_PROVIDERS = {
17
+ anthropic: { baseUrl: "https://api.anthropic.com", api: "anthropic-messages", envVar: "ANTHROPIC_API_KEY" },
18
+ openai: { baseUrl: "https://api.openai.com", api: "openai-completions", envVar: "OPENAI_API_KEY" },
19
+ google: { baseUrl: "https://generativelanguage.googleapis.com", api: "google-generative-ai", envVar: "GOOGLE_API_KEY" },
20
+ xai: { baseUrl: "https://api.x.ai", api: "openai-completions", envVar: "XAI_API_KEY" },
21
+ deepseek: { baseUrl: "https://api.deepseek.com", api: "openai-completions", envVar: "DEEPSEEK_API_KEY" }
22
+ };
23
+ function resolveBuiltin(providerId) {
24
+ const builtin = BUILTIN_PROVIDERS[providerId];
25
+ if (!builtin) return null;
26
+ const key = process.env[builtin.envVar];
27
+ if (!key) return null;
28
+ return {
29
+ upstreamProvider: providerId,
30
+ upstreamModel: "",
31
+ // caller must set
32
+ upstreamKey: key,
33
+ upstreamBaseUrl: builtin.baseUrl,
34
+ upstreamApi: builtin.api
35
+ };
36
+ }
16
37
  function resolveUpstream(modelId, providers) {
17
38
  const stripped = modelId.replace(/^opencompress\//, "");
18
39
  if (stripped === "auto") {
@@ -28,31 +49,54 @@ function resolveUpstream(modelId, providers) {
28
49
  upstreamApi: config2.api || "openai-completions"
29
50
  };
30
51
  }
52
+ for (const [id, builtin2] of Object.entries(BUILTIN_PROVIDERS)) {
53
+ const key = process.env[builtin2.envVar];
54
+ if (key) {
55
+ return {
56
+ upstreamProvider: id,
57
+ upstreamModel: "",
58
+ // OpenClaw will set the actual model
59
+ upstreamKey: key,
60
+ upstreamBaseUrl: builtin2.baseUrl,
61
+ upstreamApi: builtin2.api
62
+ };
63
+ }
64
+ }
31
65
  return null;
32
66
  }
33
67
  const slashIdx = stripped.indexOf("/");
34
68
  if (slashIdx === -1) {
35
69
  const config2 = providers[stripped];
36
- if (!config2) return null;
37
- return {
38
- upstreamProvider: stripped,
39
- upstreamModel: config2.models?.[0]?.id || stripped,
40
- upstreamKey: config2.apiKey,
41
- upstreamBaseUrl: config2.baseUrl,
42
- upstreamApi: config2.api || "openai-completions"
43
- };
70
+ if (config2) {
71
+ return {
72
+ upstreamProvider: stripped,
73
+ upstreamModel: config2.models?.[0]?.id || stripped,
74
+ upstreamKey: config2.apiKey,
75
+ upstreamBaseUrl: config2.baseUrl,
76
+ upstreamApi: config2.api || "openai-completions"
77
+ };
78
+ }
79
+ const builtin2 = resolveBuiltin(stripped);
80
+ if (builtin2) return builtin2;
81
+ return null;
44
82
  }
45
83
  const upstreamProvider = stripped.slice(0, slashIdx);
46
84
  const upstreamModel = stripped.slice(slashIdx + 1);
47
85
  const config = providers[upstreamProvider];
48
- if (!config) return null;
49
- return {
50
- upstreamProvider,
51
- upstreamModel,
52
- upstreamKey: config.apiKey,
53
- upstreamBaseUrl: config.baseUrl,
54
- upstreamApi: config.api || "openai-completions"
55
- };
86
+ if (config) {
87
+ return {
88
+ upstreamProvider,
89
+ upstreamModel,
90
+ upstreamKey: config.apiKey,
91
+ upstreamBaseUrl: config.baseUrl,
92
+ upstreamApi: config.api || "openai-completions"
93
+ };
94
+ }
95
+ const builtin = resolveBuiltin(upstreamProvider);
96
+ if (builtin) {
97
+ return { ...builtin, upstreamModel };
98
+ }
99
+ return null;
56
100
  }
57
101
  function generateModelCatalog(providers) {
58
102
  const models = [];
@@ -88,7 +132,7 @@ function startProxy(getProviders2, getOccKey) {
88
132
  server = http.createServer(async (req, res) => {
89
133
  if (req.url === "/health" && req.method === "GET") {
90
134
  res.writeHead(200, { "Content-Type": "application/json" });
91
- res.end(JSON.stringify({ status: "ok", version: "2.0.0" }));
135
+ res.end(JSON.stringify({ status: "ok", version: VERSION }));
92
136
  return;
93
137
  }
94
138
  if (req.url === "/provision" && req.method === "POST") {
@@ -260,6 +304,14 @@ function startProxy(getProviders2, getOccKey) {
260
304
  server.on("error", (err) => {
261
305
  if (err.code === "EADDRINUSE") {
262
306
  server = null;
307
+ try {
308
+ const { execSync } = __require("child_process");
309
+ execSync(`lsof -i :${PROXY_PORT} -t | xargs kill -9 2>/dev/null`, { stdio: "ignore" });
310
+ } catch {
311
+ }
312
+ setTimeout(() => {
313
+ if (!server) startProxy(getProviders2, getOccKey);
314
+ }, 2e3);
263
315
  }
264
316
  });
265
317
  return server;
@@ -362,6 +414,15 @@ async function autoProvision(api) {
362
414
  function getProviders(api) {
363
415
  return api.config.models?.providers || {};
364
416
  }
417
+ function injectEnvVars(api) {
418
+ const envVars = api.config.env?.vars;
419
+ if (!envVars) return;
420
+ for (const [key, value] of Object.entries(envVars)) {
421
+ if (!process.env[key] && value) {
422
+ process.env[key] = value;
423
+ }
424
+ }
425
+ }
365
426
  function createProvider(api) {
366
427
  return {
367
428
  id: PROVIDER_ID,
@@ -429,6 +490,7 @@ var plugin = {
429
490
  description: "Save tokens and sharpen quality on any LLM. Use your existing providers.",
430
491
  version: VERSION,
431
492
  register(api) {
493
+ injectEnvVars(api);
432
494
  api.registerProvider(createProvider(api));
433
495
  api.logger.info(`OpenCompress v${VERSION} registered`);
434
496
  api.registerService({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opencompress/openclaw",
3
- "version": "3.0.1",
3
+ "version": "3.0.3",
4
4
  "description": "OpenCompress for OpenClaw — save tokens and sharpen quality on any LLM",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",