Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(companions): inject connection reader during desktop bootstrap

Chris88f14da5ebcf
diff --git a/apps/desktop/src/main/bootstrap-electron.ts b/apps/desktop/src/main/bootstrap-electron.ts
index 3fb364efa2..81932d849b 100644
--- a/apps/desktop/src/main/bootstrap-electron.ts
+++ b/apps/desktop/src/main/bootstrap-electron.ts
@@ -291,6 +291,10 @@ import {
startImConnection,
stopImConnection,
} from './im';
+import { buildBotImConnectionListPayload } from './im/shared/botImConnectionRuntime.js';
+import { readWechatChannelSettings } from './im/wechat/channelSettings.js';
+import { readXCompanionAssignment } from './hook-control/ipc.js';
+import type { BotControlState } from '@cindy/mcps';
import { setTelegramRemoteSource } from './device-link/telegramRemoteControl';
import * as authManager from './authManager';
import { createAuthCredentialRecovery } from './authCredentialRecovery';
@@ -692,6 +696,7 @@ import {
restartCodexAfterAuthModeChange,
waitForInitialCustomMcpRefresh,
registerPiAgentIfAvailable,
+ setBotConversationConnectionsReader,
} from './maker-host/index.js';
import { createPiRuntimeRecovery } from './agent-binaries/pi-runtime-recovery.js';
import { createDynamicMaker } from './maker-host/dynamic-maker.js';
@@ -6257,6 +6262,17 @@ const registerIpcHandlers = () => {
disposePiRuntimeRecovery = () => piRuntimeRecovery.dispose();
const registerMakerIpcsAfterSplash = async (): Promise<void> => {
if (makerIpcsRegistered) return;
+ // Compose here: IM runtime and hook IPC depend on maker-host, so the host
+ // receives a reader instead of importing those modules during tool calls.
+ setBotConversationConnectionsReader(async (botId) => {
+ const connections: NonNullable<BotControlState['conversations']>['connections'] =
+ buildBotImConnectionListPayload(botId).connections
+ .map(record => ({ channel: record.service ?? record.channel, connectionId: record.id, status: record.status.kind }));
+ if (readWechatChannelSettings().companionBotId === botId) connections.push({ channel: 'wechat', status: 'assigned' });
+ const x = readXCompanionAssignment();
+ if (x?.botId === botId) connections.push({ channel: 'x', status: x.enabled ? 'assigned' : 'disabled' });
+ return connections;
+ });
// 模型供应商目录(providers.json)按「OSS 真源 / bundled 兜底」加载一次存内存:必须在第一次
// getMakerCore()(下面构造 Maker、同步从 getActiveCatalog() 派生 availableModels)之前完成,
// 否则首个进程会用内置兜底目录派生模型清单。ensureActiveCatalogLoaded 幂等且永不抛
diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.ts
index 8cfa70e925..98e0557087 100644
--- a/apps/desktop/src/main/maker-host/index.ts
+++ b/apps/desktop/src/main/maker-host/index.ts
@@ -666,6 +666,15 @@ export async function refreshCodexGatewayHost(
// clears owner-scoped bookkeeping by epoch. Keep it across resetMaker; IPC is not
// registered again after an account switch. MCP factories bind before it is ready.
let _resolveBotCapabilityAgentKind: BotCapabilityServiceDeps['resolveBotAgentKind'] | null = null;
+// Bootstrap owns IM/hook modules that depend back on this host. Bind their reader
+// once, but read the current owner's stores on each call (including after resetMaker).
+let _readBotConversationConnections: BotCapabilityServiceDeps['readConversationConnections'];
+export function setBotConversationConnectionsReader(
+ reader: NonNullable<BotCapabilityServiceDeps['readConversationConnections']>,
+): void {
+ _readBotConversationConnections = reader;
+}
+
export function setBotCapabilityAgentKindResolver(
resolver: BotCapabilityServiceDeps['resolveBotAgentKind'] | null,
): void {
@@ -895,18 +904,8 @@ function createDesktopBotCapabilityService() {
getMaker, getPluginRegistry, isBotToolsetAvailable,
listMcpServers: listBotRuntimeMcpServers,
readConversationConnections: async (botId) => {
- const [{ buildBotImConnectionListPayload }, { readWechatChannelSettings }, { readXCompanionAssignment }] = await Promise.all([
- import('../im/shared/botImConnectionRuntime.js'),
- import('../im/wechat/channelSettings.js'),
- import('../hook-control/ipc.js'),
- ]);
- const connections: NonNullable<import('@cindy/mcps').BotControlState['conversations']>['connections'] =
- buildBotImConnectionListPayload(botId).connections
- .map(record => ({ channel: record.service ?? record.channel, connectionId: record.id, status: record.status.kind }));
- if (readWechatChannelSettings().companionBotId === botId) connections.push({ channel: 'wechat', status: 'assigned' });
- const x = readXCompanionAssignment();
- if (x?.botId === botId) connections.push({ channel: 'x', status: x.enabled ? 'assigned' : 'disabled' });
- return connections;
+ if (!_readBotConversationConnections) throw new Error('Bot conversation connections reader is not initialized');
+ return _readBotConversationConnections(botId);
},
resolveBotAgentKind: async (sessionId, chain) => _resolveBotCapabilityAgentKind?.(sessionId, chain) ?? null,
});