( events: OpenHandsEvent[], includeToolDetails: boolean, )
| 266 | ); |
| 267 | |
| 268 | const buildTranscriptEntries = ( |
| 269 | events: OpenHandsEvent[], |
| 270 | includeToolDetails: boolean, |
| 271 | ): TranscriptEntry[] => { |
| 272 | const uiEvents = events.reduce<OpenHandsEvent[]>((current, event) => { |
| 273 | try { |
| 274 | return handleEventForUI(event, current); |
| 275 | } catch { |
| 276 | return current; |
| 277 | } |
| 278 | }, []); |
| 279 | const actionsById = new Map( |
| 280 | events.filter(isActionEvent).map((event) => [event.id, event]), |
| 281 | ); |
| 282 | const entries: TranscriptEntry[] = []; |
| 283 | const emittedNarrationActionIds = new Set<string>(); |
| 284 | const renderableEvents = uiEvents.filter( |
| 285 | (event) => |
| 286 | (isSwitchLLMObservationEvent(event) && !event.observation.is_error) || |
| 287 | (isClassifyAndSwitchLLMObservationEvent(event) && |
| 288 | !event.observation.is_error) || |
| 289 | shouldRenderEvent(event), |
| 290 | ); |
| 291 | const renderedItems = groupEvents( |
| 292 | renderableEvents, |
| 293 | Number.MAX_SAFE_INTEGER, |
| 294 | events, |
| 295 | ); |
| 296 | |
| 297 | const addActionNarration = (action: ActionEvent) => { |
| 298 | if ( |
| 299 | emittedNarrationActionIds.has(action.id) || |
| 300 | !canRenderActionNarration(action) |
| 301 | ) { |
| 302 | return; |
| 303 | } |
| 304 | emittedNarrationActionIds.add(action.id); |
| 305 | const content = getActionNarration(action); |
| 306 | if (content) { |
| 307 | entries.push({ |
| 308 | kind: "message", |
| 309 | author: "assistant", |
| 310 | content, |
| 311 | timestamp: action.timestamp, |
| 312 | }); |
| 313 | } |
| 314 | }; |
| 315 | |
| 316 | for (const item of renderedItems) { |
| 317 | if (item.kind === "group") continue; |
| 318 | if (item.kind === "thought") { |
| 319 | addActionNarration(item.action); |
| 320 | continue; |
| 321 | } |
| 322 | |
| 323 | const { event } = item; |
| 324 | try { |
| 325 | const narrationAction = isActionEvent(event) |
no test coverage detected