MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / buildTranscriptEntries

Function buildTranscriptEntries

src/utils/transcript-export/index.ts:270–590  ·  view source on GitHub ↗
(
  events: OpenHandsEvent[],
  includeToolDetails: boolean,
)

Source from the content-addressed store, hash-verified

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

Callers 2

eventsToMarkdownFunction · 0.85
eventsToHtmlFunction · 0.85

Calls 15

handleEventForUIFunction · 0.90
deliveredAnswerIdsFunction · 0.90
shouldRenderEventFunction · 0.90
groupEventsFunction · 0.90
isActionEventFunction · 0.90
isObservationEventFunction · 0.90
isUserRejectObservationFunction · 0.90
isMessageEventFunction · 0.90
parseMessageFromEventFunction · 0.90
splitInlineThinkFunction · 0.90

Tested by

no test coverage detected