(
part: Extract<OpencodePart, { type: 'reasoning' }>,
delta: string | undefined,
)
| 226 | } |
| 227 | |
| 228 | function* handleReasoningPart( |
| 229 | part: Extract<OpencodePart, { type: 'reasoning' }>, |
| 230 | delta: string | undefined, |
| 231 | ): Generator<StreamChunk> { |
| 232 | yield* closeText() |
| 233 | |
| 234 | const prev = textAccumulators.get(part.id) ?? '' |
| 235 | let deltaText: string |
| 236 | if (typeof delta === 'string' && delta !== '') { |
| 237 | deltaText = delta |
| 238 | textAccumulators.set(part.id, prev + delta) |
| 239 | } else { |
| 240 | const full = part.text |
| 241 | deltaText = full.startsWith(prev) ? full.slice(prev.length) : full |
| 242 | textAccumulators.set(part.id, full) |
| 243 | } |
| 244 | if (deltaText === '') return |
| 245 | |
| 246 | if (openReasoningId !== part.id) { |
| 247 | yield* closeReasoning() |
| 248 | openReasoningId = part.id |
| 249 | yield { |
| 250 | type: EventType.REASONING_START, |
| 251 | messageId: part.id, |
| 252 | model, |
| 253 | timestamp: now(), |
| 254 | } |
| 255 | yield { |
| 256 | type: EventType.REASONING_MESSAGE_START, |
| 257 | messageId: part.id, |
| 258 | role: 'reasoning' as const, |
| 259 | model, |
| 260 | timestamp: now(), |
| 261 | } |
| 262 | } |
| 263 | yield { |
| 264 | type: EventType.REASONING_MESSAGE_CONTENT, |
| 265 | messageId: part.id, |
| 266 | delta: deltaText, |
| 267 | model, |
| 268 | timestamp: now(), |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | function* openToolCall( |
| 273 | part: Extract<OpencodePart, { type: 'tool' }>, |
no test coverage detected