- Add OpenClawProcessOwner class to manage the lifecycle of the OpenClaw process. - Introduce utility functions for managing OpenClaw runtime paths. - Update session store to normalize agent session keys and migrate existing keys. - Refactor main process to handle local provider API routing through a new dispatch function. - Enhance token usage writer to utilize a new session key parsing function. - Create agents management store to handle agent data and interactions. - Update chat store to integrate agent selection and session management. - Introduce AgentsSection component for displaying agent information in the UI. - Refactor HomePage to support agent selection and display current agent. - Update routing to reflect new agents page structure.
47 lines
1.3 KiB
TypeScript
47 lines
1.3 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 { handleFileRoutes } from './routes/files';
|
|
import { handleGatewayRoutes } from './routes/gateway';
|
|
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,
|
|
handleAgentRoutes,
|
|
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;
|
|
}
|