Feat: Add z.ai usage tracking

This commit is contained in:
eclipxe
2026-01-20 14:34:15 -08:00
committed by gsxdsm
parent 1662c6bf0b
commit 7765a12868
23 changed files with 1331 additions and 55 deletions

View File

@@ -1,6 +1,6 @@
// Type definitions for Electron IPC API
import type { SessionListItem, Message } from '@/types/electron';
import type { ClaudeUsageResponse, CodexUsageResponse } from '@/store/app-store';
import type { ClaudeUsageResponse, CodexUsageResponse, ZaiUsageResponse } from '@/store/app-store';
import type {
IssueValidationVerdict,
IssueValidationConfidence,
@@ -865,6 +865,15 @@ export interface ElectronAPI {
error?: string;
}>;
};
zai?: {
getUsage: () => Promise<ZaiUsageResponse>;
verify: (apiKey: string) => Promise<{
success: boolean;
authenticated: boolean;
message?: string;
error?: string;
}>;
};
settings?: {
getStatus: () => Promise<{
success: boolean;
@@ -1364,6 +1373,51 @@ const _getMockElectronAPI = (): ElectronAPI => {
};
},
},
// Mock z.ai API
zai: {
getUsage: async () => {
console.log('[Mock] Getting z.ai usage');
return {
quotaLimits: {
tokens: {
limitType: 'TOKENS_LIMIT',
limit: 1000000,
used: 250000,
remaining: 750000,
usedPercent: 25,
nextResetTime: Date.now() + 86400000,
},
time: {
limitType: 'TIME_LIMIT',
limit: 3600,
used: 900,
remaining: 2700,
usedPercent: 25,
nextResetTime: Date.now() + 3600000,
},
planType: 'standard',
},
lastUpdated: new Date().toISOString(),
};
},
verify: async (apiKey: string) => {
console.log('[Mock] Verifying z.ai API key');
// Mock successful verification if key is provided
if (apiKey && apiKey.trim().length > 0) {
return {
success: true,
authenticated: true,
message: 'Connection successful! z.ai API responded.',
};
}
return {
success: false,
authenticated: false,
error: 'Please provide an API key to test.',
};
},
},
};
};

View File

@@ -1737,6 +1737,67 @@ export class HttpApiClient implements ElectronAPI {
},
};
// z.ai API
zai = {
getStatus: (): Promise<{
success: boolean;
available: boolean;
message?: string;
hasApiKey?: boolean;
hasEnvApiKey?: boolean;
error?: string;
}> => this.get('/api/zai/status'),
getUsage: (): Promise<{
quotaLimits?: {
tokens?: {
limitType: string;
limit: number;
used: number;
remaining: number;
usedPercent: number;
nextResetTime: number;
};
time?: {
limitType: string;
limit: number;
used: number;
remaining: number;
usedPercent: number;
nextResetTime: number;
};
planType: string;
} | null;
usageDetails?: Array<{
modelId: string;
used: number;
limit: number;
}>;
lastUpdated: string;
error?: string;
message?: string;
}> => this.get('/api/zai/usage'),
configure: (
apiToken?: string,
apiHost?: string
): Promise<{
success: boolean;
message?: string;
isAvailable?: boolean;
error?: string;
}> => this.post('/api/zai/configure', { apiToken, apiHost }),
verify: (
apiKey: string
): Promise<{
success: boolean;
authenticated: boolean;
message?: string;
error?: string;
}> => this.post('/api/zai/verify', { apiKey }),
};
// Features API
features: FeaturesAPI & {
bulkUpdate: (

View File

@@ -99,6 +99,8 @@ export const queryKeys = {
claude: () => ['usage', 'claude'] as const,
/** Codex API usage */
codex: () => ['usage', 'codex'] as const,
/** z.ai API usage */
zai: () => ['usage', 'zai'] as const,
},
// ============================================