@@ -37,6 +37,7 @@ import { ILanguageModelChatMetadata, ILanguageModelChatMetadataAndIdentifier } f
3737import { IChatAgentCommand , IChatAgentData , IChatAgentResult , IChatAgentService , UserSelectedTools , reviveSerializedAgent } from '../participants/chatAgents.js' ;
3838import { ChatRequestTextPart , IParsedChatRequest , reviveParsedChatRequest } from '../requestParser/chatParserTypes.js' ;
3939import { LocalChatSessionUri } from './chatUri.js' ;
40+ import { ObjectMutationLog } from './objectMutationLog.js' ;
4041
4142
4243export const CHAT_ATTACHABLE_IMAGE_MIME_TYPES : Record < string , string > = {
@@ -210,6 +211,8 @@ export interface IChatResponseModel {
210211 readonly completedAt ?: number ;
211212 /** The state of this response */
212213 readonly state : ResponseModelState ;
214+ /** @internal */
215+ readonly stateT : ResponseModelStateT ;
213216 /**
214217 * Adjusted millisecond timestamp that excludes the duration during which
215218 * the model was pending user confirmation. `Date.now() - confirmationAdjustedTimestamp`
@@ -792,7 +795,7 @@ export interface IChatResponseModelParameters {
792795 codeBlockInfos : ICodeBlockInfo [ ] | undefined ;
793796}
794797
795- type ResponseModelStateT =
798+ export type ResponseModelStateT =
796799 | { value : ResponseModelState . Pending }
797800 | { value : ResponseModelState . NeedsInput }
798801 | { value : ResponseModelState . Complete | ResponseModelState . Cancelled | ResponseModelState . Failed ; completedAt : number } ;
@@ -869,6 +872,10 @@ export class ChatResponseModel extends Disposable implements IChatResponseModel
869872 return state ;
870873 }
871874
875+ public get stateT ( ) : ResponseModelStateT {
876+ return this . _modelState . get ( ) ;
877+ }
878+
872879 public get vote ( ) : ChatAgentVoteDirection | undefined {
873880 return this . _vote ;
874881 }
@@ -1398,9 +1405,7 @@ export interface ISerializableChatModelInputState {
13981405*/
13991406export type ISerializableChatData = ISerializableChatData3 ;
14001407
1401- export interface IChatDataSerializerLog {
1402- write ( current : IChatModel ) : { op : 'append' | 'replace' ; data : VSBuffer } ;
1403- }
1408+ export type IChatDataSerializerLog = ObjectMutationLog < IChatModel , ISerializableChatData > ;
14041409
14051410export interface ISerializedChatDataReference {
14061411 value : ISerializableChatData | IExportableChatData ;
@@ -1736,7 +1741,7 @@ export class ChatModel extends Disposable implements IChatModel {
17361741 public dataSerializer ?: IChatDataSerializerLog ;
17371742
17381743 constructor (
1739- initialData : ISerializedChatDataReference | undefined ,
1744+ dataRef : ISerializedChatDataReference | undefined ,
17401745 initialModelProps : { initialLocation : ChatAgentLocation ; canUseTools : boolean ; inputState ?: ISerializableChatModelInputState ; resource ?: URI ; sessionId ?: string ; disableBackgroundKeepAlive ?: boolean } ,
17411746 @IConfigurationService private readonly configurationService : IConfigurationService ,
17421747 @ILogService private readonly logService : ILogService ,
@@ -1746,6 +1751,7 @@ export class ChatModel extends Disposable implements IChatModel {
17461751 ) {
17471752 super ( ) ;
17481753
1754+ const initialData = dataRef ?. value ;
17491755 const isValidExportedData = isExportableSessionData ( initialData ) ;
17501756 const isValidFullData = isValidExportedData && isSerializableSessionData ( initialData ) ;
17511757 if ( initialData && ! isValidExportedData ) {
@@ -1775,9 +1781,9 @@ export class ChatModel extends Disposable implements IChatModel {
17751781 selections : serializedInputState . selections
17761782 } ) ;
17771783
1778- this . dataSerializer = initialData ?. serializer ;
1779- this . _initialResponderUsername = initialData ?. value . responderUsername ;
1780- this . _initialLocation = initialData ?. value . initialLocation ?? initialModelProps . initialLocation ;
1784+ this . dataSerializer = dataRef ?. serializer ;
1785+ this . _initialResponderUsername = initialData ?. responderUsername ;
1786+ this . _initialLocation = initialData ?. initialLocation ?? initialModelProps . initialLocation ;
17811787
17821788 this . _canUseTools = initialModelProps . canUseTools ;
17831789
@@ -1918,6 +1924,11 @@ export class ChatModel extends Disposable implements IChatModel {
19181924 const result = 'responseErrorDetails' in raw ?
19191925 // eslint-disable-next-line local/code-no-dangerous-type-assertions
19201926 { errorDetails : raw . responseErrorDetails } as IChatAgentResult : raw . result ;
1927+ let modelState = raw . modelState || { value : raw . isCanceled ? ResponseModelState . Cancelled : ResponseModelState . Complete , completedAt : Date . now ( ) } ;
1928+ if ( modelState . value === ResponseModelState . Pending || modelState . value === ResponseModelState . NeedsInput ) {
1929+ modelState = { value : ResponseModelState . Cancelled , completedAt : Date . now ( ) } ;
1930+ }
1931+
19211932 request . response = new ChatResponseModel ( {
19221933 responseContent : raw . response ?? [ new MarkdownString ( raw . response ) ] ,
19231934 session : this ,
0 commit comments