@@ -16,18 +16,18 @@ marked.use(
1616 } )
1717) ;
1818
19- enum ChatResultOutcome {
19+ export enum ChatResultOutcome {
2020 Success = "success" ,
2121 Error = "error" ,
2222 Finished = "finished" ,
2323}
2424
25- enum ChatResultRole {
25+ export enum ChatResultRole {
2626 Assistant = "assistant" ,
2727 User = "user" ,
2828}
2929
30- type ChatResult = {
30+ export type ChatResult = {
3131 outcome : ChatResultOutcome ;
3232 textContent : string ;
3333 role : ChatResultRole ;
@@ -38,15 +38,21 @@ export type ChatRequestData = {
3838 message : string ;
3939} ;
4040
41+ export type CodeReviewRequestData = {
42+ kind : "review_request" ;
43+ main : string ;
44+ current : string ;
45+ } ;
46+
4147export type RecipeRequestData = {
4248 kind : "recipe_request" ;
4349 name : string ;
4450 id : string ;
4551} ;
4652
4753export type ChatRequest = {
48- type : "recipe_request" | "chat_request" ;
49- data : ChatRequestData | RecipeRequestData ;
54+ type : "recipe_request" | "chat_request" | "review_request" ;
55+ data : ChatRequestData | RecipeRequestData | CodeReviewRequestData ;
5056 context_range ?: any ;
5157} ;
5258
@@ -60,7 +66,7 @@ export type OpenLinkRequest = {
6066 link : string ;
6167} ;
6268
63- type InsertAtCursorInstruction = {
69+ export type InsertAtCursorInstruction = {
6470 type : "insert_at_cursor" ;
6571 content : string ;
6672} ;
@@ -214,7 +220,7 @@ export class ChatProvider implements vscode.WebviewViewProvider {
214220 this . _currentAssistantMessage = result . textContent ;
215221 }
216222
217- let sanitized = this . renderAssistantMessage ( this . _currentAssistantMessage ) ;
223+ let sanitized = renderAssistantMessage ( this . _currentAssistantMessage ) ;
218224
219225 this . _view . webview . postMessage ( {
220226 command : "add_result" ,
@@ -226,23 +232,6 @@ export class ChatProvider implements vscode.WebviewViewProvider {
226232 } ) ;
227233 }
228234
229- private renderAssistantMessage ( message : string ) {
230- // Send the whole message we've been streamed so far to the webview,
231- // after converting from markdown to html
232-
233- const rendered = marked ( message , {
234- gfm : true ,
235- breaks : true ,
236- mangle : false ,
237- headerIds : false ,
238- } ) ;
239-
240- // Allow any classes on span and code blocks or highlightjs classes get removed
241- return sanitizeHtml ( rendered , {
242- allowedClasses : { span : false , code : false } ,
243- } ) ;
244- }
245-
246235 public clearChat ( ) {
247236 this . _view . webview . postMessage ( { command : "clear_chat" } ) ;
248237 this . _currentAssistantMessage = "" ;
@@ -316,7 +305,6 @@ export class ChatProvider implements vscode.WebviewViewProvider {
316305 <section id="message-container" class="sidebar__section-container active" data-section="chat-assistant">
317306 <ul class="sidebar__chat-assistant--dialogue-container">
318307
319- <li id="anchor"></li>
320308 </ul>
321309 </section>
322310 <footer class="sidebar__chat-assistant--footer">
@@ -344,3 +332,24 @@ export class ChatProvider implements vscode.WebviewViewProvider {
344332 </html>` ;
345333 }
346334}
335+
336+ export function renderAssistantMessage ( message : string ) {
337+ // Send the whole message we've been streamed so far to the webview,
338+ // after converting from markdown to html
339+
340+ const rendered = marked ( message , {
341+ gfm : true ,
342+ breaks : true ,
343+ mangle : false ,
344+ headerIds : false ,
345+ } ) ;
346+
347+ // Allow any classes on span and code blocks or highlightjs classes get removed
348+ return sanitizeHtml ( rendered , {
349+ allowedTags : sanitizeHtml . defaults . allowedTags . concat ( [
350+ "details" ,
351+ "summary" ,
352+ ] ) ,
353+ allowedClasses : { span : false , code : false } ,
354+ } ) ;
355+ }
0 commit comments