Implements modular provider probing with two distinct header schemas: - Teams direct (unified schema): 5h/7d utilization floats, status, reset countdown - Shelley proxy (classic schema): token/request counts + Exedev-Gateway-Cost (USD/call) - api-ateam: reports no billing data (confirmed non-existent by recon) Key: uses claude-haiku-4-5-20251001 for minimal probe calls (1 token). Rate-limit headers present on ALL responses (200 and 429). 113/113 tests passing. Built from Face recon (trentuna/a-team#91) — live header capture confirmed unified schema with utilization floats replaces old per-count schema.
47 lines
1.3 KiB
JavaScript
47 lines
1.3 KiB
JavaScript
/**
|
|
* providers/index.js — provider registry
|
|
*
|
|
* Reads ~/.pi/agent/models.json and returns typed provider config for all
|
|
* providers we know how to probe. Non-anthropic-messages providers (e.g. zai)
|
|
* are silently skipped.
|
|
*/
|
|
|
|
import { readFileSync } from 'fs';
|
|
import { homedir } from 'os';
|
|
|
|
/**
|
|
* Classify a provider by name and config.
|
|
* @returns {'teams-direct'|'shelley-proxy'|'api-direct'|null}
|
|
*/
|
|
function classifyProvider(name, config) {
|
|
if (name === 'shelley-proxy') return 'shelley-proxy';
|
|
if (name === 'api-ateam') return 'api-direct';
|
|
if (config.api === 'anthropic-messages' && name.startsWith('team-')) return 'teams-direct';
|
|
return null; // skip (zai, etc.)
|
|
}
|
|
|
|
/**
|
|
* Load and classify all providers from models.json.
|
|
* @returns {Object} map of provider name → { name, type, baseUrl, apiKey }
|
|
*/
|
|
export function getProviders() {
|
|
const modelsJson = JSON.parse(
|
|
readFileSync(`${homedir()}/.pi/agent/models.json`, 'utf-8')
|
|
);
|
|
|
|
const providers = {};
|
|
for (const [name, config] of Object.entries(modelsJson.providers)) {
|
|
const type = classifyProvider(name, config);
|
|
if (!type) continue;
|
|
providers[name] = {
|
|
name,
|
|
type,
|
|
baseUrl: config.baseUrl,
|
|
apiKey: config.apiKey || null,
|
|
};
|
|
}
|
|
return providers;
|
|
}
|
|
|
|
// Alias for backwards compatibility
|
|
export const loadProviders = getProviders;
|