|
4 | 4 | * SPDX-License-Identifier: Apache-2.0 |
5 | 5 | */ |
6 | 6 |
|
7 | | -import {PerformanceInsightFormatter} from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceInsightFormatter.js'; |
| 7 | +import {PerformanceTraceFormatter} from '../../node_modules/chrome-devtools-frontend/front_end/models/ai_assistance/data_formatters/PerformanceTraceFormatter.js'; |
8 | 8 | import * as TraceEngine from '../../node_modules/chrome-devtools-frontend/front_end/models/trace/trace.js'; |
9 | 9 | import {logger} from '../logger.js'; |
| 10 | +import {AgentFocus} from 'chrome-devtools-frontend/front_end/panels/timeline/utils/AIContext.js'; |
| 11 | +import {EventsSerializer} from 'chrome-devtools-frontend/front_end/models/trace/EventsSerializer.js'; |
10 | 12 |
|
11 | 13 | const engine = TraceEngine.TraceModel.Model.createWithAllHandlers(); |
12 | 14 |
|
@@ -62,38 +64,9 @@ export async function parseRawTraceBuffer( |
62 | 64 | // TODO(jactkfranklin): move the formatters from DevTools to use here. |
63 | 65 | // This is a very temporary helper to output some text from the tool call to aid development. |
64 | 66 | export function insightOutput(result: TraceResult): string { |
65 | | - const mainNavigationId = |
66 | | - result.parsedTrace.data.Meta.mainFrameNavigations.at(0)?.args.data |
67 | | - ?.navigationId; |
68 | | - if (!mainNavigationId) { |
69 | | - return ''; |
70 | | - } |
71 | | - |
72 | | - let text = ''; |
73 | | - const insightsForNav = result.insights.get(mainNavigationId); |
74 | | - if (!insightsForNav) { |
75 | | - text += 'No Performance insights were found for this trace.'; |
76 | | - return text; |
77 | | - } |
78 | | - |
79 | | - const failingInsightKeys = Object.keys(insightsForNav.model).filter( |
80 | | - insightKey => { |
81 | | - const key = insightKey as keyof TraceEngine.Insights.Types.InsightModels; |
82 | | - const data = insightsForNav.model[key] ?? null; |
83 | | - return data?.state === 'fail'; |
84 | | - }, |
85 | | - ) as Array<keyof TraceEngine.Insights.Types.InsightModels>; |
86 | | - logger(`Found failing Insight keys: ${failingInsightKeys.join(', ')}`); |
87 | | - |
88 | | - for (const failingKey of failingInsightKeys) { |
89 | | - const modelData = insightsForNav.model[failingKey]; |
90 | | - const formatter = new PerformanceInsightFormatter( |
91 | | - result.parsedTrace, |
92 | | - modelData, |
93 | | - ); |
94 | | - |
95 | | - const output = formatter.formatInsight(); |
96 | | - text += `${output}\n`; |
97 | | - } |
98 | | - return text; |
| 67 | + const focus = AgentFocus.full(result.parsedTrace); |
| 68 | + const serializer = new EventsSerializer(); |
| 69 | + const formatter = new PerformanceTraceFormatter(focus, serializer); |
| 70 | + const output = formatter.formatTraceSummary(); |
| 71 | + return output; |
99 | 72 | } |
0 commit comments