- Added telemetry utility to capture application events and metrics. - Integrated PostHog for event tracking with distinct user identification. - Implemented telemetry initialization, event capturing, and shutdown procedures. feat: add UV environment setup for Python management - Created utilities to manage Python installation and configuration. - Implemented network optimization checks for Python installation mirrors. - Added functions to set up managed Python environments with error handling. feat: enhance host API communication with token management - Introduced host API token retrieval and management for secure requests. - Updated host API fetch functions to include token in headers. - Added support for creating event sources with authentication. test: add comprehensive tests for gateway protocol and startup helpers - Implemented unit tests for gateway protocol helpers, event dispatching, and state management. - Added tests for startup recovery strategies and process policies. - Ensured coverage for connection monitoring and restart governance logic.
63 lines
2.0 KiB
TypeScript
63 lines
2.0 KiB
TypeScript
import { BrowserWindow } from 'electron';
|
|
import { gatewayManager } from '@electron/gateway/manager';
|
|
import { providerApiService } from '@electron/service/provider-api-service';
|
|
import { ClawHubService } from '@electron/gateway/clawhub';
|
|
import { hostEventBus } from './event-bus';
|
|
import type { HostApiContext } from './context';
|
|
import type { HostApiRequest } from './route-utils';
|
|
import { normalizeRequest } from './route-utils';
|
|
import { handleAgentRoutes } from './routes/agents';
|
|
import { handleChannelRoutes } from './routes/channels';
|
|
import { handleCronRoutes } from './routes/cron';
|
|
import { handleFileRoutes } from './routes/files';
|
|
import { handleGatewayRoutes } from './routes/gateway';
|
|
import { handleKnowledgeRoutes } from './routes/knowledge';
|
|
import { handleLogRoutes } from './routes/logs';
|
|
import { handleProviderRoutes } from './routes/providers';
|
|
import { handleSettingsRoutes } from './routes/settings';
|
|
import { handleSessionRoutes } from './routes/sessions';
|
|
import { handleSkillRoutes } from './routes/skills';
|
|
|
|
type RouteHandler = (
|
|
request: ReturnType<typeof normalizeRequest>,
|
|
ctx: HostApiContext,
|
|
) => Promise<any | null>;
|
|
|
|
const routeHandlers: RouteHandler[] = [
|
|
handleProviderRoutes,
|
|
handleChannelRoutes,
|
|
handleAgentRoutes,
|
|
handleCronRoutes,
|
|
handleGatewayRoutes,
|
|
handleKnowledgeRoutes,
|
|
handleLogRoutes,
|
|
handleFileRoutes,
|
|
handleSessionRoutes,
|
|
handleSettingsRoutes,
|
|
handleSkillRoutes,
|
|
];
|
|
|
|
export function createHostApiContext(): HostApiContext {
|
|
return {
|
|
gatewayManager,
|
|
providerApiService,
|
|
mainWindow: BrowserWindow.getAllWindows()[0] ?? null,
|
|
clawHubService: new ClawHubService(),
|
|
eventBus: hostEventBus,
|
|
};
|
|
}
|
|
|
|
export async function dispatchLocalHostApi(request: HostApiRequest) {
|
|
const normalized = normalizeRequest(request);
|
|
const ctx = createHostApiContext();
|
|
|
|
for (const handler of routeHandlers) {
|
|
const result = await handler(normalized, ctx);
|
|
if (result) {
|
|
return result;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
}
|