import path from 'node:path'; import { createRequire } from 'node:module'; import { PACKAGE_ROOT } from './config-loader.mjs'; const require = createRequire(import.meta.url); const webhookServer = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'core', 'webhook-server.js')); const webhookTypes = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'core', 'webhook-types.js')); const agentService = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'dashboard', 'agent-service.js')); const dashboardServer = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'dashboard', 'server.js')); const loginTools = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'tools', 'qiwei-login-run.js')); export async function processRelayEnvelope(envelope) { const events = webhookTypes.parseWebhookEnvelope(envelope); const webhookResult = await webhookServer.processWebhookEvents({ ...envelope, source: 'enterprise-relay', }); if (Number(webhookResult.errors || 0) > 0) { throw new Error(`Webhook processor reported ${webhookResult.errors} error(s).`); } return { ...webhookResult, total: events.length, }; } export function syncConversations() { return agentService.syncConversations(); } export function startPersonalListener() { return agentService.startListener({ automatic: true }); } export function stopPersonalListener(options = {}) { return agentService.stopListener(options); } export function getPersonalListenerStatus() { return agentService.getAgentStatus(); } export function recoverPersonalLogin() { return loginTools.qiweiLoginCheck({ manual: true, persistConfig: false }); } export function startDashboard(port) { return dashboardServer.startServer(port); }