@opencompress/openclaw 3.0.1 → 3.0.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.js +71 -17
- 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.
|
|
9
|
+
var VERSION = "3.0.2";
|
|
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 (
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
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 (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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 = [];
|
|
@@ -362,6 +406,15 @@ async function autoProvision(api) {
|
|
|
362
406
|
function getProviders(api) {
|
|
363
407
|
return api.config.models?.providers || {};
|
|
364
408
|
}
|
|
409
|
+
function injectEnvVars(api) {
|
|
410
|
+
const envVars = api.config.env?.vars;
|
|
411
|
+
if (!envVars) return;
|
|
412
|
+
for (const [key, value] of Object.entries(envVars)) {
|
|
413
|
+
if (!process.env[key] && value) {
|
|
414
|
+
process.env[key] = value;
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
365
418
|
function createProvider(api) {
|
|
366
419
|
return {
|
|
367
420
|
id: PROVIDER_ID,
|
|
@@ -429,6 +482,7 @@ var plugin = {
|
|
|
429
482
|
description: "Save tokens and sharpen quality on any LLM. Use your existing providers.",
|
|
430
483
|
version: VERSION,
|
|
431
484
|
register(api) {
|
|
485
|
+
injectEnvVars(api);
|
|
432
486
|
api.registerProvider(createProvider(api));
|
|
433
487
|
api.logger.info(`OpenCompress v${VERSION} registered`);
|
|
434
488
|
api.registerService({
|