Repository navigation
Add Zhipu / Z.AI usage monitoring #10901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| import { ipcMain } from 'electron' | ||
| import { | ||
| clearZhipuCredentials, | ||
| hasZhipuCredentials, | ||
| readZhipuCredentials, | ||
| saveZhipuCredentials | ||
| } from '../zhipu/zhipu-credential-store' | ||
| import { readCcSwitchZhipuCredentials } from '../zhipu/cc-switch-import' | ||
| import type { RateLimitService } from '../rate-limits/service' | ||
| import { ZHIPU_DEFAULT_BASE_URL } from '../../shared/zhipu-usage' | ||
|
|
||
| export type ZhipuCredentialsStatus = { | ||
| configured: boolean | ||
| baseUrl: string | null | ||
| } | ||
|
|
||
| export type ZhipuCredentialsImportStatus = ZhipuCredentialsStatus & { | ||
| importedProviderName: string | ||
| } | ||
|
|
||
| function getZhipuCredentialsStatus(): ZhipuCredentialsStatus { | ||
| let baseUrl: string | null = null | ||
| try { | ||
| baseUrl = readZhipuCredentials()?.baseUrl ?? null | ||
| } catch { | ||
| baseUrl = null | ||
| } | ||
| return { | ||
| configured: hasZhipuCredentials(), | ||
| baseUrl | ||
| } | ||
| } | ||
|
|
||
| // Why: callers need the persisted status immediately; usage refresh can finish in the background. | ||
| function refreshAfterZhipuCredentialChange( | ||
| rateLimits: RateLimitService | null, | ||
| action: 'save' | 'clear' | 'import' | ||
| ): void { | ||
| rateLimits?.invalidateZhipuCredentialState() | ||
| void rateLimits?.refresh().catch((error: unknown) => { | ||
| console.error(`[zhipu] failed to trigger rate-limit refresh after ${action}:`, error) | ||
| }) | ||
| } | ||
|
|
||
| export function registerZhipuCredentialsHandlers(rateLimits: RateLimitService | null): void { | ||
| ipcMain.handle('zhipuCredentials:getStatus', () => getZhipuCredentialsStatus()) | ||
| ipcMain.handle('zhipuCredentials:save', (_event, args: unknown) => { | ||
| if ( | ||
| typeof args !== 'object' || | ||
| args === null || | ||
| typeof (args as { authToken?: unknown }).authToken !== 'string' || | ||
| typeof (args as { baseUrl?: unknown }).baseUrl !== 'string' | ||
| ) { | ||
| throw new Error('Zhipu credentials must include baseUrl and authToken strings') | ||
| } | ||
| saveZhipuCredentials({ | ||
| baseUrl: (args as { baseUrl: string }).baseUrl || ZHIPU_DEFAULT_BASE_URL, | ||
| authToken: (args as { authToken: string }).authToken | ||
| }) | ||
| refreshAfterZhipuCredentialChange(rateLimits, 'save') | ||
| return getZhipuCredentialsStatus() | ||
| }) | ||
| ipcMain.handle('zhipuCredentials:clear', () => { | ||
| clearZhipuCredentials() | ||
| refreshAfterZhipuCredentialChange(rateLimits, 'clear') | ||
| return getZhipuCredentialsStatus() | ||
| }) | ||
| ipcMain.handle('zhipuCredentials:importFromCcSwitch', () => { | ||
| const imported = readCcSwitchZhipuCredentials() | ||
| saveZhipuCredentials({ | ||
| baseUrl: imported.baseUrl, | ||
| authToken: imported.authToken | ||
| }) | ||
| refreshAfterZhipuCredentialChange(rateLimits, 'import') | ||
| return { | ||
| ...getZhipuCredentialsStatus(), | ||
| importedProviderName: imported.providerName | ||
| } | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refreshZhiputriggers a full provider refresh rather than a Zhipu-specific onerateLimits:refreshZhipuis wired torateLimits.refresh(), which refreshes every provider (Claude, Codex, Gemini, MiniMax, Grok, etc.) in parallel. By contrast,rateLimits:refreshGrokcalls the dedicatedrateLimits.refreshGrok(). When a user clicks "Refresh usage" in the Zhipu settings panel, all other provider fetches are triggered as a side-effect. This is consistent with the MiniMax pattern so it won't break anything, but if a dedicatedrefreshZhipu()method is ever added toRateLimitService(as was done for Grok), the IPC handler here will need to be updated in tandem.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!