@opencompress/opencompress 1.5.2 → 1.6.0
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 +80 -1
- 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.
|
|
9
|
+
var VERSION = "1.6.0";
|
|
10
10
|
var DEFAULT_BASE_URL = "https://www.opencompress.ai/api";
|
|
11
11
|
function getApiKey(api) {
|
|
12
12
|
const auth = api.config.auth;
|
|
@@ -124,6 +124,79 @@ function persistModelsConfig(providerModels) {
|
|
|
124
124
|
} catch {
|
|
125
125
|
}
|
|
126
126
|
}
|
|
127
|
+
function persistAgentModelsJson(providerModels) {
|
|
128
|
+
try {
|
|
129
|
+
const os = __require("os");
|
|
130
|
+
const fs = __require("fs");
|
|
131
|
+
const path = __require("path");
|
|
132
|
+
const agentsDir = path.join(os.homedir(), ".openclaw", "agents");
|
|
133
|
+
if (!fs.existsSync(agentsDir)) return;
|
|
134
|
+
const agentDirs = fs.readdirSync(agentsDir);
|
|
135
|
+
for (const agent of agentDirs) {
|
|
136
|
+
const modelsPath = path.join(agentsDir, agent, "agent", "models.json");
|
|
137
|
+
const modelsDir = path.dirname(modelsPath);
|
|
138
|
+
if (!fs.existsSync(modelsDir)) continue;
|
|
139
|
+
let data = { providers: {} };
|
|
140
|
+
if (fs.existsSync(modelsPath)) {
|
|
141
|
+
try {
|
|
142
|
+
data = JSON.parse(fs.readFileSync(modelsPath, "utf-8"));
|
|
143
|
+
if (!data.providers || typeof data.providers !== "object") {
|
|
144
|
+
data.providers = {};
|
|
145
|
+
}
|
|
146
|
+
} catch {
|
|
147
|
+
data = { providers: {} };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
data.providers.opencompress = {
|
|
151
|
+
baseUrl: providerModels.baseUrl,
|
|
152
|
+
api: providerModels.api || "openai-completions",
|
|
153
|
+
apiKey: providerModels.apiKey || void 0,
|
|
154
|
+
models: providerModels.models.map((m) => ({
|
|
155
|
+
id: m.id,
|
|
156
|
+
name: m.name,
|
|
157
|
+
api: m.api || "openai-completions",
|
|
158
|
+
reasoning: m.reasoning ?? false,
|
|
159
|
+
input: m.input || ["text"],
|
|
160
|
+
cost: m.cost || { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 },
|
|
161
|
+
contextWindow: m.contextWindow || 2e5,
|
|
162
|
+
maxTokens: m.maxTokens || 8192
|
|
163
|
+
})),
|
|
164
|
+
...providerModels.headers ? { headers: providerModels.headers } : {}
|
|
165
|
+
};
|
|
166
|
+
fs.writeFileSync(modelsPath, JSON.stringify(data, null, 2) + "\n");
|
|
167
|
+
}
|
|
168
|
+
} catch {
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
function persistAgentAuthJson(apiKey) {
|
|
172
|
+
try {
|
|
173
|
+
const os = __require("os");
|
|
174
|
+
const fs = __require("fs");
|
|
175
|
+
const path = __require("path");
|
|
176
|
+
const agentsDir = path.join(os.homedir(), ".openclaw", "agents");
|
|
177
|
+
if (!fs.existsSync(agentsDir)) return;
|
|
178
|
+
const agentDirs = fs.readdirSync(agentsDir);
|
|
179
|
+
for (const agent of agentDirs) {
|
|
180
|
+
const authPath = path.join(agentsDir, agent, "agent", "auth.json");
|
|
181
|
+
const authDir = path.dirname(authPath);
|
|
182
|
+
if (!fs.existsSync(authDir)) continue;
|
|
183
|
+
let data = {};
|
|
184
|
+
if (fs.existsSync(authPath)) {
|
|
185
|
+
try {
|
|
186
|
+
data = JSON.parse(fs.readFileSync(authPath, "utf-8"));
|
|
187
|
+
} catch {
|
|
188
|
+
data = {};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
data.opencompress = {
|
|
192
|
+
type: "api_key",
|
|
193
|
+
key: apiKey
|
|
194
|
+
};
|
|
195
|
+
fs.writeFileSync(authPath, JSON.stringify(data, null, 2) + "\n");
|
|
196
|
+
}
|
|
197
|
+
} catch {
|
|
198
|
+
}
|
|
199
|
+
}
|
|
127
200
|
function persistAuthProfile(apiKey) {
|
|
128
201
|
try {
|
|
129
202
|
const os = __require("os");
|
|
@@ -229,7 +302,9 @@ var opencompressProvider = {
|
|
|
229
302
|
const onboardModels = buildProviderModels(DEFAULT_BASE_URL, llmKey, upstreamBaseUrl, void 0, data.apiKey);
|
|
230
303
|
const modelCount = FALLBACK_MODELS.length;
|
|
231
304
|
persistModelsConfig(onboardModels);
|
|
305
|
+
persistAgentModelsJson(onboardModels);
|
|
232
306
|
persistAuthProfile(data.apiKey);
|
|
307
|
+
persistAgentAuthJson(data.apiKey);
|
|
233
308
|
return {
|
|
234
309
|
profiles: [
|
|
235
310
|
{
|
|
@@ -282,9 +357,11 @@ var plugin = {
|
|
|
282
357
|
}
|
|
283
358
|
api.config.models.providers.opencompress = providerModels;
|
|
284
359
|
persistModelsConfig(providerModels);
|
|
360
|
+
persistAgentModelsJson(providerModels);
|
|
285
361
|
const apiKey = getApiKey(api);
|
|
286
362
|
if (apiKey) {
|
|
287
363
|
persistAuthProfile(apiKey);
|
|
364
|
+
persistAgentAuthJson(apiKey);
|
|
288
365
|
}
|
|
289
366
|
const modelCount = existingModels ? existingModels.length : FALLBACK_MODELS.length;
|
|
290
367
|
const source = existingModels ? "from existing providers" : "fallback";
|
|
@@ -375,6 +452,7 @@ var plugin = {
|
|
|
375
452
|
api.config.models.providers.opencompress = cleanModels;
|
|
376
453
|
}
|
|
377
454
|
persistModelsConfig(cleanModels);
|
|
455
|
+
persistAgentModelsJson(cleanModels);
|
|
378
456
|
try {
|
|
379
457
|
await fetch(`${baseUrl}/v1/byok`, {
|
|
380
458
|
method: "DELETE",
|
|
@@ -411,6 +489,7 @@ var plugin = {
|
|
|
411
489
|
api.config.models.providers.opencompress = updatedModels;
|
|
412
490
|
}
|
|
413
491
|
persistModelsConfig(updatedModels);
|
|
492
|
+
persistAgentModelsJson(updatedModels);
|
|
414
493
|
try {
|
|
415
494
|
await fetch(`${baseUrl}/v1/byok`, {
|
|
416
495
|
method: "POST",
|