11import {
2+ AssistantMessagePhase ,
23 ChatAttachment ,
34 CheckpointRef ,
45 IsoDateTime ,
@@ -70,6 +71,7 @@ const ProjectionProjectDbRowSchema = ProjectionProject.mapFields(
7071const ProjectionThreadMessageDbRowSchema = ProjectionThreadMessage . mapFields (
7172 Struct . assign ( {
7273 isStreaming : Schema . Number ,
74+ assistantPhase : Schema . NullOr ( AssistantMessagePhase ) ,
7375 attachments : Schema . NullOr ( Schema . fromJsonString ( Schema . Array ( ChatAttachment ) ) ) ,
7476 } ) ,
7577) ;
@@ -414,6 +416,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
414416 turn_id AS "turnId",
415417 role,
416418 text,
419+ assistant_phase AS "assistantPhase",
417420 attachments_json AS "attachments",
418421 is_streaming AS "isStreaming",
419422 created_at AS "createdAt",
@@ -777,6 +780,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
777780 turn_id AS "turnId",
778781 role,
779782 text,
783+ assistant_phase AS "assistantPhase",
780784 attachments_json AS "attachments",
781785 is_streaming AS "isStreaming",
782786 created_at AS "createdAt",
@@ -877,6 +881,28 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
877881 ` ,
878882 } ) ;
879883
884+ const listTurnRowsByThread = SqlSchema . findAll ( {
885+ Request : ThreadIdLookupInput ,
886+ Result : ProjectionLatestTurnDbRowSchema ,
887+ execute : ( { threadId } ) =>
888+ sql `
889+ SELECT
890+ thread_id AS "threadId",
891+ turn_id AS "turnId",
892+ state,
893+ requested_at AS "requestedAt",
894+ started_at AS "startedAt",
895+ completed_at AS "completedAt",
896+ assistant_message_id AS "assistantMessageId",
897+ source_proposed_plan_thread_id AS "sourceProposedPlanThreadId",
898+ source_proposed_plan_id AS "sourceProposedPlanId"
899+ FROM projection_turns
900+ WHERE thread_id = ${ threadId }
901+ AND turn_id IS NOT NULL
902+ ORDER BY requested_at ASC, turn_id ASC
903+ ` ,
904+ } ) ;
905+
880906 const listCheckpointRowsByThread = SqlSchema . findAll ( {
881907 Request : ThreadIdLookupInput ,
882908 Result : ProjectionCheckpointDbRowSchema ,
@@ -1048,6 +1074,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
10481074 id : row . messageId ,
10491075 role : row . role ,
10501076 text : row . text ,
1077+ ...( row . assistantPhase !== null ? { assistantPhase : row . assistantPhase } : { } ) ,
10511078 ...( row . attachments !== null ? { attachments : row . attachments } : { } ) ,
10521079 turnId : row . turnId ,
10531080 streaming : row . isStreaming === 1 ,
@@ -1903,6 +1930,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
19031930 activityRows ,
19041931 checkpointRows ,
19051932 latestTurnRow ,
1933+ turnRows ,
19061934 sessionRow ,
19071935 ] = yield * Effect . all ( [
19081936 getActiveThreadRowById ( { threadId } ) . pipe (
@@ -1953,6 +1981,14 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
19531981 ) ,
19541982 ) ,
19551983 ) ,
1984+ listTurnRowsByThread ( { threadId } ) . pipe (
1985+ Effect . mapError (
1986+ toPersistenceSqlOrDecodeError (
1987+ "ProjectionSnapshotQuery.getThreadDetailById:listTurns:query" ,
1988+ "ProjectionSnapshotQuery.getThreadDetailById:listTurns:decodeRows" ,
1989+ ) ,
1990+ ) ,
1991+ ) ,
19561992 getThreadSessionRowByThread ( { threadId } ) . pipe (
19571993 Effect . mapError (
19581994 toPersistenceSqlOrDecodeError (
@@ -1977,6 +2013,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
19772013 branch : threadRow . value . branch ,
19782014 worktreePath : threadRow . value . worktreePath ,
19792015 latestTurn : Option . isSome ( latestTurnRow ) ? mapLatestTurn ( latestTurnRow . value ) : null ,
2016+ turns : turnRows . map ( mapLatestTurn ) ,
19802017 createdAt : threadRow . value . createdAt ,
19812018 updatedAt : threadRow . value . updatedAt ,
19822019 archivedAt : threadRow . value . archivedAt ,
@@ -1986,6 +2023,7 @@ const makeProjectionSnapshotQuery = Effect.gen(function* () {
19862023 id : row . messageId ,
19872024 role : row . role ,
19882025 text : row . text ,
2026+ ...( row . assistantPhase !== null ? { assistantPhase : row . assistantPhase } : { } ) ,
19892027 turnId : row . turnId ,
19902028 streaming : row . isStreaming === 1 ,
19912029 createdAt : row . createdAt ,
0 commit comments