88 lines
3.2 KiB
TypeScript
88 lines
3.2 KiB
TypeScript
import axios from 'axios';
|
|
import dotenv from 'dotenv';
|
|
import { QuotaEntry } from './db';
|
|
|
|
dotenv.config();
|
|
|
|
export async function fetchAntigravityQuota(): Promise<QuotaEntry> {
|
|
try {
|
|
const url = process.env.ANTIGRAVITY_ENDPOINT || 'https://api.antigravity.google/v1/quota';
|
|
const res = await axios.get(url, {
|
|
headers: {
|
|
'Authorization': `Bearer ${process.env.ANTIGRAVITY_API_KEY}`
|
|
}
|
|
});
|
|
|
|
// Assuming response structure: { used: number, total: number }
|
|
const used = res.data.used || 0;
|
|
const total = res.data.total || 1000;
|
|
const percentage = (used / total) * 100;
|
|
|
|
return { provider: 'Antigravity', used, total, percentage };
|
|
} catch (error: any) {
|
|
console.error('Error fetching Antigravity quota:', error.message);
|
|
// Fallback for demonstration / local testing if endpoint is mocked
|
|
return { provider: 'Antigravity', used: 0, total: 100, percentage: 0 };
|
|
}
|
|
}
|
|
|
|
export async function fetchPoeQuota(): Promise<QuotaEntry> {
|
|
try {
|
|
const res = await axios.get('https://api.poe.com/usage/current_balance', {
|
|
headers: {
|
|
'Authorization': `Bearer ${process.env.POE_API_KEY}`
|
|
}
|
|
});
|
|
|
|
const available = res.data.current_point_balance || 0;
|
|
const total = 2500000;
|
|
const used = total - available > 0 ? total - available : 0;
|
|
const percentage = (used / total) * 100;
|
|
|
|
return { provider: 'POE', used, total, percentage };
|
|
} catch (error: any) {
|
|
console.error('Error fetching POE quota:', error.message);
|
|
return { provider: 'POE', used: 0, total: 2500000, percentage: 0 };
|
|
}
|
|
}
|
|
|
|
export async function fetchMinimaxQuota(): Promise<QuotaEntry> {
|
|
try {
|
|
const res = await axios.get('https://api.minimax.io/v1/api/openplatform/coding_plan/remains', {
|
|
headers: {
|
|
'Authorization': `Bearer ${process.env.MINIMAX_API_KEY}`
|
|
}
|
|
});
|
|
|
|
const remains = res.data.model_remains?.find((r: any) => r.model_name === 'general');
|
|
const intervalUsed = remains ? (100 - remains.current_interval_remaining_percent) : 0;
|
|
const weeklyUsed = remains ? (100 - remains.current_weekly_remaining_percent) : 0;
|
|
|
|
// Use the highest percentage for the progress bar logic
|
|
const percentage = Math.max(intervalUsed, weeklyUsed);
|
|
const used = percentage;
|
|
const total = 100;
|
|
|
|
const meta = {
|
|
intervalUsed,
|
|
weeklyUsed,
|
|
intervalReset: remains ? remains.end_time : null,
|
|
weeklyReset: remains ? remains.weekly_end_time : null
|
|
};
|
|
|
|
return { provider: 'MiniMax', used, total, percentage, meta };
|
|
} catch (error: any) {
|
|
console.error('Error fetching MiniMax quota:', error.message);
|
|
return { provider: 'MiniMax', used: 0, total: 100, percentage: 0 };
|
|
}
|
|
}
|
|
|
|
export async function fetchAllQuotas(): Promise<QuotaEntry[]> {
|
|
const results = await Promise.all([
|
|
fetchAntigravityQuota(),
|
|
fetchPoeQuota(),
|
|
fetchMinimaxQuota()
|
|
]);
|
|
return results;
|
|
}
|