@@ -17,6 +17,7 @@ import { FileOperationResult, IFileService, toFileOperationResult } from '../../
17
17
import { ILogService } from '../../../../platform/log/common/log.js' ;
18
18
import { IStorageService , StorageScope , StorageTarget } from '../../../../platform/storage/common/storage.js' ;
19
19
import { ITelemetryService } from '../../../../platform/telemetry/common/telemetry.js' ;
20
+ import { IUserDataProfilesService } from '../../../../platform/userDataProfile/common/userDataProfile.js' ;
20
21
import { IWorkspaceContextService } from '../../../../platform/workspace/common/workspace.js' ;
21
22
import { ILifecycleService } from '../../../services/lifecycle/common/lifecycle.js' ;
22
23
import { ChatModel , ISerializableChatData , ISerializableChatDataIn , ISerializableChatsData , normalizeSerializableChatData } from './chatModel.js' ;
@@ -29,6 +30,7 @@ const ChatIndexStorageKey = 'chat.ChatSessionStore.index';
29
30
30
31
export class ChatSessionStore extends Disposable {
31
32
private readonly storageRoot : URI ;
33
+ private readonly previousEmptyWindowStorageRoot : URI | undefined ;
32
34
// private readonly transferredSessionStorageRoot: URI;
33
35
34
36
private readonly storeQueue = new Sequencer ( ) ;
@@ -44,15 +46,20 @@ export class ChatSessionStore extends Disposable {
44
46
@ITelemetryService private readonly telemetryService : ITelemetryService ,
45
47
@IStorageService private readonly storageService : IStorageService ,
46
48
@ILifecycleService private readonly lifecycleService : ILifecycleService ,
49
+ @IUserDataProfilesService private readonly userDataProfilesService : IUserDataProfilesService ,
47
50
) {
48
51
super ( ) ;
49
52
50
53
const workspace = this . workspaceContextService . getWorkspace ( ) ;
51
54
const isEmptyWindow = ! workspace . configuration && workspace . folders . length === 0 ;
52
- const workspaceId = isEmptyWindow ?
53
- 'no-workspace' :
54
- this . workspaceContextService . getWorkspace ( ) . id ;
55
- this . storageRoot = joinPath ( this . environmentService . workspaceStorageHome , workspaceId , 'chatSessions' ) ;
55
+ const workspaceId = this . workspaceContextService . getWorkspace ( ) . id ;
56
+ this . storageRoot = isEmptyWindow ?
57
+ joinPath ( this . userDataProfilesService . defaultProfile . globalStorageHome , 'emptyWindowChatSessions' ) :
58
+ joinPath ( this . environmentService . workspaceStorageHome , workspaceId , 'chatSessions' ) ;
59
+
60
+ this . previousEmptyWindowStorageRoot = isEmptyWindow ?
61
+ joinPath ( this . environmentService . workspaceStorageHome , 'no-workspace' , 'chatSessions' ) :
62
+ undefined ;
56
63
57
64
// TODO tmpdir
58
65
// this.transferredSessionStorageRoot = joinPath(this.environmentService.workspaceStorageHome, 'transferredChatSessions');
@@ -309,13 +316,20 @@ export class ChatSessionStore extends Disposable {
309
316
310
317
public async readSession ( sessionId : string ) : Promise < ISerializableChatData | undefined > {
311
318
return await this . storeQueue . queue ( async ( ) => {
312
- let rawData : string ;
319
+ let rawData : string | undefined ;
313
320
const storageLocation = this . getStorageLocation ( sessionId ) ;
314
321
try {
315
322
rawData = ( await this . fileService . readFile ( storageLocation ) ) . value . toString ( ) ;
316
323
} catch ( e ) {
317
324
this . reportError ( 'sessionReadFile' , `Error reading chat session file ${ sessionId } ` , e ) ;
318
- return undefined ;
325
+
326
+ if ( toFileOperationResult ( e ) === FileOperationResult . FILE_NOT_FOUND && this . previousEmptyWindowStorageRoot ) {
327
+ rawData = await this . readSessionFromPreviousLocation ( sessionId ) ;
328
+ }
329
+
330
+ if ( ! rawData ) {
331
+ return undefined ;
332
+ }
319
333
}
320
334
321
335
try {
@@ -343,6 +357,23 @@ export class ChatSessionStore extends Disposable {
343
357
} ) ;
344
358
}
345
359
360
+ private async readSessionFromPreviousLocation ( sessionId : string ) : Promise < string | undefined > {
361
+ let rawData : string | undefined ;
362
+
363
+ if ( this . previousEmptyWindowStorageRoot ) {
364
+ const storageLocation2 = joinPath ( this . previousEmptyWindowStorageRoot , `${ sessionId } .json` ) ;
365
+ try {
366
+ rawData = ( await this . fileService . readFile ( storageLocation2 ) ) . value . toString ( ) ;
367
+ this . logService . info ( `ChatSessionStore: Read chat session ${ sessionId } from previous location` ) ;
368
+ } catch ( e ) {
369
+ this . reportError ( 'sessionReadFile' , `Error reading chat session file ${ sessionId } from previous location` , e ) ;
370
+ return undefined ;
371
+ }
372
+ }
373
+
374
+ return rawData ;
375
+ }
376
+
346
377
private getStorageLocation ( chatSessionId : string ) : URI {
347
378
return joinPath ( this . storageRoot , `${ chatSessionId } .json` ) ;
348
379
}
0 commit comments