Files
orca/src/main/ipc/opencode-go-credentials.ts
T
53f9ea7839 fix(opencode): keep Go credentials private and resolve backend keys (#24615)
Preserve the complete credential storage, migration, IPC, Settings and rate-limit refresh change alongside standalone GLM plans, current-main database diagnostics and the reviewed unknown-backend environment correction. Keep native discovery cancellation third and selected environment fourth.

Original-topic-commit: 7903f1cddb
Original-topic-commit: 588117b5cf
Original-topic-commit: dedd4f8c86
Original-topic-commit: 6645dae104
Original-topic-commit: a25b80c02c1af7830b0e6a65e72d965b3ad98276
Restacked-from: a25b80c02c1af7830b0e6a65e72d965b3ad98276
Restacked-onto: b032867021

Co-authored-by: kespineira <kespineira@users.noreply.github.com>
Co-authored-by: kevimux <kevimux@users.noreply.github.com>
Reported-by: pullfrog
Reviewed-full-source: 849fe093073f4c1606bd65d79a0c725d955d0d1f
Native-helper-source: 80dbe23237


Reviewed-full-current-source: 36acb57d44adb3d378c0289c8c15f7da0fda214c
2026-10-02 23:21:27 -07:00

48 lines
1.6 KiB
TypeScript

import { ipcMain } from 'electron'
import {
clearOpenCodeGoApiKey,
hasOpenCodeGoApiKey,
saveOpenCodeGoApiKey
} from '../opencode/opencode-go-api-key-store'
import type { RateLimitService } from '../rate-limits/service'
import { refreshAfterCredentialChange } from './credential-change-rate-limit-refresh'
type CredentialRateLimits = Pick<
RateLimitService,
'invalidateOpenCodeGoCredentialState' | 'refresh'
>
function getOpenCodeGoCredentialsStatus(): { apiKeyConfigured: boolean } {
return { apiKeyConfigured: hasOpenCodeGoApiKey() }
}
function refreshAfterOpenCodeGoCredentialChange(
rateLimits: CredentialRateLimits | null,
apiKeyCleared: boolean
): void {
refreshAfterCredentialChange(
rateLimits,
(service) => service.invalidateOpenCodeGoCredentialState({ apiKeyCleared }),
'[opencode-go] failed to refresh usage after a credential change:'
)
}
export function registerOpenCodeGoCredentialsHandlers(
rateLimits: CredentialRateLimits | null
): void {
ipcMain.handle('opencodeGoCredentials:getStatus', () => getOpenCodeGoCredentialsStatus())
ipcMain.handle('opencodeGoCredentials:saveApiKey', (_event, key: unknown) => {
if (typeof key !== 'string') {
throw new Error('OpenCode Go API key must be a string')
}
saveOpenCodeGoApiKey(key)
refreshAfterOpenCodeGoCredentialChange(rateLimits, false)
return getOpenCodeGoCredentialsStatus()
})
ipcMain.handle('opencodeGoCredentials:clearApiKey', () => {
clearOpenCodeGoApiKey()
refreshAfterOpenCodeGoCredentialChange(rateLimits, true)
return getOpenCodeGoCredentialsStatus()
})
}