mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-22 02:54:31 -07:00
Add usage limit remaining in /stats (#13843)
This commit is contained in:
@@ -380,4 +380,38 @@ describe('CodeAssistServer', () => {
|
||||
});
|
||||
expect(response).toEqual(mockResponse);
|
||||
});
|
||||
|
||||
it('should call the retrieveUserQuota endpoint', async () => {
|
||||
const client = new OAuth2Client();
|
||||
const server = new CodeAssistServer(
|
||||
client,
|
||||
'test-project',
|
||||
{},
|
||||
'test-session',
|
||||
UserTierId.FREE,
|
||||
);
|
||||
const mockResponse = {
|
||||
buckets: [
|
||||
{
|
||||
modelId: 'gemini-2.5-pro',
|
||||
tokenType: 'REQUESTS',
|
||||
remainingFraction: 0.75,
|
||||
resetTime: '2025-10-22T16:01:15Z',
|
||||
},
|
||||
],
|
||||
};
|
||||
const requestPostSpy = vi
|
||||
.spyOn(server, 'requestPost')
|
||||
.mockResolvedValue(mockResponse);
|
||||
|
||||
const req = {
|
||||
project: 'projects/my-cloudcode-project',
|
||||
userAgent: 'CloudCodePlugin/1.0 (gaghosh)',
|
||||
};
|
||||
|
||||
const response = await server.retrieveUserQuota(req);
|
||||
|
||||
expect(requestPostSpy).toHaveBeenCalledWith('retrieveUserQuota', req);
|
||||
expect(response).toEqual(mockResponse);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -14,6 +14,8 @@ import type {
|
||||
OnboardUserRequest,
|
||||
SetCodeAssistGlobalUserSettingRequest,
|
||||
ClientMetadata,
|
||||
RetrieveUserQuotaRequest,
|
||||
RetrieveUserQuotaResponse,
|
||||
} from './types.js';
|
||||
import type {
|
||||
ListExperimentsRequest,
|
||||
@@ -171,6 +173,15 @@ export class CodeAssistServer implements ContentGenerator {
|
||||
);
|
||||
}
|
||||
|
||||
async retrieveUserQuota(
|
||||
req: RetrieveUserQuotaRequest,
|
||||
): Promise<RetrieveUserQuotaResponse> {
|
||||
return await this.requestPost<RetrieveUserQuotaResponse>(
|
||||
'retrieveUserQuota',
|
||||
req,
|
||||
);
|
||||
}
|
||||
|
||||
async requestPost<T>(
|
||||
method: string,
|
||||
req: object,
|
||||
|
||||
@@ -200,3 +200,20 @@ export interface GoogleRpcResponse {
|
||||
interface GoogleRpcErrorInfo {
|
||||
reason?: string;
|
||||
}
|
||||
|
||||
export interface RetrieveUserQuotaRequest {
|
||||
project: string;
|
||||
userAgent?: string;
|
||||
}
|
||||
|
||||
export interface BucketInfo {
|
||||
remainingAmount?: string;
|
||||
remainingFraction?: number;
|
||||
resetTime?: string;
|
||||
tokenType?: string;
|
||||
modelId?: string;
|
||||
}
|
||||
|
||||
export interface RetrieveUserQuotaResponse {
|
||||
buckets?: BucketInfo[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user