remoteServiceAccess.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. import { IGenUiService } from "@zcode/services";
  2. import { ProxyChannel, type IChannelClient } from "@zcode/rpc";
  3. import {
  4. IFileService,
  5. IMediaPreviewService,
  6. IGitService,
  7. IGitCheckpointService,
  8. ISystemService,
  9. ITerminalService,
  10. ISettingService,
  11. IOnboardingRecordService,
  12. ICredentialService,
  13. IBroadcastService,
  14. IZCodeTaskService,
  15. IZCodeAgentService,
  16. IZCodeSessionService,
  17. ICuaPermissionService,
  18. IConversationShareService,
  19. IBotsService,
  20. IFileWatcherService,
  21. IOAuthService,
  22. IModelSelectionService,
  23. IProviderSettingsService,
  24. IProviderProvisioningTargetService,
  25. IUsageStatsService,
  26. ICodingPlanSubscriptionService,
  27. IClientConfigService,
  28. IClientScenesService,
  29. ICloudContentService,
  30. IMarketingTouchService,
  31. IOffPeakTaskService,
  32. IHighspeedCardService,
  33. ISkillsService,
  34. ISkillSyncService,
  35. IMcpSyncService,
  36. IPluginUiAppToolsService,
  37. IPluginUiSamplingService,
  38. IPluginUiBridgeService,
  39. IPluginSyncService,
  40. IPluginsService,
  41. IPluginManagementService,
  42. ISubagentsService,
  43. ICommandsService,
  44. IHooksService,
  45. IMemoryService,
  46. IOutputStyleService,
  47. ISettingsSyncService,
  48. IFeedbackService,
  49. IPromptAttachmentTransferService,
  50. IWindowControllerService,
  51. type IServiceAccessor,
  52. } from "@zcode/services";
  53. /**
  54. * RemoteServiceAccess — 通过 ChannelClient 自动创建类型安全的服务代理
  55. *
  56. * 新增服务只需在此添加一个 getter。
  57. */
  58. export class RemoteServiceAccess implements IServiceAccessor {
  59. readonly fileService: IFileService;
  60. readonly mediaPreviewService: IMediaPreviewService;
  61. readonly gitService: IGitService;
  62. readonly gitCheckpointService: IGitCheckpointService;
  63. readonly systemService: ISystemService;
  64. readonly terminalService: ITerminalService;
  65. readonly settingService: ISettingService;
  66. readonly onboardingRecordService: IOnboardingRecordService;
  67. readonly credentialService: ICredentialService;
  68. readonly broadcastService: IBroadcastService;
  69. readonly zcodeTaskService: IZCodeTaskService;
  70. readonly windowControllerService: IWindowControllerService;
  71. readonly zcodeAgentService: IZCodeAgentService;
  72. readonly zcodeSessionService: IZCodeSessionService;
  73. // cuaPermissionService 在 IServiceAccessor 上是可选(远端/bots host 不提供),但桌面 renderer
  74. // 经 RPC 一定能拿到(main host 始终注册此 descriptor;非 macOS / 未启用时方法返回 available:false)。
  75. readonly cuaPermissionService: ICuaPermissionService;
  76. readonly conversationShareService: IConversationShareService;
  77. readonly botsService: IBotsService;
  78. readonly fileWatcherService: IFileWatcherService;
  79. readonly oauthService: IOAuthService;
  80. readonly providerSettingsService: IProviderSettingsService;
  81. readonly modelSelectionService: IModelSelectionService;
  82. /** Host-only target proxy;不属于 IServiceAccessor,避免向 Renderer 暴露 Secret 写入接口。 */
  83. readonly providerProvisioningTargetService!: IProviderProvisioningTargetService;
  84. readonly usageStatsService: IUsageStatsService;
  85. readonly codingPlanSubscriptionService: ICodingPlanSubscriptionService;
  86. readonly clientConfigService: IClientConfigService;
  87. readonly clientScenesService: IClientScenesService;
  88. readonly cloudContentService: ICloudContentService;
  89. readonly marketingTouchService: IMarketingTouchService;
  90. readonly offPeakTaskService: IOffPeakTaskService;
  91. readonly highspeedCardService: IHighspeedCardService;
  92. readonly skillsService: ISkillsService;
  93. readonly skillSyncService: ISkillSyncService;
  94. readonly mcpSyncService: IMcpSyncService;
  95. readonly genUiService: IGenUiService;
  96. readonly pluginUiBridgeService: IPluginUiBridgeService;
  97. readonly pluginUiSamplingService: IPluginUiSamplingService;
  98. readonly pluginUiAppToolsService: IPluginUiAppToolsService;
  99. readonly pluginSyncService: IPluginSyncService;
  100. readonly pluginsService: IPluginsService;
  101. readonly pluginManagementService: IPluginManagementService;
  102. readonly subagentsService: ISubagentsService;
  103. readonly commandsService: ICommandsService;
  104. readonly hooksService: IHooksService;
  105. readonly memoryService: IMemoryService;
  106. readonly outputStyleService: IOutputStyleService;
  107. readonly settingsSyncService: ISettingsSyncService;
  108. readonly feedbackService: IFeedbackService;
  109. readonly promptAttachmentTransferService: IPromptAttachmentTransferService;
  110. constructor(channelClient: IChannelClient) {
  111. this.fileService = ProxyChannel.toService<IFileService>(
  112. channelClient.getChannel(IFileService.channelName),
  113. );
  114. // Host 已注册 media-preview channel,但遗漏 renderer proxy 时,PreviewPane
  115. // 会静默回退到 8 MiB 的 file.readMediaPreview,导致大 MP4 无法打开。
  116. this.mediaPreviewService = ProxyChannel.toService<IMediaPreviewService>(
  117. channelClient.getChannel(IMediaPreviewService.channelName),
  118. );
  119. this.gitService = ProxyChannel.toService<IGitService>(
  120. channelClient.getChannel(IGitService.channelName),
  121. );
  122. this.gitCheckpointService = ProxyChannel.toService<IGitCheckpointService>(
  123. channelClient.getChannel(IGitCheckpointService.channelName),
  124. );
  125. this.systemService = ProxyChannel.toService<ISystemService>(
  126. channelClient.getChannel(ISystemService.channelName),
  127. );
  128. this.terminalService = ProxyChannel.toService<ITerminalService>(
  129. channelClient.getChannel(ITerminalService.channelName),
  130. );
  131. this.settingService = ProxyChannel.toService<ISettingService>(
  132. channelClient.getChannel(ISettingService.channelName),
  133. );
  134. this.onboardingRecordService = ProxyChannel.toService<IOnboardingRecordService>(
  135. channelClient.getChannel(IOnboardingRecordService.channelName),
  136. );
  137. this.credentialService = ProxyChannel.toService<ICredentialService>(
  138. channelClient.getChannel(ICredentialService.channelName),
  139. );
  140. this.broadcastService = ProxyChannel.toService<IBroadcastService>(
  141. channelClient.getChannel(IBroadcastService.channelName),
  142. );
  143. this.zcodeTaskService = ProxyChannel.toService<IZCodeTaskService>(
  144. channelClient.getChannel(IZCodeTaskService.channelName),
  145. );
  146. this.windowControllerService = ProxyChannel.toService<IWindowControllerService>(
  147. channelClient.getChannel(IWindowControllerService.channelName),
  148. );
  149. this.zcodeAgentService = ProxyChannel.toService<IZCodeAgentService>(
  150. channelClient.getChannel(IZCodeAgentService.channelName),
  151. );
  152. this.zcodeSessionService = ProxyChannel.toService<IZCodeSessionService>(
  153. channelClient.getChannel(IZCodeSessionService.channelName),
  154. );
  155. this.cuaPermissionService = ProxyChannel.toService<ICuaPermissionService>(
  156. channelClient.getChannel(ICuaPermissionService.channelName),
  157. );
  158. this.conversationShareService = ProxyChannel.toService<IConversationShareService>(
  159. channelClient.getChannel(IConversationShareService.channelName),
  160. );
  161. this.botsService = ProxyChannel.toService<IBotsService>(
  162. channelClient.getChannel(IBotsService.channelName),
  163. );
  164. this.fileWatcherService = ProxyChannel.toService<IFileWatcherService>(
  165. channelClient.getChannel(IFileWatcherService.channelName),
  166. );
  167. this.oauthService = ProxyChannel.toService<IOAuthService>(
  168. channelClient.getChannel(IOAuthService.channelName),
  169. );
  170. this.providerSettingsService = ProxyChannel.toService<IProviderSettingsService>(
  171. channelClient.getChannel(IProviderSettingsService.channelName),
  172. );
  173. this.modelSelectionService = ProxyChannel.toService<IModelSelectionService>(
  174. channelClient.getChannel(IModelSelectionService.channelName),
  175. );
  176. Object.defineProperty(this, "providerProvisioningTargetService", {
  177. value: ProxyChannel.toService<IProviderProvisioningTargetService>(
  178. channelClient.getChannel(IProviderProvisioningTargetService.channelName),
  179. ),
  180. enumerable: false,
  181. });
  182. this.usageStatsService = ProxyChannel.toService<IUsageStatsService>(
  183. channelClient.getChannel(IUsageStatsService.channelName),
  184. );
  185. this.codingPlanSubscriptionService = ProxyChannel.toService<ICodingPlanSubscriptionService>(
  186. channelClient.getChannel(ICodingPlanSubscriptionService.channelName),
  187. );
  188. this.clientConfigService = ProxyChannel.toService<IClientConfigService>(
  189. channelClient.getChannel(IClientConfigService.channelName),
  190. );
  191. this.clientScenesService = ProxyChannel.toService<IClientScenesService>(
  192. channelClient.getChannel(IClientScenesService.channelName),
  193. );
  194. this.cloudContentService = ProxyChannel.toService<ICloudContentService>(
  195. channelClient.getChannel(ICloudContentService.channelName),
  196. );
  197. this.marketingTouchService = ProxyChannel.toService<IMarketingTouchService>(
  198. channelClient.getChannel(IMarketingTouchService.channelName),
  199. );
  200. this.offPeakTaskService = ProxyChannel.toService<IOffPeakTaskService>(
  201. channelClient.getChannel(IOffPeakTaskService.channelName),
  202. );
  203. this.highspeedCardService = ProxyChannel.toService<IHighspeedCardService>(
  204. channelClient.getChannel(IHighspeedCardService.channelName),
  205. );
  206. this.skillsService = ProxyChannel.toService<ISkillsService>(
  207. channelClient.getChannel(ISkillsService.channelName),
  208. );
  209. this.skillSyncService = ProxyChannel.toService<ISkillSyncService>(
  210. channelClient.getChannel(ISkillSyncService.channelName),
  211. );
  212. this.mcpSyncService = ProxyChannel.toService<IMcpSyncService>(
  213. channelClient.getChannel(IMcpSyncService.channelName),
  214. );
  215. this.genUiService = ProxyChannel.toService<IGenUiService>(
  216. channelClient.getChannel(IGenUiService.channelName),
  217. );
  218. this.pluginUiBridgeService = ProxyChannel.toService<IPluginUiBridgeService>(
  219. channelClient.getChannel(IPluginUiBridgeService.channelName),
  220. );
  221. this.pluginUiSamplingService = ProxyChannel.toService<IPluginUiSamplingService>(
  222. channelClient.getChannel(IPluginUiSamplingService.channelName),
  223. );
  224. this.pluginUiAppToolsService = ProxyChannel.toService<IPluginUiAppToolsService>(
  225. channelClient.getChannel(IPluginUiAppToolsService.channelName),
  226. );
  227. this.pluginSyncService = ProxyChannel.toService<IPluginSyncService>(
  228. channelClient.getChannel(IPluginSyncService.channelName),
  229. );
  230. this.pluginsService = ProxyChannel.toService<IPluginsService>(
  231. channelClient.getChannel(IPluginsService.channelName),
  232. );
  233. this.pluginManagementService = ProxyChannel.toService<IPluginManagementService>(
  234. channelClient.getChannel(IPluginManagementService.channelName),
  235. );
  236. this.subagentsService = ProxyChannel.toService<ISubagentsService>(
  237. channelClient.getChannel(ISubagentsService.channelName),
  238. );
  239. this.commandsService = ProxyChannel.toService<ICommandsService>(
  240. channelClient.getChannel(ICommandsService.channelName),
  241. );
  242. this.hooksService = ProxyChannel.toService<IHooksService>(
  243. channelClient.getChannel(IHooksService.channelName),
  244. );
  245. this.memoryService = ProxyChannel.toService<IMemoryService>(
  246. channelClient.getChannel(IMemoryService.channelName),
  247. );
  248. this.outputStyleService = ProxyChannel.toService<IOutputStyleService>(
  249. channelClient.getChannel(IOutputStyleService.channelName),
  250. );
  251. this.settingsSyncService = ProxyChannel.toService<ISettingsSyncService>(
  252. channelClient.getChannel(ISettingsSyncService.channelName),
  253. );
  254. this.feedbackService = ProxyChannel.toService<IFeedbackService>(
  255. channelClient.getChannel(IFeedbackService.channelName),
  256. );
  257. this.promptAttachmentTransferService = ProxyChannel.toService<IPromptAttachmentTransferService>(
  258. channelClient.getChannel(IPromptAttachmentTransferService.channelName),
  259. );
  260. }
  261. }