omp-config-crypt 0.5.4 → 0.5.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/index.js +36 -2
- package/package.json +1 -1
- package/src/provider-store.js +11 -26
package/index.js
CHANGED
|
@@ -36,6 +36,8 @@ import {
|
|
|
36
36
|
readPrivateProviders,
|
|
37
37
|
writePrivateProviders,
|
|
38
38
|
ensureLocalExtension,
|
|
39
|
+
parseYamlModels,
|
|
40
|
+
formatYamlModels,
|
|
39
41
|
} from "./src/provider-store.js";
|
|
40
42
|
import { getRoles, setRole, VALID_ROLES } from "./src/role-manager.js";
|
|
41
43
|
|
|
@@ -241,8 +243,22 @@ export function buildArchive(pass, root = configRoot()) {
|
|
|
241
243
|
const homePosix = home.replace(/\\/g, "/");
|
|
242
244
|
|
|
243
245
|
const files = items.map(({ rel, abs }) => {
|
|
244
|
-
|
|
246
|
+
let raw = fs.readFileSync(abs);
|
|
245
247
|
const mode = fs.statSync(abs).mode & 0o777;
|
|
248
|
+
|
|
249
|
+
// Sanitize private providers from models.yml so they are never exported to cloud
|
|
250
|
+
if (rel === "models.yml" || rel === "models.yaml") {
|
|
251
|
+
try {
|
|
252
|
+
const providers = parseYamlModels(raw.toString("utf8"));
|
|
253
|
+
const publicProviders = {};
|
|
254
|
+
for (const [name, cfg] of Object.entries(providers)) {
|
|
255
|
+
if (!cfg.private) {
|
|
256
|
+
publicProviders[name] = cfg;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
raw = Buffer.from(formatYamlModels(publicProviders), "utf8");
|
|
260
|
+
} catch {}
|
|
261
|
+
}
|
|
246
262
|
let data;
|
|
247
263
|
if (isText(raw)) {
|
|
248
264
|
let str = raw.toString("utf8");
|
|
@@ -337,8 +353,26 @@ export function restoreArchive(blob, pass, root = configRoot(), options = {}) {
|
|
|
337
353
|
buf = Buffer.from(str, "utf8");
|
|
338
354
|
}
|
|
339
355
|
}
|
|
340
|
-
|
|
341
356
|
const exists = fs.existsSync(dst);
|
|
357
|
+
|
|
358
|
+
// Intelligently merge existing local private providers in models.yml so they are never overwritten
|
|
359
|
+
if ((rel === "models.yml" || rel === "models.yaml") && exists) {
|
|
360
|
+
try {
|
|
361
|
+
const existingRaw = fs.readFileSync(dst, "utf8");
|
|
362
|
+
const existingProviders = parseYamlModels(existingRaw);
|
|
363
|
+
const privateProviders = {};
|
|
364
|
+
for (const [name, cfg] of Object.entries(existingProviders)) {
|
|
365
|
+
if (cfg.private) {
|
|
366
|
+
privateProviders[name] = cfg;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (Object.keys(privateProviders).length > 0) {
|
|
370
|
+
const incomingProviders = parseYamlModels(buf.toString("utf8"));
|
|
371
|
+
const merged = { ...incomingProviders, ...privateProviders };
|
|
372
|
+
buf = Buffer.from(formatYamlModels(merged), "utf8");
|
|
373
|
+
}
|
|
374
|
+
} catch {}
|
|
375
|
+
}
|
|
342
376
|
actions.push({ path: rel, dest: dst, exists, remapped });
|
|
343
377
|
|
|
344
378
|
if (!dryRun) {
|
package/package.json
CHANGED
package/src/provider-store.js
CHANGED
|
@@ -165,6 +165,7 @@ export function formatYamlModels(providers) {
|
|
|
165
165
|
let out = "providers:\n";
|
|
166
166
|
for (const [name, cfg] of Object.entries(providers || {})) {
|
|
167
167
|
out += ` ${name}:\n`;
|
|
168
|
+
if (cfg.private) out += ` private: true\n`;
|
|
168
169
|
if (cfg.baseUrl) out += ` baseUrl: ${cfg.baseUrl}\n`;
|
|
169
170
|
if (cfg.api) out += ` api: ${cfg.api}\n`;
|
|
170
171
|
if (cfg.apiKey) out += ` apiKey: ${cfg.apiKey}\n`;
|
|
@@ -257,6 +258,7 @@ export function saveProvider({
|
|
|
257
258
|
}
|
|
258
259
|
|
|
259
260
|
const cleanConfig = {
|
|
261
|
+
private: Boolean(isPrivate),
|
|
260
262
|
baseUrl: providerConfig.baseUrl,
|
|
261
263
|
api: providerConfig.api || "openai-completions",
|
|
262
264
|
apiKey: providerConfig.apiKey || "",
|
|
@@ -264,26 +266,18 @@ export function saveProvider({
|
|
|
264
266
|
models: Array.isArray(providerConfig.models) ? providerConfig.models : [],
|
|
265
267
|
};
|
|
266
268
|
|
|
267
|
-
|
|
269
|
+
// Always save to models.yml so OMP /model natively sees and uses it
|
|
270
|
+
const pub = readPublicProviders(agentDir);
|
|
271
|
+
pub[name] = cleanConfig;
|
|
272
|
+
writePublicProviders(agentDir, pub);
|
|
268
273
|
|
|
274
|
+
// Also record in models.local.json for redundancy
|
|
269
275
|
if (isPrivate) {
|
|
270
276
|
const priv = readPrivateProviders(agentDir);
|
|
271
277
|
priv[name] = cleanConfig;
|
|
272
278
|
writePrivateProviders(agentDir, priv);
|
|
273
|
-
ensureLocalExtension(
|
|
274
|
-
|
|
275
|
-
// If it existed in public, remove from public to prevent duplicate
|
|
276
|
-
const pub = readPublicProviders(agentDir);
|
|
277
|
-
if (pub[name]) {
|
|
278
|
-
delete pub[name];
|
|
279
|
-
writePublicProviders(agentDir, pub);
|
|
280
|
-
}
|
|
279
|
+
ensureLocalExtension(getOmpDir(agentDir));
|
|
281
280
|
} else {
|
|
282
|
-
const pub = readPublicProviders(agentDir);
|
|
283
|
-
pub[name] = cleanConfig;
|
|
284
|
-
writePublicProviders(agentDir, pub);
|
|
285
|
-
|
|
286
|
-
// If it existed in private, remove from private
|
|
287
281
|
const priv = readPrivateProviders(agentDir);
|
|
288
282
|
if (priv[name]) {
|
|
289
283
|
delete priv[name];
|
|
@@ -323,22 +317,13 @@ export function removeProvider({ name, agentDir = getAgentDir() }) {
|
|
|
323
317
|
export function listProviders({ agentDir = getAgentDir() } = {}) {
|
|
324
318
|
const pub = readPublicProviders(agentDir);
|
|
325
319
|
const priv = readPrivateProviders(agentDir);
|
|
320
|
+
const merged = { ...priv, ...pub };
|
|
326
321
|
|
|
327
322
|
const list = [];
|
|
328
|
-
for (const [name, cfg] of Object.entries(
|
|
329
|
-
list.push({
|
|
330
|
-
name,
|
|
331
|
-
isPrivate: false,
|
|
332
|
-
baseUrl: cfg.baseUrl,
|
|
333
|
-
api: cfg.api,
|
|
334
|
-
apiKey: cfg.apiKey,
|
|
335
|
-
models: cfg.models || [],
|
|
336
|
-
});
|
|
337
|
-
}
|
|
338
|
-
for (const [name, cfg] of Object.entries(priv)) {
|
|
323
|
+
for (const [name, cfg] of Object.entries(merged)) {
|
|
339
324
|
list.push({
|
|
340
325
|
name,
|
|
341
|
-
isPrivate:
|
|
326
|
+
isPrivate: Boolean(cfg.private || priv[name]),
|
|
342
327
|
baseUrl: cfg.baseUrl,
|
|
343
328
|
api: cfg.api,
|
|
344
329
|
apiKey: cfg.apiKey,
|