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

Function buildAccountPool

server/index.js:3594–3662  ·  view source on GitHub ↗
(provider)

Source from the content-addressed store, hash-verified

3592}
3593
3594function buildAccountPool(provider) {
3595 const activePlugin = getActiveGooglePlugin();
3596 const namespace = provider === 'google'
3597 ? ('google.antigravity')
3598 : provider;
3599
3600 const profileDir = getProfileDir(provider, activePlugin);
3601
3602 const profiles = [];
3603 const now = Date.now();
3604 const metadata = loadPoolMetadata();
3605 const providerMeta = metadata[namespace] || metadata[provider] || {};
3606
3607 // Get current active profile from studio config
3608 const studio = loadStudioConfig();
3609 const activeProfile = studio.activeProfiles?.[provider] || null;
3610
3611 if (fs.existsSync(profileDir)) {
3612 const files = fs.readdirSync(profileDir).filter(f => f.endsWith('.json'));
3613 files.forEach(file => {
3614 const name = file.replace('.json', '');
3615 const meta = providerMeta[name] || {};
3616 let profileEmail = null;
3617 let projectId = null;
3618 let tier = null;
3619 try {
3620 const raw = fs.readFileSync(path.join(profileDir, file), 'utf8');
3621 const parsed = JSON.parse(raw);
3622 profileEmail = parsed?.email || null;
3623 projectId = parsed?.projectId || null;
3624 tier = parsed?.tier || null;
3625 } catch {}
3626 let status = getAccountStatus(meta, now);
3627 if (name === activeProfile && status === 'ready') status = 'active';
3628
3629 profiles.push({
3630 name,
3631 email: meta.email || profileEmail || null,
3632 status,
3633 lastUsed: meta.lastUsed || 0,
3634 usageCount: meta.usageCount || 0,
3635 cooldownUntil: meta.cooldownUntil || null,
3636 createdAt: meta.createdAt || 0,
3637 projectId,
3638 tier
3639 });
3640 });
3641 }
3642
3643 // Sort: active first, then by lastUsed (LRU)
3644 profiles.sort((a, b) => {
3645 if (a.status === 'active') return -1;
3646 if (b.status === 'active') return 1;
3647 return a.lastUsed - b.lastUsed;
3648 });
3649
3650 const available = profiles.filter(p => p.status === 'active' || p.status === 'ready').length;
3651 const cooldown = profiles.filter(p => p.status === 'cooldown').length;

Callers 2

rotateAccountFunction · 0.85
index.jsFile · 0.85

Calls 5

getProfileDirFunction · 0.85
loadPoolMetadataFunction · 0.85
loadStudioConfigFunction · 0.85
getAccountStatusFunction · 0.85
getActiveGooglePluginFunction · 0.70

Tested by

no test coverage detected