omp-config-crypt 0.9.1 → 0.9.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "omp-config-crypt",
3
- "version": "0.9.1",
3
+ "version": "0.9.3",
4
4
  "description": "Universal cross-platform encrypted portability for omp config, extensions, and instructions",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -8,6 +8,7 @@
8
8
  import fs from "node:fs";
9
9
  import path from "node:path";
10
10
  import os from "node:os";
11
+ import { parseDocument } from "yaml";
11
12
 
12
13
  export function getAgentDir(customRoot) {
13
14
  return customRoot || process.env.OMP_CFG_ROOT || path.join(os.homedir(), ".omp", "agent");
@@ -230,6 +231,37 @@ export function ensureLocalExtension(ompDir) {
230
231
  */
231
232
  export function parseYamlModels(str) {
232
233
  if (!str || typeof str !== "string") return {};
234
+ // Prefer the yaml package: handles flow-style (braces) and block-list values
235
+ // (e.g. `input:` followed by `- text` lines) the line parser cannot.
236
+ const parsed = normalizeProviderInputs(parseFlowYamlModels(str));
237
+ if (Object.keys(parsed).length) return parsed;
238
+ return normalizeProviderInputs(parseBlockYamlModels(str));
239
+ }
240
+
241
+ function normalizeProviderInputs(providers) {
242
+ for (const cfg of Object.values(providers || {})) {
243
+ for (const model of cfg?.models || []) {
244
+ if (typeof model.input === "string" && model.input) model.input = [model.input];
245
+ }
246
+ }
247
+ return providers;
248
+ }
249
+
250
+ function parseFlowYamlModels(str) {
251
+ let doc;
252
+ try {
253
+ doc = parseDocument(str, { indent: true });
254
+ if (doc.errors.length) return {};
255
+ } catch {
256
+ return {};
257
+ }
258
+ const data = doc.toJS();
259
+ const providers = data && typeof data === "object" && !Array.isArray(data) ? data.providers : null;
260
+ if (!providers || typeof providers !== "object" || Array.isArray(providers)) return {};
261
+ return providers;
262
+ }
263
+
264
+ function parseBlockYamlModels(str) {
233
265
  const lines = str.split("\n");
234
266
  const providers = {};
235
267
  let curProvider = null;
@@ -555,26 +587,41 @@ function assertSupportedProviders(providers) {
555
587
  function assertPublicSource(agentDir) {
556
588
  const file = ["models.yml", "models.yaml"].map(name => path.join(agentDir, name)).find(name => fs.existsSync(name));
557
589
  if (!file) return;
590
+ const text = fs.readFileSync(file, "utf8");
591
+ // The fixed-field formatter cannot preserve arbitrary YAML. Reject unfamiliar structure,
592
+ // unless the yaml package can parse it into the providers mapping (the next write
593
+ // re-serializes everything in canonical block style anyway).
594
+ try {
595
+ scanBlockSource(text);
596
+ } catch (blockError) {
597
+ if (!parseFlowYamlModels(text) || !Object.keys(parseFlowYamlModels(text)).length) throw blockError;
598
+ assertSupportedProviders(parseFlowYamlModels(text));
599
+ return;
600
+ }
601
+ assertSupportedProviders(readPublicProviders(agentDir));
602
+ }
603
+ function scanBlockSource(text) {
558
604
  // The fixed-field formatter cannot preserve arbitrary YAML. Reject unfamiliar structure.
559
605
  let section = "", provider = "";
560
- for (const line of fs.readFileSync(file, "utf8").split("\n")) {
561
- const text = line.trim();
562
- if (!text || text.startsWith("#")) continue;
606
+ for (const line of text.split("\n")) {
607
+ const trimmed = line.trim();
608
+ if (!trimmed || trimmed.startsWith("#")) continue;
563
609
  const indent = line.search(/\S/);
564
- const field = text.replace(/^-\s*/, "").split(":")[0];
565
- if (indent === 0 && text === "providers:") { section = "providers"; continue; }
566
- if (indent === 2 && /^[A-Za-z0-9][A-Za-z0-9_-]*:$/.test(text)) { provider = field; section = "provider"; continue; }
610
+ const field = trimmed.replace(/^-\s*/, "").split(":")[0];
611
+ if (indent === 0 && trimmed === "providers:") { section = "providers"; continue; }
612
+ if (indent === 2 && /^[A-Za-z0-9][A-Za-z0-9_-]*:$/.test(trimmed)) { provider = field; section = "provider"; continue; }
567
613
  if (provider && indent === 4 && PROVIDER_FIELDS.has(field)) {
568
- section = field === "models" && text === "models:" ? "models" : "provider";
569
- if (section === "provider" && field !== "apiKey" && !text.slice(text.indexOf(":") + 1).trim()) unsupported(`${provider}.${field}`);
614
+ section = field === "models" && trimmed === "models:" ? "models" : "provider";
615
+ if (section === "provider" && field !== "apiKey" && !trimmed.slice(trimmed.indexOf(":") + 1).trim()) unsupported(`${provider}.${field}`);
570
616
  continue;
571
617
  }
572
618
  if (section === "models" || section === "model" || section === "compat") {
573
- if (indent === 6 && text.startsWith("- ") && field === "id") { section = "model"; continue; }
619
+ if (indent === 6 && trimmed.startsWith("- ") && field === "id") { section = "model"; continue; }
574
620
  if (indent === 8 && MODEL_FIELDS.has(field)) { section = field === "compat" ? "compat" : "model"; continue; }
575
- if (indent === 10 && section === "compat" && /^[A-Za-z0-9_-]+:\s*\S/.test(text)) continue;
621
+ if (section === "model" && indent === 10 && trimmed.startsWith("- ")) continue;
622
+ if (indent === 10 && section === "compat" && /^[A-Za-z0-9_-]+:\s*\S/.test(trimmed)) continue;
576
623
  }
577
624
  unsupported(`${provider || "root"}.${field}`);
578
625
  }
579
- assertSupportedProviders(readPublicProviders(agentDir));
580
626
  }
627
+