mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-18 01:00:39 -07:00
feat(billing): implement G1 AI credits overage flow with billing telemetry (#18590)
This commit is contained in:
@@ -13,6 +13,7 @@ import type {
|
||||
ContentGenerator,
|
||||
ContentGeneratorConfig,
|
||||
} from '../core/contentGenerator.js';
|
||||
import type { OverageStrategy } from '../billing/billing.js';
|
||||
import {
|
||||
AuthType,
|
||||
createContentGenerator,
|
||||
@@ -116,6 +117,7 @@ import {
|
||||
import { HookSystem } from '../hooks/index.js';
|
||||
import type {
|
||||
UserTierId,
|
||||
GeminiUserTier,
|
||||
RetrieveUserQuotaResponse,
|
||||
AdminControlsSettings,
|
||||
} from '../code_assist/types.js';
|
||||
@@ -573,6 +575,9 @@ export interface ConfigParameters {
|
||||
agents?: AgentSettings;
|
||||
}>;
|
||||
enableConseca?: boolean;
|
||||
billing?: {
|
||||
overageStrategy?: OverageStrategy;
|
||||
};
|
||||
}
|
||||
|
||||
export class Config {
|
||||
@@ -754,6 +759,10 @@ export class Config {
|
||||
}>)
|
||||
| undefined;
|
||||
|
||||
private readonly billing: {
|
||||
overageStrategy: OverageStrategy;
|
||||
};
|
||||
|
||||
private readonly enableAgents: boolean;
|
||||
private agents: AgentSettings;
|
||||
private readonly enableEventDrivenScheduler: boolean;
|
||||
@@ -1001,6 +1010,10 @@ export class Config {
|
||||
this.onModelChange = params.onModelChange;
|
||||
this.onReload = params.onReload;
|
||||
|
||||
this.billing = {
|
||||
overageStrategy: params.billing?.overageStrategy ?? 'ask',
|
||||
};
|
||||
|
||||
if (params.contextFileName) {
|
||||
setGeminiMdFilename(params.contextFileName);
|
||||
}
|
||||
@@ -1264,6 +1277,10 @@ export class Config {
|
||||
return this.contentGenerator?.userTierName;
|
||||
}
|
||||
|
||||
getUserPaidTier(): GeminiUserTier | undefined {
|
||||
return this.contentGenerator?.paidTier;
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides access to the BaseLlmClient for stateless LLM operations.
|
||||
*/
|
||||
@@ -1578,6 +1595,19 @@ export class Config {
|
||||
this.hasAccessToPreviewModel = hasAccess;
|
||||
}
|
||||
|
||||
async refreshAvailableCredits(): Promise<void> {
|
||||
const codeAssistServer = getCodeAssistServer(this);
|
||||
if (!codeAssistServer) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await codeAssistServer.refreshAvailableCredits();
|
||||
} catch {
|
||||
// Non-fatal: proceed even if refresh fails.
|
||||
// The actual credit balance will be verified server-side.
|
||||
}
|
||||
}
|
||||
|
||||
async refreshUserQuota(): Promise<RetrieveUserQuotaResponse | undefined> {
|
||||
const codeAssistServer = getCodeAssistServer(this);
|
||||
if (!codeAssistServer || !codeAssistServer.projectId) {
|
||||
@@ -2052,6 +2082,19 @@ export class Config {
|
||||
return this.telemetrySettings.outfile;
|
||||
}
|
||||
|
||||
getBillingSettings(): { overageStrategy: OverageStrategy } {
|
||||
return this.billing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the overage strategy at runtime.
|
||||
* Used to switch from 'ask' to 'always' after the user accepts credits
|
||||
* via the overage dialog, so subsequent API calls auto-include credits.
|
||||
*/
|
||||
setOverageStrategy(strategy: OverageStrategy): void {
|
||||
this.billing.overageStrategy = strategy;
|
||||
}
|
||||
|
||||
getTelemetryUseCollector(): boolean {
|
||||
return this.telemetrySettings.useCollector ?? false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user