Files
zn-ai/electron/api/router.ts
duanshuwen dfef9c90a5 feat: add gateway management features and settings
- Implemented new API routes for handling logs and settings related to the gateway.
- Added a new Gateway section in the General Settings panel to manage gateway status and auto-start options.
- Introduced a state management hook for gateway settings, including status, logs, and auto-start functionality.
- Updated configuration service to include gateway auto-start setting.
- Enhanced internationalization support for new gateway-related messages.
- Refactored existing settings store to accommodate new gateway settings.
- Cleaned up code and improved logging functionality.
2026-04-20 22:22:11 +08:00

61 lines
1.9 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 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,
];
function createContext(): HostApiContext {
return {
gatewayManager,
providerApiService,
mainWindow: BrowserWindow.getAllWindows()[0] ?? null,
clawHubService: new ClawHubService(),
};
}
export async function dispatchLocalHostApi(request: HostApiRequest) {
const normalized = normalizeRequest(request);
const ctx = createContext();
for (const handler of routeHandlers) {
const result = await handler(normalized, ctx);
if (result) {
return result;
}
}
return null;
}