(request: IpcRequest)
| 159 | } |
| 160 | |
| 161 | private async handleRequest(request: IpcRequest): Promise<void> { |
| 162 | if (!this.agent || !this.conversationService) { |
| 163 | this.replyError(request.id, "IPC adapter is not ready yet"); |
| 164 | return; |
| 165 | } |
| 166 | |
| 167 | try { |
| 168 | switch (request.type) { |
| 169 | case "get_conversations": { |
| 170 | const activeChannels = new Set(this.agent.getActiveChannelIds()); |
| 171 | for (const channelId of this.createdChannels) { |
| 172 | activeChannels.add(channelId); |
| 173 | } |
| 174 | const conversations = this.conversationService.listConversations( |
| 175 | activeChannels, |
| 176 | { |
| 177 | includeDefaultWeb: true, |
| 178 | includeLegacyWeb: false, |
| 179 | }, |
| 180 | ); |
| 181 | this.reply(request.id, conversations); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | case "create_conversation": { |
| 186 | const channelId = DEFAULT_WEB_CHANNEL_ID; |
| 187 | this.createdChannels.add(channelId); |
| 188 | this.reply(request.id, { channelId }); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | case "get_messages": { |
| 193 | if (!request.channelId || typeof request.channelId !== "string") { |
| 194 | this.replyError(request.id, "channelId is required"); |
| 195 | return; |
| 196 | } |
| 197 | const messages = this.conversationService.getMessages( |
| 198 | request.channelId, |
| 199 | request.limit ?? 100, |
| 200 | ); |
| 201 | this.reply(request.id, messages); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | case "send_message": { |
| 206 | if (!request.channelId || typeof request.channelId !== "string") { |
| 207 | this.replyError(request.id, "channelId is required"); |
| 208 | return; |
| 209 | } |
| 210 | if (typeof request.text !== "string") { |
| 211 | this.replyError(request.id, "text is required"); |
| 212 | return; |
| 213 | } |
| 214 | |
| 215 | const platform = this.detectPlatform(request.channelId); |
| 216 | const attachments = this.normalizeAttachments(request.attachments); |
| 217 | this.createdChannels.add(request.channelId); |
| 218 |
no test coverage detected