processor-bridge.mjs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import path from 'node:path';
  2. import { createRequire } from 'node:module';
  3. import { PACKAGE_ROOT } from './config-loader.mjs';
  4. const require = createRequire(import.meta.url);
  5. const webhookServer = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'core', 'webhook-server.js'));
  6. const webhookTypes = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'core', 'webhook-types.js'));
  7. const agentService = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'dashboard', 'agent-service.js'));
  8. const dashboardServer = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'dashboard', 'server.js'));
  9. const loginTools = require(path.join(PACKAGE_ROOT, 'mcp', 'src', 'tools', 'qiwei-login-run.js'));
  10. export async function processRelayEnvelope(envelope) {
  11. const events = webhookTypes.parseWebhookEnvelope(envelope);
  12. const webhookResult = await webhookServer.processWebhookEvents({
  13. ...envelope,
  14. source: 'enterprise-relay',
  15. });
  16. if (Number(webhookResult.errors || 0) > 0) {
  17. throw new Error(`Webhook processor reported ${webhookResult.errors} error(s).`);
  18. }
  19. return {
  20. ...webhookResult,
  21. total: events.length,
  22. };
  23. }
  24. export function syncConversations() {
  25. return agentService.syncConversations();
  26. }
  27. export function startPersonalListener() {
  28. return agentService.startListener({ automatic: true });
  29. }
  30. export function stopPersonalListener(options = {}) {
  31. return agentService.stopListener(options);
  32. }
  33. export function getPersonalListenerStatus() {
  34. return agentService.getAgentStatus();
  35. }
  36. export function recoverPersonalLogin() {
  37. return loginTools.qiweiLoginCheck({ manual: true, persistConfig: false });
  38. }
  39. export function startDashboard(port) {
  40. return dashboardServer.startServer(port);
  41. }