feat: prepare Zhinian desktop pilot
Some checks failed
Electron E2E / Electron E2E (macos-latest) (push) Has been cancelled
Electron E2E / Electron E2E (ubuntu-latest) (push) Has been cancelled
Electron E2E / Electron E2E (windows-latest) (push) Has been cancelled

This commit is contained in:
inman
2026-05-07 21:49:20 +08:00
parent cddaf37016
commit 0abc48189c
103 changed files with 10975 additions and 2049 deletions

View File

@@ -1,7 +1,7 @@
import type { IncomingMessage, ServerResponse } from 'node:http';
import crypto from 'node:crypto';
import { basename, extname, join } from 'node:path';
import { mkdir, readFile, stat, writeFile, copyFile } from 'node:fs/promises';
import { mkdir, readFile, stat, writeFile, copyFile, rm } from 'node:fs/promises';
import type { HostApiContext } from '../context';
import { parseJsonBody, sendJson } from '../route-utils';
import { getDataDir } from '../../utils/paths';
@@ -225,6 +225,27 @@ export async function buildKnowledgeContext(params: {
};
}
async function deleteKnowledgeDocument(params: {
workspaceId?: string;
documentId: string;
}): Promise<{ deleted: KnowledgeDocument | null }> {
const workspaceId = sanitizeWorkspaceId(params.workspaceId);
const documentId = params.documentId.trim();
if (!documentId) return { deleted: null };
const registry = await readRegistry(workspaceId);
const target = registry.find((doc) => doc.id === documentId);
if (!target) return { deleted: null };
await Promise.all([
target.storedPath ? rm(target.storedPath, { force: true }).catch(() => undefined) : Promise.resolve(),
target.textPath ? rm(target.textPath, { force: true }).catch(() => undefined) : Promise.resolve(),
]);
await writeRegistry(workspaceId, registry.filter((doc) => doc.id !== documentId));
return { deleted: target };
}
export async function handleKnowledgeRoutes(
req: IncomingMessage,
res: ServerResponse,
@@ -238,6 +259,22 @@ export async function handleKnowledgeRoutes(
return true;
}
if (url.pathname.startsWith('/api/knowledge/files/') && req.method === 'DELETE') {
try {
const documentId = decodeURIComponent(url.pathname.slice('/api/knowledge/files/'.length));
const workspaceId = sanitizeWorkspaceId(url.searchParams.get('workspaceId') ?? undefined);
const result = await deleteKnowledgeDocument({ workspaceId, documentId });
if (!result.deleted) {
sendJson(res, 404, { success: false, error: 'Knowledge document not found' });
return true;
}
sendJson(res, 200, { success: true, document: result.deleted });
} catch (error) {
sendJson(res, 500, { success: false, error: String(error) });
}
return true;
}
if (url.pathname === '/api/knowledge/import-paths' && req.method === 'POST') {
try {
const body = await parseJsonBody<{ workspaceId?: string; filePaths?: string[] }>(req);