* Add KiloCode as a first-class provider with HTTP-based model catalog Implements KiloCode (kilo.ai gateway) support following repo design principles, independently of the OpenCode implementation. Key changes: - Add 'kilocode' to CliProviderId, TeamProviderId, MemberWorkSyncProviderId - Create kilocode-model-catalog feature: HTTP client fetching models from kilo.ai /models endpoint (not /v1/models — different gateway path) - Add KILO_API_KEY env var for authentication - Wire kilocode into provider routing, capabilities, and UI labels - Add 'kilo' brand icon alias in providerBrandIcons (auto-fetches from models.dev) - KiloCode status is managed via the HTTP gateway, not the multimodel bridge * Fix: preserve non-bridge providers (kilocode) when updating provider status The multimodel bridge only returns status for anthropic/codex/gemini/opencode. When checkAuthStatus replaced result.providers with the bridge response, kilocode was lost from the provider list and never appeared in the UI. Now merge bridge providers with the initial list, keeping any provider not covered by the bridge so kilocode shows up in the Extensions panel. * Fix: resolve KiloCode status after bridge merge, skip bridge refresh for non-bridge providers - resolveKilocodeStatus() gives kilocode a settled verificationState:'verified' status so isHydratedMultimodelProviderStatus() returns true and the loading spinner stops - Status reflects KILO_API_KEY presence: authenticated+supported when set, else clear message - fetchCliStatus() now skips fetchCliProviderStatus for non-bridge providers (kilocode) so the Claude Code CLI is not queried for kilocode, preventing error status overwrites * Add KiloCode to API key provider system in settings dialog isApiKeyProviderId now includes kilocode, so the API key form renders in the Provider Settings dialog instead of showing an empty modal. Adds KILO_API_KEY config with placeholder and description. * Fix KiloCode models endpoint: /api/gateway/models per docs * Fix: short-circuit getProviderStatus/verifyProviderModels for kilocode The Claude Code CLI only accepts anthropic and codex for --provider. Calling it with kilocode caused the blinking modal error. resolveKilocodeProviderStatus() returns status directly from env without touching the CLI binary — no bridge, no --provider flag. * Fix: resolveKilocodeProviderStatus reads from app key store via enrichProviderStatus process.env.KILO_API_KEY was only set for users who configured it in their shell environment. The UI stores the key in the app's encrypted key store (ApiKeyService), which enrichProviderStatus checks via hasStoredProviderApiKey. Now resolveKilocodeProviderStatus() calls providerConnectionService.enrichProviderStatus() so both the app key store and env var are checked — the same way anthropic/gemini work. * Wire KiloCode model catalog into provider status — models now load from gateway - ProviderConnectionService: add setKilocodeModelCatalogFeature() and enrichKilocodeProviderStatus() which fetches models from the gateway API and populates provider.models when the API key is configured - main/index.ts: create KilocodeModelCatalogFeature at startup and inject it into ProviderConnectionService, same lifecycle as Codex catalog * Fix: skip Claude CLI probe for kilocode in prepareForProvisioning The generic probe path calls probeClaudeRuntime with CLAUDE_CODE_ENTRY_PROVIDER=kilocode which causes the CLI to hang — freezing the Create Team dialog until timeout. Add an explicit kilocode case that short-circuits to an API key presence check (via providerConnectionService.getConnectionInfo) without touching the Claude binary, same pattern as the opencode adapter bypass. * Fix vitest localStorage fallback * test(kilocode): update provider visibility expectations --------- Co-authored-by: 777genius <quantjumppro@gmail.com>
325 lines
10 KiB
TypeScript
325 lines
10 KiB
TypeScript
/**
|
|
* IPC Handlers for CLI Installer Operations.
|
|
*
|
|
* Handlers:
|
|
* - cliInstaller:getStatus: Get current CLI installation status
|
|
* - cliInstaller:install: Start CLI install/update flow
|
|
* - cliInstaller:progress: Progress events (main → renderer, not a handler)
|
|
*/
|
|
|
|
import {
|
|
CLI_INSTALLER_GET_PROVIDER_STATUS,
|
|
CLI_INSTALLER_GET_STATUS,
|
|
CLI_INSTALLER_INSTALL,
|
|
CLI_INSTALLER_INVALIDATE_STATUS,
|
|
CLI_INSTALLER_VERIFY_PROVIDER_MODELS,
|
|
// eslint-disable-next-line boundaries/element-types -- IPC channel constants shared between main and preload
|
|
} from '@preload/constants/ipcChannels';
|
|
import { CLI_PROVIDER_STATUS_DEFERRED_MESSAGE } from '@shared/types/cliInstaller';
|
|
import { getErrorMessage } from '@shared/utils/errorHandling';
|
|
import { createLogger } from '@shared/utils/logger';
|
|
|
|
import { CodexBinaryResolver } from '../services/infrastructure/codexAppServer';
|
|
import { ClaudeBinaryResolver } from '../services/team/ClaudeBinaryResolver';
|
|
|
|
import type { CliInstallerService } from '../services';
|
|
import type {
|
|
CliInstallationStatus,
|
|
CliInstallerGetStatusOptions,
|
|
CliInstallerProviderStatusMode,
|
|
CliProviderId,
|
|
CliProviderStatus,
|
|
IpcResult,
|
|
} from '@shared/types';
|
|
import type { IpcMain, IpcMainInvokeEvent } from 'electron';
|
|
|
|
const logger = createLogger('IPC:cliInstaller');
|
|
|
|
let service: CliInstallerService;
|
|
const statusInFlight = new Map<CliInstallerProviderStatusMode, Promise<CliInstallationStatus>>();
|
|
const providerStatusInFlight = new Map<CliProviderId, Promise<CliProviderStatus | null>>();
|
|
const cachedStatus = new Map<
|
|
CliInstallerProviderStatusMode,
|
|
{ value: CliInstallationStatus; at: number }
|
|
>();
|
|
let statusCacheGeneration = 0;
|
|
const STATUS_CACHE_TTL_MS = 5_000;
|
|
const FRONTEND_MULTIMODEL_PROVIDER_IDS = new Set<CliProviderId>([
|
|
'anthropic',
|
|
'codex',
|
|
'opencode',
|
|
'kilocode',
|
|
]);
|
|
|
|
function isFrontendMultimodelProviderId(providerId: CliProviderId): boolean {
|
|
return FRONTEND_MULTIMODEL_PROVIDER_IDS.has(providerId);
|
|
}
|
|
|
|
function getCachedStatusAuthenticatedProvider(
|
|
providers: CliProviderStatus[]
|
|
): CliProviderStatus | null {
|
|
return (
|
|
providers.find(
|
|
(provider) => isFrontendMultimodelProviderId(provider.providerId) && provider.authenticated
|
|
) ?? null
|
|
);
|
|
}
|
|
|
|
function normalizeGetStatusOptions(options: unknown): Required<CliInstallerGetStatusOptions> {
|
|
if (
|
|
typeof options === 'object' &&
|
|
options !== null &&
|
|
(options as CliInstallerGetStatusOptions).providerStatusMode === 'defer'
|
|
) {
|
|
return { providerStatusMode: 'defer' };
|
|
}
|
|
|
|
return { providerStatusMode: 'full' };
|
|
}
|
|
|
|
function isDeferredProviderStatusSnapshot(status: CliInstallationStatus): boolean {
|
|
return (
|
|
status.flavor === 'agent_teams_orchestrator' &&
|
|
status.providers.length > 0 &&
|
|
status.providers.every(
|
|
(provider) =>
|
|
provider.supported === false &&
|
|
provider.authenticated === false &&
|
|
provider.verificationState === 'unknown' &&
|
|
provider.statusMessage === CLI_PROVIDER_STATUS_DEFERRED_MESSAGE
|
|
)
|
|
);
|
|
}
|
|
|
|
function hasDeferredProviderStatus(status: CliInstallationStatus): boolean {
|
|
return (
|
|
status.flavor === 'agent_teams_orchestrator' &&
|
|
status.providers.some(
|
|
(provider) => provider.statusMessage === CLI_PROVIDER_STATUS_DEFERRED_MESSAGE
|
|
)
|
|
);
|
|
}
|
|
|
|
function canUseStatusForCacheKey(
|
|
cacheKey: CliInstallerProviderStatusMode,
|
|
status: CliInstallationStatus
|
|
): boolean {
|
|
if (cacheKey === 'defer') {
|
|
return true;
|
|
}
|
|
|
|
return (
|
|
!status.authStatusChecking &&
|
|
!hasDeferredProviderStatus(status) &&
|
|
!isDeferredProviderStatusSnapshot(status)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Initializes CLI installer handlers with the service instance.
|
|
*/
|
|
export function initializeCliInstallerHandlers(installerService: CliInstallerService): void {
|
|
service = installerService;
|
|
}
|
|
|
|
/**
|
|
* Registers all CLI installer IPC handlers.
|
|
*/
|
|
export function registerCliInstallerHandlers(ipcMain: IpcMain): void {
|
|
ipcMain.handle(CLI_INSTALLER_GET_STATUS, handleGetStatus);
|
|
ipcMain.handle(CLI_INSTALLER_GET_PROVIDER_STATUS, handleGetProviderStatus);
|
|
ipcMain.handle(CLI_INSTALLER_VERIFY_PROVIDER_MODELS, handleVerifyProviderModels);
|
|
ipcMain.handle(CLI_INSTALLER_INSTALL, handleInstall);
|
|
ipcMain.handle(CLI_INSTALLER_INVALIDATE_STATUS, handleInvalidateStatus);
|
|
|
|
logger.info('CLI installer handlers registered');
|
|
}
|
|
|
|
/**
|
|
* Removes all CLI installer IPC handlers.
|
|
*/
|
|
export function removeCliInstallerHandlers(ipcMain: IpcMain): void {
|
|
ipcMain.removeHandler(CLI_INSTALLER_GET_STATUS);
|
|
ipcMain.removeHandler(CLI_INSTALLER_GET_PROVIDER_STATUS);
|
|
ipcMain.removeHandler(CLI_INSTALLER_VERIFY_PROVIDER_MODELS);
|
|
ipcMain.removeHandler(CLI_INSTALLER_INSTALL);
|
|
ipcMain.removeHandler(CLI_INSTALLER_INVALIDATE_STATUS);
|
|
|
|
logger.info('CLI installer handlers removed');
|
|
}
|
|
|
|
// =============================================================================
|
|
// Handler Implementations
|
|
// =============================================================================
|
|
|
|
async function handleGetStatus(
|
|
_event: IpcMainInvokeEvent,
|
|
options?: CliInstallerGetStatusOptions
|
|
): Promise<IpcResult<CliInstallationStatus>> {
|
|
try {
|
|
const normalizedOptions = normalizeGetStatusOptions(options);
|
|
const cacheKey = normalizedOptions.providerStatusMode;
|
|
const latestSnapshot = service.getLatestStatusSnapshot();
|
|
const cached = cachedStatus.get(cacheKey);
|
|
if (cached && Date.now() - cached.at < STATUS_CACHE_TTL_MS) {
|
|
if (latestSnapshot && canUseStatusForCacheKey(cacheKey, latestSnapshot)) {
|
|
cachedStatus.set(cacheKey, { value: latestSnapshot, at: Date.now() });
|
|
return { success: true, data: latestSnapshot };
|
|
}
|
|
return { success: true, data: cached.value };
|
|
}
|
|
|
|
if (!statusInFlight.has(cacheKey)) {
|
|
const startedAt = Date.now();
|
|
const generation = statusCacheGeneration;
|
|
const request = service
|
|
.getStatus(normalizedOptions)
|
|
.then((status) => {
|
|
if (generation === statusCacheGeneration && canUseStatusForCacheKey(cacheKey, status)) {
|
|
cachedStatus.set(cacheKey, { value: status, at: Date.now() });
|
|
}
|
|
return status;
|
|
})
|
|
.catch((err) => {
|
|
if (generation === statusCacheGeneration) {
|
|
cachedStatus.delete(cacheKey);
|
|
}
|
|
throw err;
|
|
})
|
|
.finally(() => {
|
|
const ms = Date.now() - startedAt;
|
|
if (ms >= 2000) {
|
|
logger.warn(`cliInstaller:getStatus slow ms=${ms}`);
|
|
}
|
|
if (statusInFlight.get(cacheKey) === request) {
|
|
statusInFlight.delete(cacheKey);
|
|
}
|
|
});
|
|
statusInFlight.set(cacheKey, request);
|
|
}
|
|
|
|
const status = await statusInFlight.get(cacheKey)!;
|
|
return { success: true, data: status };
|
|
} catch (error) {
|
|
const msg = getErrorMessage(error);
|
|
logger.error('Error in cliInstaller:getStatus:', msg);
|
|
return { success: false, error: msg };
|
|
}
|
|
}
|
|
|
|
function patchCachedProviderStatus(providerStatus: CliProviderStatus | null): void {
|
|
if (!providerStatus) {
|
|
return;
|
|
}
|
|
|
|
for (const [cacheKey, cached] of cachedStatus) {
|
|
if (
|
|
cached.value.flavor === 'agent_teams_orchestrator' &&
|
|
!isFrontendMultimodelProviderId(providerStatus.providerId)
|
|
) {
|
|
continue;
|
|
}
|
|
|
|
const hasProvider = cached.value.providers.some(
|
|
(provider) => provider.providerId === providerStatus.providerId
|
|
);
|
|
const nextProviders = hasProvider
|
|
? cached.value.providers.map((provider) =>
|
|
provider.providerId === providerStatus.providerId ? providerStatus : provider
|
|
)
|
|
: [...cached.value.providers, providerStatus];
|
|
const authenticatedProvider =
|
|
cached.value.flavor === 'agent_teams_orchestrator'
|
|
? getCachedStatusAuthenticatedProvider(nextProviders)
|
|
: (nextProviders.find((provider) => provider.authenticated) ?? null);
|
|
|
|
cachedStatus.set(cacheKey, {
|
|
value: {
|
|
...cached.value,
|
|
providers: nextProviders,
|
|
authLoggedIn:
|
|
cached.value.flavor === 'agent_teams_orchestrator'
|
|
? authenticatedProvider !== null
|
|
: nextProviders.some((provider) => provider.authenticated),
|
|
authMethod: authenticatedProvider?.authMethod ?? null,
|
|
},
|
|
at: Date.now(),
|
|
});
|
|
}
|
|
}
|
|
|
|
async function handleGetProviderStatus(
|
|
_event: IpcMainInvokeEvent,
|
|
providerId: CliProviderId
|
|
): Promise<IpcResult<CliProviderStatus | null>> {
|
|
try {
|
|
const inFlight = providerStatusInFlight.get(providerId);
|
|
if (inFlight) {
|
|
const status = await inFlight;
|
|
return { success: true, data: status };
|
|
}
|
|
|
|
const generation = statusCacheGeneration;
|
|
const request = service
|
|
.getProviderStatus(providerId)
|
|
.then((status) => {
|
|
if (generation === statusCacheGeneration) {
|
|
patchCachedProviderStatus(status);
|
|
}
|
|
return status;
|
|
})
|
|
.finally(() => {
|
|
if (providerStatusInFlight.get(providerId) === request) {
|
|
providerStatusInFlight.delete(providerId);
|
|
}
|
|
});
|
|
|
|
providerStatusInFlight.set(providerId, request);
|
|
const status = await request;
|
|
return { success: true, data: status };
|
|
} catch (error) {
|
|
const msg = getErrorMessage(error);
|
|
logger.error(`Error in cliInstaller:getProviderStatus(${providerId}):`, msg);
|
|
return { success: false, error: msg };
|
|
}
|
|
}
|
|
|
|
async function handleInstall(_event: IpcMainInvokeEvent): Promise<IpcResult<void>> {
|
|
try {
|
|
await service.install();
|
|
return { success: true, data: undefined };
|
|
} catch (error) {
|
|
const msg = getErrorMessage(error);
|
|
logger.error('Error in cliInstaller:install:', msg);
|
|
return { success: false, error: msg };
|
|
}
|
|
}
|
|
|
|
async function handleVerifyProviderModels(
|
|
_event: IpcMainInvokeEvent,
|
|
providerId: CliProviderId
|
|
): Promise<IpcResult<CliProviderStatus | null>> {
|
|
try {
|
|
const generation = statusCacheGeneration;
|
|
const status = await service.verifyProviderModels(providerId);
|
|
if (generation === statusCacheGeneration) {
|
|
patchCachedProviderStatus(status);
|
|
}
|
|
return { success: true, data: status };
|
|
} catch (error) {
|
|
const msg = getErrorMessage(error);
|
|
logger.error(`Error in cliInstaller:verifyProviderModels(${providerId}):`, msg);
|
|
return { success: false, error: msg };
|
|
}
|
|
}
|
|
|
|
function handleInvalidateStatus(_event: IpcMainInvokeEvent): IpcResult<void> {
|
|
statusCacheGeneration += 1;
|
|
cachedStatus.clear();
|
|
statusInFlight.clear();
|
|
providerStatusInFlight.clear();
|
|
ClaudeBinaryResolver.clearCache();
|
|
CodexBinaryResolver.clearCache();
|
|
service.invalidateStatusCache();
|
|
return { success: true, data: undefined };
|
|
}
|