@@ -25,7 +25,6 @@ import { ISelection } from '../../../../editor/common/core/selection.js';
2525import { TextEdit } from '../../../../editor/common/languages.js' ;
2626import { EditSuggestionId } from '../../../../editor/common/textModelEditSource.js' ;
2727import { localize } from '../../../../nls.js' ;
28- import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js' ;
2928import { ILogService } from '../../../../platform/log/common/log.js' ;
3029import { CellUri , ICellEditOperation } from '../../notebook/common/notebookCommon.js' ;
3130import { migrateLegacyTerminalToolSpecificData } from './chat.js' ;
@@ -1239,7 +1238,6 @@ export interface IExportableChatData {
12391238export interface ISerializableChatData1 extends IExportableChatData {
12401239 sessionId : string ;
12411240 creationDate : number ;
1242- isImported : boolean ;
12431241
12441242 /** Indicates that this session was created in this window. Is cleared after the chat has been written to storage once. Needed to sync chat creations/deletions between empty windows. */
12451243 isNew ?: boolean ;
@@ -1400,8 +1398,9 @@ function getLastYearDate(): number {
14001398}
14011399
14021400export function isExportableSessionData ( obj : unknown ) : obj is IExportableChatData {
1403- const data = obj as IExportableChatData ;
1404- return typeof data === 'object' ;
1401+ return ! ! obj &&
1402+ Array . isArray ( ( obj as IExportableChatData ) . requests ) &&
1403+ typeof ( obj as IExportableChatData ) . responderUsername === 'string' ;
14051404}
14061405
14071406export function isSerializableSessionData ( obj : unknown ) : obj is ISerializableChatData {
@@ -1652,26 +1651,26 @@ export class ChatModel extends Disposable implements IChatModel {
16521651 @IChatAgentService private readonly chatAgentService : IChatAgentService ,
16531652 @IChatEditingService private readonly chatEditingService : IChatEditingService ,
16541653 @IChatService chatService : IChatService ,
1655- @IConfigurationService configurationService : IConfigurationService ,
16561654 ) {
16571655 super ( ) ;
16581656
1659- const isValid = isSerializableSessionData ( initialData ) ;
1660- if ( initialData && ! isValid ) {
1657+ const isValidExportedData = isExportableSessionData ( initialData ) ;
1658+ const isValidFullData = isValidExportedData && isSerializableSessionData ( initialData ) ;
1659+ if ( initialData && ! isValidExportedData ) {
16611660 this . logService . warn ( `ChatModel#constructor: Loaded malformed session data: ${ JSON . stringify ( initialData ) } ` ) ;
16621661 }
16631662
1664- this . _isImported = ( ! ! initialData && ! isValid ) || ( initialData ?. isImported ?? false ) ;
1665- this . _sessionId = ( isValid && initialData . sessionId ) || initialModelProps . sessionId || generateUuid ( ) ;
1663+ this . _isImported = ! ! initialData && isValidExportedData && ! isValidFullData ;
1664+ this . _sessionId = ( isValidFullData && initialData . sessionId ) || initialModelProps . sessionId || generateUuid ( ) ;
16661665 this . _sessionResource = initialModelProps . resource ?? LocalChatSessionUri . forSession ( this . _sessionId ) ;
16671666
16681667 this . _requests = initialData ? this . _deserialize ( initialData ) : [ ] ;
1669- this . _timestamp = ( isValid && initialData . creationDate ) || Date . now ( ) ;
1670- this . _lastMessageDate = ( isValid && initialData . lastMessageDate ) || this . _timestamp ;
1671- this . _customTitle = isValid ? initialData . customTitle : undefined ;
1668+ this . _timestamp = ( isValidFullData && initialData . creationDate ) || Date . now ( ) ;
1669+ this . _lastMessageDate = ( isValidFullData && initialData . lastMessageDate ) || this . _timestamp ;
1670+ this . _customTitle = isValidFullData ? initialData . customTitle : undefined ;
16721671
16731672 // Initialize input model from serialized data (undefined for new chats)
1674- const serializedInputState = isValid && initialData . inputState ? initialData . inputState : undefined ;
1673+ const serializedInputState = isValidFullData && initialData . inputState ? initialData . inputState : undefined ;
16751674 this . inputModel = new InputModel ( serializedInputState && {
16761675 attachments : serializedInputState . attachments ,
16771676 mode : serializedInputState . mode ,
@@ -2121,7 +2120,6 @@ export class ChatModel extends Disposable implements IChatModel {
21212120 ...this . toExport ( ) ,
21222121 sessionId : this . sessionId ,
21232122 creationDate : this . _timestamp ,
2124- isImported : this . _isImported ,
21252123 lastMessageDate : this . _lastMessageDate ,
21262124 customTitle : this . _customTitle ,
21272125 // Only include inputState if it has been set
0 commit comments