@@ -7,7 +7,7 @@ import { basename } from 'vs/base/common/resources';
7
7
import { URI } from 'vs/base/common/uri' ;
8
8
import { IRange } from 'vs/editor/common/core/range' ;
9
9
import { IChatProgressRenderableResponseContent , IChatProgressResponseContent } from 'vs/workbench/contrib/chat/common/chatModel' ;
10
- import { IChatAgentMarkdownContentWithVulnerability , IChatAgentVulnerabilityDetails , IChatContentInlineReference } from 'vs/workbench/contrib/chat/common/chatService' ;
10
+ import { IChatAgentMarkdownContentWithVulnerability , IChatAgentVulnerabilityDetails , IChatContentInlineReference , IChatMarkdownContent } from 'vs/workbench/contrib/chat/common/chatService' ;
11
11
12
12
export const contentRefUrl = 'http://_vscodecontentref_' ; // must be lowercase for URI
13
13
@@ -43,16 +43,40 @@ export function annotateSpecialMarkdownContent(response: ReadonlyArray<IChatProg
43
43
}
44
44
45
45
export interface IMarkdownVulnerability {
46
- title : string ;
47
- description : string ;
48
- range : IRange ;
46
+ readonly title : string ;
47
+ readonly description : string ;
48
+ readonly range : IRange ;
49
+ }
50
+
51
+ export function annotateVulnerabilitiesInText ( response : ReadonlyArray < IChatProgressResponseContent > ) : readonly IChatMarkdownContent [ ] {
52
+ const result : IChatMarkdownContent [ ] = [ ] ;
53
+ for ( const item of response ) {
54
+ const previousItem = result [ result . length - 1 ] ;
55
+ if ( item . kind === 'markdownContent' ) {
56
+ if ( previousItem ?. kind === 'markdownContent' ) {
57
+ result [ result . length - 1 ] = { content : new MarkdownString ( previousItem . content . value + item . content . value , { isTrusted : previousItem . content . isTrusted } ) , kind : 'markdownContent' } ;
58
+ } else {
59
+ result . push ( item ) ;
60
+ }
61
+ } else if ( item . kind === 'markdownVuln' ) {
62
+ const vulnText = encodeURIComponent ( JSON . stringify ( item . vulnerabilities ) ) ;
63
+ const markdownText = `<vscode_annotation details='${ vulnText } '>${ item . content . value } </vscode_annotation>` ;
64
+ if ( previousItem ?. kind === 'markdownContent' ) {
65
+ result [ result . length - 1 ] = { content : new MarkdownString ( previousItem . content . value + markdownText , { isTrusted : previousItem . content . isTrusted } ) , kind : 'markdownContent' } ;
66
+ } else {
67
+ result . push ( { content : new MarkdownString ( markdownText ) , kind : 'markdownContent' } ) ;
68
+ }
69
+ }
70
+ }
71
+
72
+ return result ;
49
73
}
50
74
51
75
export function extractVulnerabilitiesFromText ( text : string ) : { newText : string ; vulnerabilities : IMarkdownVulnerability [ ] } {
52
76
const vulnerabilities : IMarkdownVulnerability [ ] = [ ] ;
53
77
let newText = text ;
54
78
let match : RegExpExecArray | null ;
55
- while ( ( match = / < v s c o d e _ a n n o t a t i o n d e t a i l s = " ( .* ?) " > ( .* ?) < \/ v s c o d e _ a n n o t a t i o n > / ms. exec ( newText ) ) !== null ) {
79
+ while ( ( match = / < v s c o d e _ a n n o t a t i o n d e t a i l s = [ " ' ] ( .* ?) [ " ' ] > ( .* ?) < \/ v s c o d e _ a n n o t a t i o n > / ms. exec ( newText ) ) !== null ) {
56
80
const [ full , details , content ] = match ;
57
81
const start = match . index ;
58
82
const textBefore = newText . substring ( 0 , start ) ;
0 commit comments