Refine desktop setup and remove bundled app center apps
This commit is contained in:
79
electron/api/routes/agent-system-documents.ts
Normal file
79
electron/api/routes/agent-system-documents.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import type { IncomingMessage, ServerResponse } from 'node:http';
|
||||
import {
|
||||
isAgentSystemDocumentKind,
|
||||
readAgentSystemDocuments,
|
||||
resetAgentSystemDocument,
|
||||
saveAgentSystemDocument,
|
||||
} from '../../utils/agent-system-documents';
|
||||
import type { HostApiContext } from '../context';
|
||||
import { parseJsonBody, sendJson } from '../route-utils';
|
||||
|
||||
function scheduleGatewayReload(ctx: HostApiContext): void {
|
||||
if (ctx.gatewayManager.getStatus().state !== 'stopped') {
|
||||
ctx.gatewayManager.debouncedReload();
|
||||
}
|
||||
}
|
||||
|
||||
function parseDocumentPath(url: URL): { kind: string; reset: boolean } | null {
|
||||
const prefix = '/api/agent-system-documents/';
|
||||
if (!url.pathname.startsWith(prefix)) return null;
|
||||
|
||||
const parts = url.pathname.slice(prefix.length).split('/').filter(Boolean);
|
||||
if (parts.length === 1) {
|
||||
return { kind: decodeURIComponent(parts[0]), reset: false };
|
||||
}
|
||||
if (parts.length === 2 && parts[1] === 'reset') {
|
||||
return { kind: decodeURIComponent(parts[0]), reset: true };
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function handleAgentSystemDocumentRoutes(
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
url: URL,
|
||||
ctx: HostApiContext,
|
||||
): Promise<boolean> {
|
||||
if (url.pathname === '/api/agent-system-documents' && req.method === 'GET') {
|
||||
try {
|
||||
sendJson(res, 200, await readAgentSystemDocuments(url.searchParams.get('agentId') ?? undefined));
|
||||
} catch (error) {
|
||||
sendJson(res, 500, { success: false, error: String(error) });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
const parsed = parseDocumentPath(url);
|
||||
if (!parsed) return false;
|
||||
|
||||
if (!isAgentSystemDocumentKind(parsed.kind)) {
|
||||
sendJson(res, 404, { success: false, error: `Unsupported system document kind "${parsed.kind}"` });
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!parsed.reset && req.method === 'PUT') {
|
||||
try {
|
||||
const body = await parseJsonBody<{ agentId?: string; content?: string }>(req);
|
||||
const snapshot = await saveAgentSystemDocument(body.agentId, parsed.kind, body.content ?? '');
|
||||
scheduleGatewayReload(ctx);
|
||||
sendJson(res, 200, snapshot);
|
||||
} catch (error) {
|
||||
sendJson(res, 500, { success: false, error: String(error) });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (parsed.reset && req.method === 'POST') {
|
||||
try {
|
||||
const body = await parseJsonBody<{ agentId?: string }>(req);
|
||||
const snapshot = await resetAgentSystemDocument(body.agentId, parsed.kind);
|
||||
scheduleGatewayReload(ctx);
|
||||
sendJson(res, 200, snapshot);
|
||||
} catch (error) {
|
||||
sendJson(res, 500, { success: false, error: String(error) });
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
import type { IncomingMessage, ServerResponse } from 'http';
|
||||
import type { HostApiContext } from '../context';
|
||||
import { sendJson } from '../route-utils';
|
||||
import {
|
||||
ensureNianxxPlayServiceStarted,
|
||||
getNianxxPlayServiceStatus,
|
||||
} from '../../utils/nianxx-play-service';
|
||||
|
||||
export async function handleAppIntegrationRoutes(
|
||||
req: IncomingMessage,
|
||||
res: ServerResponse,
|
||||
url: URL,
|
||||
_ctx: HostApiContext,
|
||||
): Promise<boolean> {
|
||||
if (url.pathname === '/api/apps/nianxx-play/status' && req.method === 'GET') {
|
||||
sendJson(res, 200, await getNianxxPlayServiceStatus());
|
||||
return true;
|
||||
}
|
||||
|
||||
if (url.pathname === '/api/apps/nianxx-play/start' && req.method === 'POST') {
|
||||
sendJson(res, 200, await ensureNianxxPlayServiceStarted());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import {
|
||||
listAgentsSnapshotFromConfig,
|
||||
} from '../../utils/agent-config';
|
||||
import {
|
||||
ensureFeishuPluginInstalled,
|
||||
ensureWeChatPluginInstalled,
|
||||
} from '../../utils/plugin-install';
|
||||
import {
|
||||
@@ -80,7 +81,7 @@ import type { HostApiContext } from '../context';
|
||||
import { parseJsonBody, sendJson } from '../route-utils';
|
||||
|
||||
const WECHAT_QR_TIMEOUT_MS = 8 * 60 * 1000;
|
||||
const DISABLED_PLUGIN_CHANNEL_TYPES = new Set(['dingtalk', 'wecom', 'feishu']);
|
||||
const DISABLED_PLUGIN_CHANNEL_TYPES = new Set(['dingtalk', 'wecom']);
|
||||
const activeQrLogins = new Map<string, string>();
|
||||
|
||||
interface WebLoginStartResult {
|
||||
@@ -1568,6 +1569,13 @@ export async function handleChannelRoutes(
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (storedChannelType === 'feishu') {
|
||||
const installResult = await ensureFeishuPluginInstalled();
|
||||
if (!installResult.installed) {
|
||||
sendJson(res, 500, { success: false, error: installResult.warning || 'Feishu plugin install failed' });
|
||||
return true;
|
||||
}
|
||||
}
|
||||
const existingValues = await getChannelFormValues(body.channelType, body.accountId);
|
||||
if (isSameConfigValues(existingValues, body.config)) {
|
||||
await ensureScopedChannelBinding(body.channelType, body.accountId);
|
||||
|
||||
@@ -82,6 +82,7 @@ export async function handleProviderRoutes(
|
||||
const body = await parseJsonBody<{ accountId: string }>(req);
|
||||
const currentDefault = await providerService.getDefaultAccountId();
|
||||
if (currentDefault === body.accountId) {
|
||||
await syncDefaultProviderToRuntime(body.accountId, ctx.gatewayManager);
|
||||
sendJson(res, 200, { success: true, noChange: true });
|
||||
return true;
|
||||
}
|
||||
@@ -174,6 +175,7 @@ export async function handleProviderRoutes(
|
||||
const body = await parseJsonBody<{ providerId: string }>(req);
|
||||
const currentDefault = await providerService.getDefaultLegacyProvider();
|
||||
if (currentDefault === body.providerId) {
|
||||
await syncDefaultProviderToRuntime(body.providerId, ctx.gatewayManager);
|
||||
sendJson(res, 200, { success: true, noChange: true });
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ import { logger } from '../utils/logger';
|
||||
import { extensionRegistry } from '../extensions/registry';
|
||||
import type { HostApiContext } from './context';
|
||||
import { handleAppRoutes } from './routes/app';
|
||||
import { handleAppIntegrationRoutes } from './routes/apps';
|
||||
import { handleGatewayRoutes } from './routes/gateway';
|
||||
import { handleSettingsRoutes } from './routes/settings';
|
||||
import { handleProviderRoutes } from './routes/providers';
|
||||
import { handleAgentRoutes } from './routes/agents';
|
||||
import { handleAgentSystemDocumentRoutes } from './routes/agent-system-documents';
|
||||
import { handleChannelRoutes } from './routes/channels';
|
||||
import { handleLogRoutes } from './routes/logs';
|
||||
import { handleUsageRoutes } from './routes/usage';
|
||||
@@ -31,11 +31,11 @@ type RouteHandler = (
|
||||
|
||||
const coreRouteHandlers: RouteHandler[] = [
|
||||
handleAppRoutes,
|
||||
handleAppIntegrationRoutes,
|
||||
handleGatewayRoutes,
|
||||
handleSettingsRoutes,
|
||||
handleProviderRoutes,
|
||||
handleAgentRoutes,
|
||||
handleAgentSystemDocumentRoutes,
|
||||
handleChannelRoutes,
|
||||
handleSkillRoutes,
|
||||
handleFileRoutes,
|
||||
|
||||
Reference in New Issue
Block a user