Files
orca/src/preload/api/rate-limits-bridge.ts
T
Neil 401664298f fix(preload): make a dropped bridge key a compile error
The split silently dropped jira.searchUsers and
runtimeEnvironments.retryControlConnection. Neither failed typecheck: the bridge
modules carried no satisfies annotation and the composed api object was
unannotated, so a missing key was only a runtime TypeError in the renderer.

Annotates each module against PreloadApi, the type window.api is already
declared as, so the contract supplies the shape rather than a parallel copy.
Deleting jira.searchUsers now fails with TS2741 naming the key.

Turning this on surfaced 106 places where a bridge locally annotated
Promise<unknown> or unknown[] over a contract that declares concrete types --
the bridge was erasing types the renderer relied on. Those annotations are gone.

Also exposes app.awaitBeforeUnloadCheckpoint, which was declared and called but
never actually on the bridge, so the lazy-chunk recovery reload optional-chained
to a no-op and navigated without joining the checkpoint. The missing key was
caught by the new annotation rather than by hand.
2026-09-01 18:24:49 -07:00

32 lines
1.7 KiB
TypeScript

import { ipcRenderer } from 'electron'
import type {
CodexRateLimitResetResult,
RateLimitRuntimeTarget,
RateLimitState
} from '../../shared/rate-limit-types'
import type { PreloadApi } from '../api-types'
export const rateLimitsApi = {
get: (): Promise<RateLimitState> => ipcRenderer.invoke('rateLimits:get'),
refresh: (): Promise<RateLimitState> => ipcRenderer.invoke('rateLimits:refresh'),
refreshCodexForTarget: (target: RateLimitRuntimeTarget): Promise<RateLimitState> =>
ipcRenderer.invoke('rateLimits:refreshCodexForTarget', target),
consumeCodexResetCredit: (): Promise<CodexRateLimitResetResult> =>
ipcRenderer.invoke('rateLimits:consumeCodexResetCredit'),
refreshClaudeForTarget: (target: RateLimitRuntimeTarget): Promise<RateLimitState> =>
ipcRenderer.invoke('rateLimits:refreshClaudeForTarget', target),
setPollingInterval: (ms: number): Promise<void> =>
ipcRenderer.invoke('rateLimits:setPollingInterval', ms),
fetchInactiveClaudeAccounts: (): Promise<void> =>
ipcRenderer.invoke('rateLimits:fetchInactiveClaudeAccounts'),
fetchInactiveCodexAccounts: (): Promise<void> =>
ipcRenderer.invoke('rateLimits:fetchInactiveCodexAccounts'),
refreshMiniMax: (): Promise<RateLimitState> => ipcRenderer.invoke('rateLimits:refreshMiniMax'),
refreshGrok: (): Promise<RateLimitState> => ipcRenderer.invoke('rateLimits:refreshGrok'),
onUpdate: (callback: (state: RateLimitState) => void): (() => void) => {
const listener = (_event: Electron.IpcRendererEvent, state: RateLimitState) => callback(state)
ipcRenderer.on('rateLimits:update', listener)
return () => ipcRenderer.removeListener('rateLimits:update', listener)
}
} satisfies PreloadApi['rateLimits']