@@ -31,7 +31,7 @@ import {
3131 listSessionsFromStore ,
3232 loadCombinedSessionStoreForGateway ,
3333 loadSessionEntry ,
34- pruneLegacyStoreKeys ,
34+ migrateAndPruneGatewaySessionStoreKey ,
3535 readSessionPreviewItemsFromTranscript ,
3636 resolveGatewaySessionStoreTarget ,
3737 resolveSessionModelRef ,
@@ -92,31 +92,6 @@ function rejectWebchatSessionMutation(params: {
9292 return true ;
9393}
9494
95- function migrateAndPruneSessionStoreKey ( params : {
96- cfg : ReturnType < typeof loadConfig > ;
97- key : string ;
98- store : Record < string , SessionEntry > ;
99- } ) {
100- const target = resolveGatewaySessionStoreTarget ( {
101- cfg : params . cfg ,
102- key : params . key ,
103- store : params . store ,
104- } ) ;
105- const primaryKey = target . canonicalKey ;
106- if ( ! params . store [ primaryKey ] ) {
107- const existingKey = target . storeKeys . find ( ( candidate ) => Boolean ( params . store [ candidate ] ) ) ;
108- if ( existingKey ) {
109- params . store [ primaryKey ] = params . store [ existingKey ] ;
110- }
111- }
112- pruneLegacyStoreKeys ( {
113- store : params . store ,
114- canonicalKey : primaryKey ,
115- candidates : target . storeKeys ,
116- } ) ;
117- return { target, primaryKey, entry : params . store [ primaryKey ] } ;
118- }
119-
12095export const sessionsHandlers : GatewayRequestHandlers = {
12196 "sessions.list" : ( { params, respond } ) => {
12297 if ( ! assertValidParams ( params , validateSessionsListParams , "sessions.list" , respond ) ) {
@@ -224,7 +199,7 @@ export const sessionsHandlers: GatewayRequestHandlers = {
224199
225200 const { cfg, target, storePath } = resolveGatewaySessionTargetFromKey ( key ) ;
226201 const applied = await updateSessionStore ( storePath , async ( store ) => {
227- const { primaryKey } = migrateAndPruneSessionStoreKey ( { cfg, key, store } ) ;
202+ const { primaryKey } = migrateAndPruneGatewaySessionStoreKey ( { cfg, key, store } ) ;
228203 return await applySessionsPatchToStore ( {
229204 cfg,
230205 store,
@@ -316,7 +291,7 @@ export const sessionsHandlers: GatewayRequestHandlers = {
316291 }
317292 const sessionId = entry ?. sessionId ;
318293 const deleted = await updateSessionStore ( storePath , ( store ) => {
319- const { primaryKey } = migrateAndPruneSessionStoreKey ( { cfg, key, store } ) ;
294+ const { primaryKey } = migrateAndPruneGatewaySessionStoreKey ( { cfg, key, store } ) ;
320295 const hadEntry = Boolean ( store [ primaryKey ] ) ;
321296 if ( hadEntry ) {
322297 delete store [ primaryKey ] ;
@@ -385,7 +360,7 @@ export const sessionsHandlers: GatewayRequestHandlers = {
385360 const { cfg, target, storePath } = resolveGatewaySessionTargetFromKey ( key ) ;
386361 // Lock + read in a short critical section; transcript work happens outside.
387362 const compactTarget = await updateSessionStore ( storePath , ( store ) => {
388- const { entry, primaryKey } = migrateAndPruneSessionStoreKey ( { cfg, key, store } ) ;
363+ const { entry, primaryKey } = migrateAndPruneGatewaySessionStoreKey ( { cfg, key, store } ) ;
389364 return { entry, primaryKey } ;
390365 } ) ;
391366 const entry = compactTarget . entry ;
0 commit comments