44 * SPDX-License-Identifier: Apache-2.0
55 */
66
7+ import {
8+ AggregatedIssue ,
9+ MarkdownIssueDescription ,
10+ } from '../../node_modules/chrome-devtools-frontend/mcp/mcp.js' ;
11+ import { ISSUE_UTILS } from '../issue-descriptions.js' ;
12+
713export interface ConsoleMessageData {
814 consoleMessageStableId : number ;
915 type ?: string ;
@@ -34,12 +40,19 @@ function getArgs(msg: ConsoleMessageData) {
3440
3541// The verbose format for a console message, including all details.
3642export function formatConsoleEventVerbose ( msg : ConsoleMessageData ) : string {
43+ if ( msg . item instanceof AggregatedIssue ) {
44+ const result = [
45+ `ID: ${ msg . consoleMessageStableId } ` ,
46+ `Message: ${ msg . type } > ${ formatIssue ( msg . item ) } ` ,
47+ ] ;
48+ return result . join ( '\n' ) ;
49+ }
50+
3751 const result = [
3852 `ID: ${ msg . consoleMessageStableId } ` ,
3953 `Message: ${ msg . type } > ${ msg . message } ` ,
4054 formatArgs ( msg ) ,
4155 ] . filter ( line => ! ! line ) ;
42-
4356 return result . join ( '\n' ) ;
4457}
4558
@@ -62,3 +75,36 @@ function formatArgs(consoleData: ConsoleMessageData): string {
6275
6376 return result . join ( '\n' ) ;
6477}
78+
79+ export function formatIssue ( issue : AggregatedIssue ) : string {
80+ const markdownDescription = issue . getDescription ( ) ;
81+ const filename = markdownDescription ?. file ;
82+ const rawMarkdown = filename
83+ ? ISSUE_UTILS . getIssueDescription ( filename )
84+ : null ;
85+ if ( ! markdownDescription || ! rawMarkdown ) {
86+ throw new Error ( 'Error parsing issue description ' + issue . code ( ) ) ;
87+ }
88+ let processedMarkdown = MarkdownIssueDescription . substitutePlaceholders (
89+ rawMarkdown ,
90+ markdownDescription . substitutions ,
91+ ) ;
92+
93+ processedMarkdown = processedMarkdown . trim ( ) ;
94+ // Remove heading in order not to conflict with the result response markdown
95+ if ( processedMarkdown . startsWith ( '# ' ) ) {
96+ processedMarkdown = processedMarkdown . substring ( 2 ) . trimStart ( ) ;
97+ }
98+
99+ const result : string [ ] = [ processedMarkdown ] ;
100+ const links = markdownDescription . links ;
101+
102+ if ( links . length > 0 ) {
103+ result . push ( 'Learn more:' ) ;
104+ for ( const link of links ) {
105+ result . push ( `[${ link . linkTitle } ](${ link . link } )` ) ;
106+ }
107+ }
108+
109+ return result . join ( '\n' ) ;
110+ }
0 commit comments