@@ -12,7 +12,7 @@ import { Installation } from "../installation"
1212import { Database , NotFoundError , eq , and , gte , isNull , desc , like , inArray , lt } from "../storage/db"
1313import { SyncEvent } from "../sync"
1414import type { SQL } from "../storage/db"
15- import { SessionTable } from "./session.sql"
15+ import { PartTable , SessionTable } from "./session.sql"
1616import { ProjectTable } from "../project/project.sql"
1717import { Storage } from "@/storage/storage"
1818import { Log } from "../util/log"
@@ -345,6 +345,11 @@ export namespace Session {
345345 messageID : MessageID
346346 partID : PartID
347347 } ) => Effect . Effect < PartID >
348+ readonly getPart : ( input : {
349+ sessionID : SessionID
350+ messageID : MessageID
351+ partID : PartID
352+ } ) => Effect . Effect < MessageV2 . Part | undefined >
348353 readonly updatePart : < T extends MessageV2 . Part > ( part : T ) => Effect . Effect < T >
349354 readonly updatePartDelta : ( input : {
350355 sessionID : SessionID
@@ -492,6 +497,29 @@ export namespace Session {
492497 return part
493498 } ) . pipe ( Effect . withSpan ( "Session.updatePart" ) )
494499
500+ const getPart : Interface [ "getPart" ] = Effect . fn ( "Session.getPart" ) ( function * ( input ) {
501+ const row = Database . use ( ( db ) =>
502+ db
503+ . select ( )
504+ . from ( PartTable )
505+ . where (
506+ and (
507+ eq ( PartTable . session_id , input . sessionID ) ,
508+ eq ( PartTable . message_id , input . messageID ) ,
509+ eq ( PartTable . id , input . partID ) ,
510+ ) ,
511+ )
512+ . get ( ) ,
513+ )
514+ if ( ! row ) return
515+ return {
516+ ...row . data ,
517+ id : row . id ,
518+ sessionID : row . session_id ,
519+ messageID : row . message_id ,
520+ } as MessageV2 . Part
521+ } )
522+
495523 const create = Effect . fn ( "Session.create" ) ( function * ( input ?: {
496524 parentID ?: SessionID
497525 title ?: string
@@ -675,6 +703,7 @@ export namespace Session {
675703 removeMessage,
676704 removePart,
677705 updatePart,
706+ getPart,
678707 updatePartDelta,
679708 initialize,
680709 } )
0 commit comments