MCPcopy Index your code
hub / github.com/Microck/opencode-studio / aggregateModels

Function aggregateModels

server/index.js:991–1032  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

989};
990
991const aggregateModels = () => {
992 const roots = getSearchRoots();
993 const activeConfigPath = getConfigPath();
994 const activeDir = activeConfigPath ? path.dirname(activeConfigPath) : null;
995
996 const providerMap = new Map();
997
998 for (const root of roots) {
999 const configPath = path.join(root, 'opencode.json');
1000
1001 if (!fs.existsSync(configPath)) continue;
1002
1003 try {
1004 const config = JSON.parse(fs.readFileSync(configPath, 'utf8'));
1005
1006 let providers = null;
1007
1008 if (config.model && config.model.providers) {
1009 providers = config.model.providers;
1010 } else if (config.providers) {
1011 providers = config.providers;
1012 }
1013
1014 if (providers && typeof providers === 'object') {
1015 for (const [providerName, providerConfig] of Object.entries(providers)) {
1016 if (!providerMap.has(providerName)) {
1017 providerMap.set(providerName, {
1018 name: providerName,
1019 config: providerConfig,
1020 source: 'json-config',
1021 configPath: root
1022 });
1023 }
1024 }
1025 }
1026 } catch (err) {
1027 console.warn(`Failed to read config from ${configPath}:`, err.message);
1028 }
1029 }
1030
1031 return Array.from(providerMap.values());
1032};
1033
1034const loadAggregatedConfig = () => {
1035 const roots = getSearchRoots();

Callers 1

index.jsFile · 0.85

Calls 2

getSearchRootsFunction · 0.85
getConfigPathFunction · 0.85

Tested by

no test coverage detected