feat: add runtime event handling for providers in ProvidersSection feat: update routing to include Channels and Agents pages feat: extend route types and navigation items for Channels and Agents feat: implement agents store for managing agent data and interactions fix: update chat store to utilize agents store for agent-related functionality chore: export agents store from index fix: enhance runtime types for better event handling fix: update Vite config to handle dev server URL correctly
53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { BrowserWindow } from 'electron';
|
|
import { gatewayManager } from '@electron/gateway/manager';
|
|
import { providerApiService } from '@electron/service/provider-api-service';
|
|
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 { handleModelRoutes } from './routes/models';
|
|
import { handleProviderRoutes } from './routes/providers';
|
|
import { handleSessionRoutes } from './routes/sessions';
|
|
|
|
type RouteHandler = (
|
|
request: ReturnType<typeof normalizeRequest>,
|
|
ctx: HostApiContext,
|
|
) => Promise<any | null>;
|
|
|
|
const routeHandlers: RouteHandler[] = [
|
|
handleProviderRoutes,
|
|
handleChannelRoutes,
|
|
handleAgentRoutes,
|
|
handleModelRoutes,
|
|
handleCronRoutes,
|
|
handleGatewayRoutes,
|
|
handleFileRoutes,
|
|
handleSessionRoutes,
|
|
];
|
|
|
|
function createContext(): HostApiContext {
|
|
return {
|
|
gatewayManager,
|
|
providerApiService,
|
|
mainWindow: BrowserWindow.getAllWindows()[0] ?? null,
|
|
};
|
|
}
|
|
|
|
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;
|
|
}
|