(index: Map<string, Val>, query: string)
| 8 | type Val = { provider: { name: string }; info: Info }; |
| 9 | |
| 10 | function matchModelCandidates(index: Map<string, Val>, query: string): Val[] { |
| 11 | const q = query.toLowerCase(); |
| 12 | const distinct = new Map<string, Val>(); |
| 13 | for (const val of index.values()) distinct.set(`${val.provider.name}/${val.info.id}`, val); |
| 14 | const prefix: Val[] = []; |
| 15 | const substr: Val[] = []; |
| 16 | for (const val of distinct.values()) { |
| 17 | const id = val.info.id.toLowerCase(); |
| 18 | const full = `${val.provider.name}/${val.info.id}`.toLowerCase(); |
| 19 | if (id.startsWith(q) || full.startsWith(q)) prefix.push(val); |
| 20 | else if (id.includes(q) || full.includes(q)) substr.push(val); |
| 21 | } |
| 22 | return prefix.length > 0 ? prefix : substr; |
| 23 | } |
| 24 | |
| 25 | // Build an index the way the router does: each model under `${provider}/${id}` AND `${id}`. |
| 26 | function buildIndex(models: Array<{ provider: string; id: string }>): Map<string, Val> { |
no test coverage detected