@@ -522,6 +522,20 @@ export const layer: Layer.Layer<
522522 const storage = yield * Storage . Service
523523 const flags = yield * RuntimeFlags . Service
524524
525+ const locationForSession = Effect . fnUntraced ( function * ( sessionID : SessionID ) {
526+ const row = yield * db
527+ . select ( { directory : SessionTable . directory , workspaceID : SessionTable . workspace_id } )
528+ . from ( SessionTable )
529+ . where ( eq ( SessionTable . id , sessionID ) )
530+ . get ( )
531+ . pipe ( Effect . orDie )
532+ if ( ! row ) return
533+ return {
534+ directory : AbsolutePath . make ( row . directory ) ,
535+ workspaceID : row . workspaceID ?? undefined ,
536+ }
537+ } )
538+
525539 const createNext = Effect . fn ( "Session.createNext" ) ( function * ( input : {
526540 id ?: SessionID
527541 title ?: string
@@ -615,26 +629,26 @@ export const layer: Layer.Layer<
615629
616630 const updateMessage = < T extends SessionLegacy . Info > ( msg : T ) : Effect . Effect < T > =>
617631 Effect . gen ( function * ( ) {
618- const session = yield * get ( msg . sessionID )
632+ const location = yield * locationForSession ( msg . sessionID )
619633 yield * events . publish (
620634 SessionLegacy . Event . MessageUpdated ,
621635 { sessionID : msg . sessionID , info : msg } ,
622- { location : eventLocation ( session ) } ,
636+ { location } ,
623637 )
624638 return msg
625639 } ) . pipe ( Effect . withSpan ( "Session.updateMessage" ) )
626640
627641 const updatePart = < T extends SessionLegacy . Part > ( part : T ) : Effect . Effect < T > =>
628642 Effect . gen ( function * ( ) {
629- const session = yield * get ( part . sessionID )
643+ const location = yield * locationForSession ( part . sessionID )
630644 yield * events . publish (
631645 SessionLegacy . Event . PartUpdated ,
632646 {
633647 sessionID : part . sessionID ,
634648 part : structuredClone ( part ) ,
635649 time : Date . now ( ) ,
636650 } ,
637- { location : eventLocation ( session ) } ,
651+ { location } ,
638652 )
639653 return part
640654 } ) . pipe ( Effect . withSpan ( "Session.updatePart" ) )
@@ -828,14 +842,14 @@ export const layer: Layer.Layer<
828842 sessionID : SessionID
829843 messageID : MessageID
830844 } ) {
831- const session = yield * get ( input . sessionID )
845+ const location = yield * locationForSession ( input . sessionID )
832846 yield * events . publish (
833847 SessionLegacy . Event . MessageRemoved ,
834848 {
835849 sessionID : input . sessionID ,
836850 messageID : input . messageID ,
837851 } ,
838- { location : eventLocation ( session ) } ,
852+ { location } ,
839853 )
840854 return input . messageID
841855 } )
@@ -845,15 +859,15 @@ export const layer: Layer.Layer<
845859 messageID : MessageID
846860 partID : PartID
847861 } ) {
848- const session = yield * get ( input . sessionID )
862+ const location = yield * locationForSession ( input . sessionID )
849863 yield * events . publish (
850864 SessionLegacy . Event . PartRemoved ,
851865 {
852866 sessionID : input . sessionID ,
853867 messageID : input . messageID ,
854868 partID : input . partID ,
855869 } ,
856- { location : eventLocation ( session ) } ,
870+ { location } ,
857871 )
858872 return input . partID
859873 } )
0 commit comments