- Introduced RequestContentDialog for displaying request content details. - Added UsageBarChart for visualizing token usage data. - Implemented UsageHistorySection to manage and display usage history with filtering and pagination. - Created provider-types for managing provider-related types. - Developed ModelsPage to encapsulate models configuration, providers, and usage history. - Defined usage-history types and utility functions for managing usage data. - Updated routing to include models page and redirect agents to models. - Refactored chat store to integrate models instead of agents. - Established models store for managing model-related state and data fetching.
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 { 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,
|
|
handleModelRoutes,
|
|
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;
|
|
}
|