MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / matchModelCandidates

Function matchModelCandidates

test/model-resolve.test.ts:10–23  ·  view source on GitHub ↗
(index: Map<string, Val>, query: string)

Source from the content-addressed store, hash-verified

8type Val = { provider: { name: string }; info: Info };
9
10function 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}`.
26function buildIndex(models: Array<{ provider: string; id: string }>): Map<string, Val> {

Callers 1

Calls 2

setMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected