(message: PersistedMessage)
| 267 | } |
| 268 | |
| 269 | export function withStoppedContentBlock(message: PersistedMessage): PersistedMessage { |
| 270 | const contentBlocks = message.contentBlocks ?? [] |
| 271 | const hasAssistantText = contentBlocks.some( |
| 272 | (block) => |
| 273 | block.type === MothershipStreamV1EventType.text && |
| 274 | block.channel !== MothershipStreamV1TextChannel.thinking && |
| 275 | block.content?.trim() |
| 276 | ) |
| 277 | if ( |
| 278 | contentBlocks.some( |
| 279 | (block) => |
| 280 | block.type === MothershipStreamV1EventType.complete && |
| 281 | block.status === MothershipStreamV1CompletionStatus.cancelled |
| 282 | ) |
| 283 | ) { |
| 284 | return message |
| 285 | } |
| 286 | |
| 287 | return normalizeMessage({ |
| 288 | ...message, |
| 289 | contentBlocks: [ |
| 290 | ...(hasAssistantText || !message.content.trim() |
| 291 | ? [] |
| 292 | : [ |
| 293 | { |
| 294 | type: MothershipStreamV1EventType.text, |
| 295 | channel: MothershipStreamV1TextChannel.assistant, |
| 296 | content: message.content, |
| 297 | }, |
| 298 | ]), |
| 299 | ...contentBlocks, |
| 300 | { |
| 301 | type: MothershipStreamV1EventType.complete, |
| 302 | status: MothershipStreamV1CompletionStatus.cancelled, |
| 303 | }, |
| 304 | ], |
| 305 | }) |
| 306 | } |
| 307 | |
| 308 | export interface UserMessageParams { |
| 309 | id: string |
no test coverage detected