(block: ContentBlock)
| 162 | } |
| 163 | |
| 164 | function mapContentBlockBody(block: ContentBlock): PersistedContentBlock { |
| 165 | switch (block.type) { |
| 166 | case 'text': |
| 167 | return { |
| 168 | type: MothershipStreamV1EventType.text, |
| 169 | channel: MothershipStreamV1TextChannel.assistant, |
| 170 | content: block.content, |
| 171 | } |
| 172 | case 'thinking': |
| 173 | return { |
| 174 | type: MothershipStreamV1EventType.text, |
| 175 | channel: MothershipStreamV1TextChannel.thinking, |
| 176 | content: block.content, |
| 177 | } |
| 178 | case 'subagent': |
| 179 | return { |
| 180 | type: MothershipStreamV1EventType.span, |
| 181 | kind: MothershipStreamV1SpanPayloadKind.subagent, |
| 182 | lifecycle: MothershipStreamV1SpanLifecycleEvent.start, |
| 183 | content: block.content, |
| 184 | } |
| 185 | case 'subagent_text': |
| 186 | return { |
| 187 | type: MothershipStreamV1EventType.text, |
| 188 | lane: 'subagent', |
| 189 | channel: MothershipStreamV1TextChannel.assistant, |
| 190 | content: block.content, |
| 191 | } |
| 192 | case 'subagent_thinking': |
| 193 | return { |
| 194 | type: MothershipStreamV1EventType.text, |
| 195 | lane: 'subagent', |
| 196 | channel: MothershipStreamV1TextChannel.thinking, |
| 197 | content: block.content, |
| 198 | } |
| 199 | case 'tool_call': { |
| 200 | if (!block.toolCall) { |
| 201 | return { |
| 202 | type: MothershipStreamV1EventType.tool, |
| 203 | phase: MothershipStreamV1ToolPhase.call, |
| 204 | content: block.content, |
| 205 | } |
| 206 | } |
| 207 | const state = resolveToolState(block) |
| 208 | const isSubagentTool = !!block.calledBy |
| 209 | const isNonTerminal = |
| 210 | state === MothershipStreamV1ToolOutcome.cancelled || |
| 211 | state === 'pending' || |
| 212 | state === 'executing' |
| 213 | |
| 214 | const redactedResult = redactToolCallResult(block.toolCall.name, block.toolCall.result) |
| 215 | |
| 216 | const toolCall: PersistedToolCall = { |
| 217 | id: block.toolCall.id, |
| 218 | name: block.toolCall.name, |
| 219 | state, |
| 220 | ...(isSubagentTool && isNonTerminal ? {} : { result: redactedResult }), |
| 221 | ...(isSubagentTool && isNonTerminal |
no test coverage detected