@@ -19,13 +19,6 @@ import { Response } from 'express';
1919import { ConnectionEntity } from '../../connection/connection.entity.js' ;
2020import { IDataAccessObject } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object.interface.js' ;
2121import { IDataAccessObjectAgent } from '@rocketadmin/shared-code/dist/src/data-access-layer/shared/interfaces/data-access-object-agent.interface.js' ;
22-
23- declare module 'express-session' {
24- interface Session {
25- lastResponseId ?: string | null ;
26- }
27- }
28-
2922@Injectable ( { scope : Scope . REQUEST } )
3023export class RequestInfoFromTableWithAIUseCaseV4
3124 extends AbstractUseCase < RequestInfoFromTableDSV2 , void >
@@ -41,8 +34,8 @@ export class RequestInfoFromTableWithAIUseCaseV4
4134 }
4235
4336 public async implementation ( inputData : RequestInfoFromTableDSV2 ) : Promise < void > {
44- const { connectionId, tableName, user_message, master_password, user_id, response } = inputData ;
45- this . initializeSession ( response ) ;
37+ const { connectionId, tableName, user_message, master_password, user_id, response, previous_response_id } =
38+ inputData ;
4639 this . setupResponseHeaders ( response ) ;
4740
4841 const { foundConnection, dataAccessObject, databaseType, isMongoDb, userEmail } = await this . setupConnection (
@@ -60,7 +53,7 @@ export class RequestInfoFromTableWithAIUseCaseV4
6053 system_prompt ,
6154 user_id ,
6255 tools ,
63- response ,
56+ previous_response_id ,
6457 ) ;
6558 const currentDepth = 0 ;
6659 await this . handleStreamRecursively (
@@ -230,7 +223,6 @@ export class RequestInfoFromTableWithAIUseCaseV4
230223 }
231224 response . write ( chunk . delta ) ;
232225 }
233- response . req . session . lastResponseId = current_response_id ;
234226 }
235227 }
236228
@@ -387,16 +379,6 @@ export class RequestInfoFromTableWithAIUseCaseV4
387379 response . setHeader ( 'Connection' , 'keep-alive' ) ;
388380 }
389381
390- private initializeSession ( response : any ) : void {
391- if ( ! response . req . session ) {
392- ( response . req as any ) . session = {
393- lastResponseId : null ,
394- } ;
395- } else if ( response . req . session . lastResponseId === undefined ) {
396- response . req . session . lastResponseId = null ;
397- }
398- }
399-
400382 private async setupConnection ( connectionId : string , master_password : string , user_id : string ) {
401383 const foundConnection = await this . _dbContext . connectionRepository . findAndDecryptConnection (
402384 connectionId ,
@@ -481,7 +463,7 @@ Remember that all responses should be clear and user-friendly, explaining techni
481463 system_prompt : string ,
482464 user_id : string ,
483465 tools : any [ ] ,
484- response : any ,
466+ previous_response_id : string | null = null ,
485467 ) {
486468 const openApiKey = getRequiredEnvVariable ( 'OPENAI_API_KEY' ) ;
487469 const openai = new OpenAI ( { apiKey : openApiKey } ) ;
@@ -493,7 +475,7 @@ Remember that all responses should be clear and user-friendly, explaining techni
493475 user : user_id ,
494476 stream : true ,
495477 tools : tools ,
496- previous_response_id : response . req . session . lastResponseId || undefined ,
478+ previous_response_id : previous_response_id || undefined ,
497479 } ) ;
498480 }
499481
0 commit comments