@opencompress/openclaw 3.0.3 → 3.0.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 +92 -10
- 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/config.ts
|
|
9
|
-
var VERSION = "3.0.
|
|
9
|
+
var VERSION = "3.0.5";
|
|
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";
|
|
@@ -14,11 +14,11 @@ var PROVIDER_ID = "opencompress";
|
|
|
14
14
|
|
|
15
15
|
// src/models.ts
|
|
16
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" }
|
|
17
|
+
anthropic: { baseUrl: "https://api.anthropic.com", api: "anthropic-messages", envVar: "ANTHROPIC_API_KEY", defaultModel: "claude-sonnet-4-20250514" },
|
|
18
|
+
openai: { baseUrl: "https://api.openai.com", api: "openai-completions", envVar: "OPENAI_API_KEY", defaultModel: "gpt-4o" },
|
|
19
|
+
google: { baseUrl: "https://generativelanguage.googleapis.com", api: "google-generative-ai", envVar: "GOOGLE_API_KEY", defaultModel: "gemini-2.0-flash" },
|
|
20
|
+
xai: { baseUrl: "https://api.x.ai", api: "openai-completions", envVar: "XAI_API_KEY", defaultModel: "grok-3" },
|
|
21
|
+
deepseek: { baseUrl: "https://api.deepseek.com", api: "openai-completions", envVar: "DEEPSEEK_API_KEY", defaultModel: "deepseek-chat" }
|
|
22
22
|
};
|
|
23
23
|
function resolveBuiltin(providerId) {
|
|
24
24
|
const builtin = BUILTIN_PROVIDERS[providerId];
|
|
@@ -27,8 +27,7 @@ function resolveBuiltin(providerId) {
|
|
|
27
27
|
if (!key) return null;
|
|
28
28
|
return {
|
|
29
29
|
upstreamProvider: providerId,
|
|
30
|
-
upstreamModel:
|
|
31
|
-
// caller must set
|
|
30
|
+
upstreamModel: builtin.defaultModel,
|
|
32
31
|
upstreamKey: key,
|
|
33
32
|
upstreamBaseUrl: builtin.baseUrl,
|
|
34
33
|
upstreamApi: builtin.api
|
|
@@ -54,8 +53,7 @@ function resolveUpstream(modelId, providers) {
|
|
|
54
53
|
if (key) {
|
|
55
54
|
return {
|
|
56
55
|
upstreamProvider: id,
|
|
57
|
-
upstreamModel:
|
|
58
|
-
// OpenClaw will set the actual model
|
|
56
|
+
upstreamModel: builtin2.defaultModel,
|
|
59
57
|
upstreamKey: key,
|
|
60
58
|
upstreamBaseUrl: builtin2.baseUrl,
|
|
61
59
|
upstreamApi: builtin2.api
|
|
@@ -484,6 +482,89 @@ function createProvider(api) {
|
|
|
484
482
|
]
|
|
485
483
|
};
|
|
486
484
|
}
|
|
485
|
+
function injectConfig(api) {
|
|
486
|
+
try {
|
|
487
|
+
const fs = __require("fs");
|
|
488
|
+
const os = __require("os");
|
|
489
|
+
const path = __require("path");
|
|
490
|
+
const configPath = path.join(os.homedir(), ".openclaw", "openclaw.json");
|
|
491
|
+
if (!fs.existsSync(configPath)) return;
|
|
492
|
+
const cfg = JSON.parse(fs.readFileSync(configPath, "utf-8"));
|
|
493
|
+
let changed = false;
|
|
494
|
+
if (!cfg.models) cfg.models = {};
|
|
495
|
+
if (!cfg.models.providers) cfg.models.providers = {};
|
|
496
|
+
const providers = getProviders(api);
|
|
497
|
+
const models = generateModelCatalog(providers);
|
|
498
|
+
const firstProvider = Object.values(providers).find((p) => p.api);
|
|
499
|
+
const primaryApi = firstProvider?.api || "anthropic-messages";
|
|
500
|
+
const occKey = getApiKey(api) || "auto-provision-pending";
|
|
501
|
+
if (!cfg.models.providers.opencompress || cfg.models.providers.opencompress.baseUrl !== `http://${PROXY_HOST}:${PROXY_PORT}/v1`) {
|
|
502
|
+
cfg.models.providers.opencompress = {
|
|
503
|
+
baseUrl: `http://${PROXY_HOST}:${PROXY_PORT}/v1`,
|
|
504
|
+
api: primaryApi,
|
|
505
|
+
apiKey: occKey,
|
|
506
|
+
models: models.map((m) => ({
|
|
507
|
+
id: m.id,
|
|
508
|
+
name: m.name,
|
|
509
|
+
api: primaryApi,
|
|
510
|
+
reasoning: m.reasoning ?? false,
|
|
511
|
+
input: m.input || ["text"],
|
|
512
|
+
cost: m.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
513
|
+
contextWindow: m.contextWindow || 2e5,
|
|
514
|
+
maxTokens: m.maxTokens || 8192
|
|
515
|
+
}))
|
|
516
|
+
};
|
|
517
|
+
changed = true;
|
|
518
|
+
}
|
|
519
|
+
if (!cfg.agents) cfg.agents = {};
|
|
520
|
+
if (!cfg.agents.defaults) cfg.agents.defaults = {};
|
|
521
|
+
if (!cfg.agents.defaults.models) cfg.agents.defaults.models = {};
|
|
522
|
+
for (const m of models) {
|
|
523
|
+
if (!cfg.agents.defaults.models[m.id]) {
|
|
524
|
+
cfg.agents.defaults.models[m.id] = {};
|
|
525
|
+
changed = true;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
if (!cfg.plugins) cfg.plugins = {};
|
|
529
|
+
const allow = cfg.plugins.allow || [];
|
|
530
|
+
if (!allow.includes("opencompress")) {
|
|
531
|
+
cfg.plugins.allow = [...allow, "opencompress"];
|
|
532
|
+
changed = true;
|
|
533
|
+
}
|
|
534
|
+
if (changed) {
|
|
535
|
+
fs.writeFileSync(configPath, JSON.stringify(cfg, null, 2) + "\n");
|
|
536
|
+
api.logger.info("OpenCompress: injected provider + models into config");
|
|
537
|
+
}
|
|
538
|
+
const agentsDir = path.join(os.homedir(), ".openclaw", "agents");
|
|
539
|
+
if (fs.existsSync(agentsDir)) {
|
|
540
|
+
for (const agent of fs.readdirSync(agentsDir)) {
|
|
541
|
+
const authPath = path.join(agentsDir, agent, "agent", "auth-profiles.json");
|
|
542
|
+
const authDir = path.dirname(authPath);
|
|
543
|
+
if (!fs.existsSync(authDir)) continue;
|
|
544
|
+
let profiles = { version: 1, profiles: {} };
|
|
545
|
+
if (fs.existsSync(authPath)) {
|
|
546
|
+
try {
|
|
547
|
+
profiles = JSON.parse(fs.readFileSync(authPath, "utf-8"));
|
|
548
|
+
} catch {
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
if (!profiles.profiles["opencompress:default"]) {
|
|
552
|
+
profiles.profiles["opencompress:default"] = {
|
|
553
|
+
type: "api_key",
|
|
554
|
+
provider: "opencompress",
|
|
555
|
+
key: occKey
|
|
556
|
+
};
|
|
557
|
+
fs.writeFileSync(authPath, JSON.stringify(profiles, null, 2) + "\n");
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
if (api.config.models?.providers) {
|
|
562
|
+
api.config.models.providers.opencompress = cfg.models.providers.opencompress;
|
|
563
|
+
}
|
|
564
|
+
} catch (err) {
|
|
565
|
+
api.logger.warn(`OpenCompress: config injection failed: ${err}`);
|
|
566
|
+
}
|
|
567
|
+
}
|
|
487
568
|
var plugin = {
|
|
488
569
|
id: "opencompress",
|
|
489
570
|
name: "OpenCompress",
|
|
@@ -492,6 +573,7 @@ var plugin = {
|
|
|
492
573
|
register(api) {
|
|
493
574
|
injectEnvVars(api);
|
|
494
575
|
api.registerProvider(createProvider(api));
|
|
576
|
+
injectConfig(api);
|
|
495
577
|
api.logger.info(`OpenCompress v${VERSION} registered`);
|
|
496
578
|
api.registerService({
|
|
497
579
|
id: "opencompress-proxy",
|