Files
zn-ai/electron/api/router.ts
duanshuwen 5cc9b86e1f refactor: update knowledge document types and API client interfaces
- Refactored types in `Knowledge/types.ts` to introduce new interfaces for document handling.
- Added `KnowledgeDocItem`, `KnowledgeDocsListResponse`, `KnowledgeDocsUploadInput`, `KnowledgeDocsUploadResponse`, and `KnowledgeDocsDeleteResponse` for better structure and clarity.
- Updated `KnowledgeDocsApiClient` interface to include methods for listing, uploading, and deleting documents.

fix: replace deprecated icons in AccountSettingsPanel and SettingMenu

- Replaced `CheckCircleIcon` with `CheckCircle` from `lucide-react` in `AccountSettingsPanel.tsx`.
- Updated `SettingMenu.tsx` to use `Settings` and `User` from `lucide-react` instead of custom icons.

test: add tests for knowledge docs routes and KnowledgePage

- Created `knowledge-docs-routes.test.ts` to test API routes for listing, uploading, and deleting knowledge documents.
- Added `knowledge-page.test.tsx` to test the rendering and functionality of the KnowledgePage component, including document loading and deletion.
2026-04-19 09:40:07 +08:00

55 lines
1.6 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 { handleKnowledgeRoutes } from './routes/knowledge';
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,
handleKnowledgeRoutes,
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;
}