adapt to new api
This commit is contained in:
1 parent
35da5bb8a0
commit
9f77975766
5 files changed
+239
-50
No files matched your search
+78
-36
@@ -1,5 +1,5 @@
|
||||
import * as vscode from 'vscode';
|
||||
import { QuotaResponse, QuotaDisplay, QUOTA_LIMITS } from './types';
|
||||
import { QuotaResponse, QuotaDisplay } from './types';
|
||||
|
||||
export class StatusBarManager {
|
||||
private statusBarItem: vscode.StatusBarItem;
|
||||
@@ -28,8 +28,8 @@ export class StatusBarManager {
|
||||
}
|
||||
|
||||
updateWithQuota(data: QuotaDisplay): void {
|
||||
const domesticPercent = Math.round(data.domestic.percent);
|
||||
const globalPercent = Math.round(data.global.percent);
|
||||
const domesticPercent = Math.round(data.domestic.daily.percent);
|
||||
const globalPercent = Math.round(data.global.monthly.percent);
|
||||
|
||||
this.statusBarItem.text = `$(cloud) 国内 ${domesticPercent}% | 国外 ${globalPercent}%`;
|
||||
this.statusBarItem.tooltip = this.generateTooltipMarkdown(data);
|
||||
@@ -52,16 +52,19 @@ export class StatusBarManager {
|
||||
md.appendMarkdown(`${data.user.email}\n\n`);
|
||||
md.appendMarkdown('---\n\n');
|
||||
|
||||
const domesticWarning = data.domestic.percent > 80 ? '⚠️ ' : '';
|
||||
md.appendMarkdown(`#### ${domesticWarning}国内模型用量\n\n`);
|
||||
md.appendMarkdown(`\`${getProgressBar(data.domestic.percent)}\` \`${formatPercent(data.domestic.percent)}%\`\n\n`);
|
||||
md.appendMarkdown(`已用 **${formatNumber(data.domestic.used)}** / ${formatNumber(data.domestic.total)}\n\n`);
|
||||
const domesticDailyWarning = data.domestic.daily.percent > 80 ? '⚠️ ' : '';
|
||||
md.appendMarkdown(`#### ${domesticDailyWarning}${data.domestic.label} (日额度)\n\n`);
|
||||
md.appendMarkdown(`\`${getProgressBar(data.domestic.daily.percent)}\` \`${formatPercent(data.domestic.daily.percent)}%\`\n\n`);
|
||||
md.appendMarkdown(`已用 **${formatNumber(data.domestic.daily.used)}** / ${formatNumber(data.domestic.daily.total)}\n\n`);
|
||||
if (data.domestic.hasMonthlyLimit) {
|
||||
md.appendMarkdown(`月额度: ${formatPercent(data.domestic.monthly.percent)}% (${formatNumber(data.domestic.monthly.used)} / ${formatNumber(data.domestic.monthly.total)})\n\n`);
|
||||
}
|
||||
md.appendMarkdown(`支持模型: ${data.domestic.models.map(m => `\`${m}\``).join(' ')}\n\n`);
|
||||
|
||||
const globalWarning = data.global.percent > 80 ? '⚠️ ' : '';
|
||||
md.appendMarkdown(`#### ${globalWarning}国外模型用量\n\n`);
|
||||
md.appendMarkdown(`\`${getProgressBar(data.global.percent)}\` \`${formatPercent(data.global.percent)}%\`\n\n`);
|
||||
md.appendMarkdown(`已用 **${formatNumber(data.global.used)}** / ${formatNumber(data.global.total)}\n\n`);
|
||||
const globalWarning = data.global.monthly.percent > 80 ? '⚠️ ' : '';
|
||||
md.appendMarkdown(`#### ${globalWarning}${data.global.label}\n\n`);
|
||||
md.appendMarkdown(`\`${getProgressBar(data.global.monthly.percent)}\` \`${formatPercent(data.global.monthly.percent)}%\`\n\n`);
|
||||
md.appendMarkdown(`已用 **${formatNumber(data.global.monthly.used)}** / ${formatNumber(data.global.monthly.total)}\n\n`);
|
||||
md.appendMarkdown(`支持模型: ${data.global.models.map(m => `\`${m}\``).join(' ')}\n\n`);
|
||||
|
||||
md.appendMarkdown('---\n\n');
|
||||
@@ -178,15 +181,20 @@ export class StatusBarManager {
|
||||
margin: 0 0 12px 0;
|
||||
font-size: 16px;
|
||||
}
|
||||
.quota-stats {
|
||||
.quota-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 12px;
|
||||
margin-bottom: 12px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
.quota-label {
|
||||
min-width: 60px;
|
||||
color: var(--vscode-descriptionForeground);
|
||||
}
|
||||
.quota-percent {
|
||||
font-size: 28px;
|
||||
font-size: 20px;
|
||||
font-weight: bold;
|
||||
min-width: 70px;
|
||||
}
|
||||
.quota-details {
|
||||
color: var(--vscode-descriptionForeground);
|
||||
@@ -208,6 +216,7 @@ export class StatusBarManager {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 8px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.model-tag {
|
||||
padding: 4px 8px;
|
||||
@@ -247,32 +256,54 @@ export class StatusBarManager {
|
||||
</div>
|
||||
|
||||
<div class="quota-section">
|
||||
<h2>国内模型用量</h2>
|
||||
<div class="quota-stats">
|
||||
<span class="quota-percent ${data.domestic.percent > 80 ? 'warning' : ''}">${formatPercent(data.domestic.percent)}%</span>
|
||||
<span class="quota-details">
|
||||
已用 ${formatNumber(data.domestic.used)} / ${formatNumber(data.domestic.total)}
|
||||
</span>
|
||||
<h2>${data.domestic.label}</h2>
|
||||
${data.domestic.hasDailyLimit ? `
|
||||
<div class="quota-row">
|
||||
<span class="quota-label">日额度</span>
|
||||
<span class="quota-percent ${data.domestic.daily.percent > 80 ? 'warning' : ''}">${formatPercent(data.domestic.daily.percent)}%</span>
|
||||
<span class="quota-details">已用 ${formatNumber(data.domestic.daily.used)} / ${formatNumber(data.domestic.daily.total)}</span>
|
||||
</div>
|
||||
<div class="progress-container">
|
||||
<div class="progress-bar ${data.domestic.percent > 80 ? 'progress-warning' : 'progress-ok'}" style="width: ${Math.min(data.domestic.percent, 100)}%;"></div>
|
||||
<div class="progress-bar ${data.domestic.daily.percent > 80 ? 'progress-warning' : 'progress-ok'}" style="width: ${Math.min(data.domestic.daily.percent, 100)}%;"></div>
|
||||
</div>
|
||||
` : ''}
|
||||
${data.domestic.hasMonthlyLimit ? `
|
||||
<div class="quota-row">
|
||||
<span class="quota-label">月额度</span>
|
||||
<span class="quota-percent ${data.domestic.monthly.percent > 80 ? 'warning' : ''}">${formatPercent(data.domestic.monthly.percent)}%</span>
|
||||
<span class="quota-details">已用 ${formatNumber(data.domestic.monthly.used)} / ${formatNumber(data.domestic.monthly.total)}</span>
|
||||
</div>
|
||||
<div class="progress-container">
|
||||
<div class="progress-bar ${data.domestic.monthly.percent > 80 ? 'progress-warning' : 'progress-ok'}" style="width: ${Math.min(data.domestic.monthly.percent, 100)}%;"></div>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="models-list">
|
||||
${data.domestic.models.map(m => `<span class="model-tag">${m}</span>`).join('')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="quota-section">
|
||||
<h2>国外模型用量</h2>
|
||||
<div class="quota-stats">
|
||||
<span class="quota-percent ${data.global.percent > 80 ? 'warning' : ''}">${formatPercent(data.global.percent)}%</span>
|
||||
<span class="quota-details">
|
||||
已用 ${formatNumber(data.global.used)} / ${formatNumber(data.global.total)}
|
||||
</span>
|
||||
<h2>${data.global.label}</h2>
|
||||
${data.global.hasDailyLimit ? `
|
||||
<div class="quota-row">
|
||||
<span class="quota-label">日额度</span>
|
||||
<span class="quota-percent ${data.global.daily.percent > 80 ? 'warning' : ''}">${formatPercent(data.global.daily.percent)}%</span>
|
||||
<span class="quota-details">已用 ${formatNumber(data.global.daily.used)} / ${formatNumber(data.global.daily.total)}</span>
|
||||
</div>
|
||||
<div class="progress-container">
|
||||
<div class="progress-bar ${data.global.percent > 80 ? 'progress-warning' : 'progress-ok'}" style="width: ${Math.min(data.global.percent, 100)}%;"></div>
|
||||
<div class="progress-bar ${data.global.daily.percent > 80 ? 'progress-warning' : 'progress-ok'}" style="width: ${Math.min(data.global.daily.percent, 100)}%;"></div>
|
||||
</div>
|
||||
` : ''}
|
||||
${data.global.hasMonthlyLimit ? `
|
||||
<div class="quota-row">
|
||||
<span class="quota-label">月额度</span>
|
||||
<span class="quota-percent ${data.global.monthly.percent > 80 ? 'warning' : ''}">${formatPercent(data.global.monthly.percent)}%</span>
|
||||
<span class="quota-details">已用 ${formatNumber(data.global.monthly.used)} / ${formatNumber(data.global.monthly.total)}</span>
|
||||
</div>
|
||||
<div class="progress-container">
|
||||
<div class="progress-bar ${data.global.monthly.percent > 80 ? 'progress-warning' : 'progress-ok'}" style="width: ${Math.min(data.global.monthly.percent, 100)}%;"></div>
|
||||
</div>
|
||||
` : ''}
|
||||
<div class="models-list">
|
||||
${data.global.models.map(m => `<span class="model-tag">${m}</span>`).join('')}
|
||||
</div>
|
||||
@@ -302,19 +333,30 @@ export function parseQuotaResponse(response: QuotaResponse): QuotaDisplay {
|
||||
const domestic = response.groups.find(g => g.key === 'domestic')!;
|
||||
const global = response.groups.find(g => g.key === 'global')!;
|
||||
|
||||
const parseQuota = (usedStr: string, totalStr: string) => {
|
||||
const used = parseFloat(usedStr) || 0;
|
||||
const total = parseFloat(totalStr) || 1;
|
||||
const percent = total > 0 ? (used / total) * 100 : 0;
|
||||
return { used, total, percent };
|
||||
};
|
||||
|
||||
return {
|
||||
user: response.user,
|
||||
domestic: {
|
||||
used: QUOTA_LIMITS.domestic - domestic.remaining_tokens,
|
||||
total: QUOTA_LIMITS.domestic,
|
||||
percent: ((QUOTA_LIMITS.domestic - domestic.remaining_tokens) / QUOTA_LIMITS.domestic) * 100,
|
||||
models: domestic.models
|
||||
label: domestic.label,
|
||||
models: domestic.models,
|
||||
hasDailyLimit: domestic.has_daily_limit,
|
||||
hasMonthlyLimit: domestic.has_monthly_limit,
|
||||
daily: parseQuota(domestic.usage.daily_amount, domestic.effective_daily_amount),
|
||||
monthly: parseQuota(domestic.usage.month_amount, domestic.effective_monthly_amount)
|
||||
},
|
||||
global: {
|
||||
used: QUOTA_LIMITS.global - global.remaining_tokens,
|
||||
total: QUOTA_LIMITS.global,
|
||||
percent: ((QUOTA_LIMITS.global - global.remaining_tokens) / QUOTA_LIMITS.global) * 100,
|
||||
models: global.models
|
||||
label: global.label,
|
||||
models: global.models,
|
||||
hasDailyLimit: global.has_daily_limit,
|
||||
hasMonthlyLimit: global.has_monthly_limit,
|
||||
daily: parseQuota(global.usage.daily_amount, global.effective_daily_amount),
|
||||
monthly: parseQuota(global.usage.month_amount, global.effective_monthly_amount)
|
||||
}
|
||||
};
|
||||
}
|
||||
+47
-13
@@ -4,12 +4,31 @@ export interface User {
|
||||
email: string;
|
||||
}
|
||||
|
||||
export interface Usage {
|
||||
total_tokens: number;
|
||||
daily_amount: string;
|
||||
month_amount: string;
|
||||
daily_amount_available: boolean;
|
||||
month_amount_available: boolean;
|
||||
unpriced_models: string[];
|
||||
}
|
||||
|
||||
export interface Group {
|
||||
key: 'domestic' | 'global';
|
||||
label: string;
|
||||
query_model: string;
|
||||
models: string[];
|
||||
remaining_tokens: number;
|
||||
default_daily_amount: string;
|
||||
effective_daily_amount: string;
|
||||
effective_monthly_amount: string;
|
||||
monthly_limit_amount: string;
|
||||
has_daily_limit: boolean;
|
||||
has_monthly_limit: boolean;
|
||||
remaining_daily_amount: string;
|
||||
remaining_monthly_amount: string;
|
||||
remaining_daily_ratio: number | null;
|
||||
remaining_monthly_ratio: number;
|
||||
remaining_ratio: number | null;
|
||||
usage: Usage;
|
||||
}
|
||||
|
||||
export interface QuotaResponse {
|
||||
@@ -25,20 +44,35 @@ export interface Credentials {
|
||||
export interface QuotaDisplay {
|
||||
user: User;
|
||||
domestic: {
|
||||
used: number;
|
||||
total: number;
|
||||
percent: number;
|
||||
label: string;
|
||||
models: string[];
|
||||
hasDailyLimit: boolean;
|
||||
hasMonthlyLimit: boolean;
|
||||
daily: {
|
||||
used: number;
|
||||
total: number;
|
||||
percent: number;
|
||||
};
|
||||
monthly: {
|
||||
used: number;
|
||||
total: number;
|
||||
percent: number;
|
||||
};
|
||||
};
|
||||
global: {
|
||||
used: number;
|
||||
total: number;
|
||||
percent: number;
|
||||
label: string;
|
||||
models: string[];
|
||||
hasDailyLimit: boolean;
|
||||
hasMonthlyLimit: boolean;
|
||||
daily: {
|
||||
used: number;
|
||||
total: number;
|
||||
percent: number;
|
||||
};
|
||||
monthly: {
|
||||
used: number;
|
||||
total: number;
|
||||
percent: number;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export const QUOTA_LIMITS = {
|
||||
domestic: 30000000,
|
||||
global: 10000000
|
||||
} as const;
|
||||
Reference in new issue
Block a user