@@ -551,28 +551,38 @@ export const SessionRoutes = lazy(() =>
551551 async ( c ) => {
552552 const sessionID = c . req . valid ( "param" ) . sessionID
553553 const body = c . req . valid ( "json" )
554- const session = await Session . get ( sessionID )
555- await SessionRevert . cleanup ( session )
556- const msgs = await Session . messages ( { sessionID } )
557- const defaultAgent = await AppRuntime . runPromise ( Agent . Service . use ( ( svc ) => svc . defaultAgent ( ) ) )
558- let currentAgent = defaultAgent
559- for ( let i = msgs . length - 1 ; i >= 0 ; i -- ) {
560- const info = msgs [ i ] . info
561- if ( info . role === "user" ) {
562- currentAgent = info . agent || defaultAgent
563- break
564- }
565- }
566- await SessionCompaction . create ( {
567- sessionID,
568- agent : currentAgent ,
569- model : {
570- providerID : body . providerID ,
571- modelID : body . modelID ,
572- } ,
573- auto : body . auto ,
574- } )
575- await SessionPrompt . loop ( { sessionID } )
554+ await AppRuntime . runPromise (
555+ Effect . gen ( function * ( ) {
556+ const session = yield * Session . Service
557+ const revert = yield * SessionRevert . Service
558+ const compact = yield * SessionCompaction . Service
559+ const prompt = yield * SessionPrompt . Service
560+ const agent = yield * Agent . Service
561+
562+ yield * revert . cleanup ( yield * session . get ( sessionID ) )
563+ const msgs = yield * session . messages ( { sessionID } )
564+ const defaultAgent = yield * agent . defaultAgent ( )
565+ let currentAgent = defaultAgent
566+ for ( let i = msgs . length - 1 ; i >= 0 ; i -- ) {
567+ const info = msgs [ i ] . info
568+ if ( info . role === "user" ) {
569+ currentAgent = info . agent || defaultAgent
570+ break
571+ }
572+ }
573+
574+ yield * compact . create ( {
575+ sessionID,
576+ agent : currentAgent ,
577+ model : {
578+ providerID : body . providerID ,
579+ modelID : body . modelID ,
580+ } ,
581+ auto : body . auto ,
582+ } )
583+ yield * prompt . loop ( { sessionID } )
584+ } ) ,
585+ )
576586 return c . json ( true )
577587 } ,
578588 )
0 commit comments