@@ -81,6 +81,53 @@ export class ChatRequestModel implements IChatRequestModel {
8181 }
8282}
8383
84+
85+ interface ResponsePart { string : IMarkdownString ; resolving ?: boolean }
86+ class Response {
87+ private _responseParts : ResponsePart [ ] ;
88+ private _responseRepr : IMarkdownString ;
89+
90+ get value ( ) : IMarkdownString {
91+ return this . _responseRepr ;
92+ }
93+
94+ constructor ( value : IMarkdownString ) {
95+ this . _responseRepr = value ;
96+ this . _responseParts = [ { string : value } ] ;
97+ }
98+
99+ updateContent ( responsePart : string | { placeholder : string ; resolvedContent ?: Promise < string > } ) : void {
100+ if ( typeof responsePart === 'string' ) {
101+ const responsePartLength = this . _responseParts . length - 1 ;
102+ const lastResponsePart = this . _responseParts [ responsePartLength ] ;
103+
104+ if ( lastResponsePart . resolving === true ) {
105+ // The last part is resolving, start a new part
106+ this . _responseParts . push ( { string : new MarkdownString ( responsePart ) } ) ;
107+ } else {
108+ // Combine this part with the last, non-resolving part
109+ this . _responseParts [ responsePartLength ] = { string : new MarkdownString ( lastResponsePart . string . value + responsePart ) } ;
110+ }
111+
112+ this . _updateRepr ( ) ;
113+ } else {
114+ // Add a new resolving part
115+ const responsePosition = this . _responseParts . push ( { string : new MarkdownString ( responsePart . placeholder ) , resolving : true } ) ;
116+ this . _updateRepr ( ) ;
117+
118+ responsePart . resolvedContent ?. then ( ( content ) => {
119+ // Replace the resolving part's content with the resolved response
120+ this . _responseParts [ responsePosition ] = { string : new MarkdownString ( content ) } ;
121+ this . _updateRepr ( ) ;
122+ } ) ;
123+ }
124+ }
125+
126+ private _updateRepr ( ) {
127+ this . _responseRepr = new MarkdownString ( this . _responseParts . map ( r => r . string . value ) . join ( '\n' ) ) ;
128+ }
129+ }
130+
84131export class ChatResponseModel extends Disposable implements IChatResponseModel {
85132 private readonly _onDidChange = this . _register ( new Emitter < void > ( ) ) ;
86133 readonly onDidChange = this . _onDidChange . event ;
@@ -112,8 +159,9 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
112159 return this . _followups ;
113160 }
114161
162+ private _response : Response ;
115163 public get response ( ) : IMarkdownString {
116- return this . _response ;
164+ return this . _response . value ;
117165 }
118166
119167 public get errorDetails ( ) : IChatResponseErrorDetails | undefined {
@@ -133,7 +181,7 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
133181 }
134182
135183 constructor (
136- private _response : IMarkdownString ,
184+ _response : IMarkdownString ,
137185 public readonly session : ChatModel ,
138186 private _isComplete : boolean = false ,
139187 private _isCanceled = false ,
@@ -143,13 +191,17 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
143191 private _followups ?: IChatFollowup [ ]
144192 ) {
145193 super ( ) ;
194+ this . _response = new Response ( _response ) ;
146195 this . _id = 'response_' + ChatResponseModel . nextId ++ ;
147196 }
148197
149- updateContent ( responsePart : string , quiet ?: boolean ) {
150- this . _response = new MarkdownString ( this . response . value + responsePart ) ;
151- if ( ! quiet ) {
152- this . _onDidChange . fire ( ) ;
198+ updateContent ( responsePart : string | { placeholder : string ; resolvedContent ?: Promise < string > } , quiet ?: boolean ) {
199+ try {
200+ this . _response . updateContent ( responsePart ) ;
201+ } finally {
202+ if ( ! quiet ) {
203+ this . _onDidChange . fire ( ) ;
204+ }
153205 }
154206 }
155207
@@ -453,6 +505,8 @@ export class ChatModel extends Disposable implements IChatModel {
453505
454506 if ( 'content' in progress ) {
455507 request . response . updateContent ( progress . content , quiet ) ;
508+ } else if ( 'placeholder' in progress ) {
509+ request . response . updateContent ( progress , quiet ) ;
456510 } else {
457511 request . setProviderRequestId ( progress . requestId ) ;
458512 request . response . setProviderResponseId ( progress . requestId ) ;
0 commit comments