startup-summary.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. function buildStartupSummary(status = {}, agent = {}) {
  2. const summary = status.summary || {};
  3. const data = agent.data || {};
  4. const account = data.account || {};
  5. const listener = data.listener || {};
  6. const ingress = data.ingress || {};
  7. const product = data.product || { mode: 'personal', label: '个人版', collectionLabel: '本地主动监听', relayReady: false };
  8. const allowedSenderCount = Number(data.config?.allowedSenderCount || 0);
  9. const checks = [
  10. { key: 'auth', label: 'Fmode 鉴权', ready: Boolean(summary.authConfigured), action: '在 Fmode Studio 登录当前账号后重新启动' },
  11. { key: 'subscription', label: '企微席位', ready: Boolean(summary.subscribed), action: '在工作台打开订阅与登录流程,先开通席位' },
  12. { key: 'account', label: '企微账号', ready: Boolean(account.online), action: account.configured ? '在工作台点击“恢复登录”' : '在工作台完成企微扫码登录' },
  13. ...(product.mode === 'enterprise' ? [{ key: 'relay', label: '企业回调', ready: Boolean(ingress.running), action: '等待 MCP 自动连接服务端回调并启动 Relay 消费守护进程' }] : []),
  14. { key: 'allowlist', label: '测试白名单', ready: allowedSenderCount > 0, action: '配置至少一个测试联系人白名单' },
  15. ...(product.mode === 'personal' ? [{ key: 'listener', label: 'AI 监听', ready: Boolean(listener.running), action: '账号在线后,在智能会话页点击“启动 AI 监听”' }] : []),
  16. ];
  17. const next = checks.find(item => !item.ready);
  18. return {
  19. ready: checks.every(item => item.ready),
  20. checks,
  21. nextAction: next?.action || '工作台已就绪,可以进入智能会话进行测试',
  22. authConfigured: Boolean(summary.authConfigured),
  23. subscribed: Boolean(summary.subscribed),
  24. accountConfigured: Boolean(account.configured),
  25. online: Boolean(account.online),
  26. allowedSenderCount,
  27. listenerRunning: product.mode === 'personal' ? Boolean(listener.running) : false,
  28. callbackRunning: product.mode === 'enterprise' ? Boolean(ingress.running) : false,
  29. product,
  30. };
  31. }
  32. function startupAssistantMessage(startup = {}) {
  33. const stateText = (startup.checks || []).map(item => `${item.label}${item.ready ? '完成' : '待处理'}`).join(',');
  34. const productText = startup.product?.label ? `${startup.product.label}(${startup.product.collectionLabel})` : '当前模式';
  35. return `企微智能工作台已启动,当前为${productText}。${stateText}。下一步:${startup.nextAction}`;
  36. }
  37. module.exports = { buildStartupSummary, startupAssistantMessage };