(yamlText: string)
| 74 | } |
| 75 | |
| 76 | function parseExistingModels(yamlText: string): ExistingByProvider { |
| 77 | const doc = parseDocument(yamlText); |
| 78 | if (doc.contents == null) { |
| 79 | return {}; |
| 80 | } |
| 81 | if (!isMap(doc.contents)) { |
| 82 | throw new Error( |
| 83 | "Expected a map at the root of models.yml (keyed by provider)", |
| 84 | ); |
| 85 | } |
| 86 | const result: Record<string, ExistingEntry[]> = {}; |
| 87 | for (const pair of (doc.contents as YAMLMap).items) { |
| 88 | const provider = (pair.key as { value?: unknown })?.value; |
| 89 | if (typeof provider !== "string") { |
| 90 | continue; |
| 91 | } |
| 92 | if (!isSeq(pair.value)) { |
| 93 | result[provider] = []; |
| 94 | continue; |
| 95 | } |
| 96 | const entries: ExistingEntry[] = []; |
| 97 | for (const item of (pair.value as YAMLSeq).items) { |
| 98 | if (!isMap(item)) { |
| 99 | continue; |
| 100 | } |
| 101 | for (const subPair of (item as YAMLMap).items) { |
| 102 | const key = (subPair.key as { value?: unknown })?.value; |
| 103 | const value = (subPair.value as { value?: unknown })?.value; |
| 104 | if (key === "model" && typeof value === "string") { |
| 105 | entries.push({ model: value }); |
| 106 | break; |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | result[provider] = entries; |
| 111 | } |
| 112 | return result; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Build a `YAMLMap` for one entry with the right flow-style array fields. |
no test coverage detected
searching dependent graphs…