11import { sql } from "kysely" ;
2- import type { TranscriptDisplayPosition } from "../../chat/transcript-display-position.js" ;
32import {
43 executeSqliteQuerySync ,
54 executeSqliteQueryTakeFirstSync ,
65} from "../../infra/kysely-sync.js" ;
76import {
87 getActiveTranscriptKysely ,
8+ parseActiveTranscriptMessageRow ,
9+ readTranscriptProjectionGeneration ,
910 withCurrentProjectionSnapshot ,
11+ type SessionTranscriptMessageEvent ,
1012} from "./session-accessor.sqlite-active-projection.js" ;
1113import type {
1214 SessionTranscriptVisibleMessageDeltaLimits ,
@@ -16,7 +18,6 @@ import type {
1618} from "./session-accessor.sqlite-contract.js" ;
1719import {
1820 iterateVisibleMessageRange ,
19- readTranscriptProjectionGeneration ,
2021 readVisibleMessageMetadata ,
2122 readVisibleMessageRange ,
2223 readVisibleTranscriptStats ,
@@ -41,13 +42,7 @@ export {
4142 isSessionTranscriptProjectionUnavailableError ,
4243 SessionTranscriptProjectionUnavailableError ,
4344} from "./session-transcript-projection-error.js" ;
44-
45- export type SessionTranscriptMessageEvent = {
46- event : TranscriptEvent ;
47- eventSeq : number ;
48- seq : number ;
49- displayPosition ?: TranscriptDisplayPosition ;
50- } ;
45+ export type { SessionTranscriptMessageEvent } from "./session-accessor.sqlite-active-projection.js" ;
5146
5247export type SessionTranscriptMessageEventPage = {
5348 activeLeafEntryId ?: string | null ;
@@ -75,23 +70,6 @@ export type SessionTranscriptBoundedMessageTailPage = SessionTranscriptMessageEv
7570 } ;
7671} ;
7772
78- function parseMessageEventRow ( row : {
79- event_seq : number ;
80- event_json : string ;
81- message_position : number | null ;
82- } ) : SessionTranscriptMessageEvent {
83- if ( row . message_position === null ) {
84- throw new Error ( "Active transcript message row is missing its message position" ) ;
85- }
86- return {
87- event : JSON . parse ( row . event_json ) as TranscriptEvent ,
88- eventSeq : row . event_seq ,
89- // Gateway cursors use the visible-message ordinal, matching the JSONL index.
90- // Raw event seq includes headers/control rows and would make pages overlap.
91- seq : row . message_position + 1 ,
92- } ;
93- }
94-
9573/** Reads every message event on the active path. Full callers remain intentionally O(output). */
9674export function readSessionTranscriptMessageEvents (
9775 scope : SessionTranscriptReadScope ,
@@ -206,13 +184,7 @@ export function readSessionTranscriptVisibleMessageDeltaCore(
206184 database : projection . database ,
207185 ...projection . resolved ,
208186 } ) ;
209- const generation = executeSqliteQueryTakeFirstSync (
210- projection . database . db ,
211- db
212- . selectFrom ( "transcript_rewrite_watermarks" )
213- . select ( "generation" )
214- . where ( "session_id" , "=" , projection . resolved . sessionId ) ,
215- ) ?. generation ;
187+ const generation = readTranscriptProjectionGeneration ( projection ) ;
216188 if ( ! generation ) {
217189 return { kind : "missing" } ;
218190 }
@@ -513,7 +485,7 @@ export function readSessionTranscriptBoundedMessageTailPage(
513485 . where ( "active.session_id" , "=" , projection . resolved . sessionId )
514486 . where ( "active.message_position" , "in" , selectedPositions )
515487 . orderBy ( "active.message_position" , "asc" ) ,
516- ) . rows . map ( parseMessageEventRow ) ;
488+ ) . rows . map ( parseActiveTranscriptMessageRow ) ;
517489 return {
518490 activeLeafEntryId : projection . state . leafEventId ,
519491 events,
0 commit comments