@@ -12,6 +12,7 @@ import {
1212 ORCHESTRATION_PROTOCOL_HEADER ,
1313 ORCHESTRATION_PROTOCOL_VERSION ,
1414 OrchestrationV2ThreadBoundedSnapshot ,
15+ OrchestrationV2ThreadHistoryPage ,
1516 OrchestrationV2ThreadStreamItem ,
1617 ProjectId ,
1718 ProviderDriverKind ,
@@ -48,6 +49,9 @@ import * as ThreadManagementService from "./ThreadManagementService.ts";
4849const decodeBounded = Schema . decodeUnknownSync (
4950 Schema . fromJsonString ( Schema . toCodecJson ( OrchestrationV2ThreadBoundedSnapshot ) ) ,
5051) ;
52+ const decodeHistoryPage = Schema . decodeUnknownSync (
53+ Schema . fromJsonString ( Schema . toCodecJson ( OrchestrationV2ThreadHistoryPage ) ) ,
54+ ) ;
5155const decodeStreamItem = Schema . decodeUnknownSync (
5256 Schema . toCodecJson ( OrchestrationV2ThreadStreamItem ) ,
5357) ;
@@ -74,6 +78,10 @@ const management = Layer.unwrap(
7478 getThreadSnapshot : ( id ) => projections . getThreadSnapshot ( id ) . pipe ( Effect . orDie ) ,
7579 getThreadSnapshotWindow : ( id , options ) =>
7680 projections . getThreadSnapshotWindow ( id , options ) . pipe ( Effect . orDie ) ,
81+ getThreadHistoryPage : ( id , cursor , throughEntryId , conversationOnly ) =>
82+ projections
83+ . getThreadHistoryPage ( id , cursor , throughEntryId , conversationOnly )
84+ . pipe ( Effect . orDie ) ,
7785 streamStoredEventsFrom : ( ) => Stream . empty ,
7886 } ) ;
7987 } ) ,
@@ -332,6 +340,46 @@ it.layer(TestLayer)("compact bounded snapshot transport", (it) => {
332340 ) ,
333341 ) ;
334342
343+ it . effect ( "HTTP: the ID table is opt-in and decodes to the same snapshot" , ( ) =>
344+ withHttp ( async ( get ) => {
345+ const base = `/api/orchestration/threads/${ encodeURIComponent ( threadId ) } /bounded?compactTurnItems=1` ;
346+ const plainBody = await ( await get ( base ) ) . text ( ) ;
347+ const tableBody = await ( await get ( `${ base } &compactIds=1` ) ) . text ( ) ;
348+ const wire = JSON . parse ( tableBody ) ;
349+
350+ assert . notProperty ( JSON . parse ( plainBody ) , "ids" ) ;
351+ assert . isArray ( wire . ids ) ;
352+ assert . isNumber ( wire . projection . visibleTurnItems [ 0 ] . item . id ) ;
353+ assert . isNumber ( wire . projection . thread . id ) ;
354+ assert . isBelow ( tableBody . length , plainBody . length ) ;
355+ const decoded = decodeBounded ( tableBody ) ;
356+ assert . deepStrictEqual ( decoded , decodeBounded ( plainBody ) ) ;
357+
358+ // Only the long thread has older history to page.
359+ if ( threadId !== LONG ) return ;
360+ assert . isNotNull ( decoded . historyCursor ) ;
361+ const history = `/api/orchestration/threads/${ encodeURIComponent ( threadId ) } /history?cursor=${ encodeURIComponent ( decoded . historyCursor ?? "" ) } ` ;
362+ const plainPage = await ( await get ( history ) ) . text ( ) ;
363+ const tablePage = await ( await get ( `${ history } &compactIds=1` ) ) . text ( ) ;
364+ assert . isArray ( JSON . parse ( tablePage ) . ids ) ;
365+ const page = decodeHistoryPage ( tablePage ) ;
366+ assert . isAbove ( page . items . length , 0 ) ;
367+ assert . deepStrictEqual ( page , decodeHistoryPage ( plainPage ) ) ;
368+ } ) ,
369+ ) ;
370+
371+ it . effect ( "WS: the ID table is opt-in and decodes to the same snapshot" , ( ) =>
372+ Effect . gen ( function * ( ) {
373+ const input = { threadId, acceptBoundedSnapshot : true , acceptCompactTurnItems : true } ;
374+ const plain = yield * firstSnapshot ( input ) ;
375+ const table = yield * firstSnapshot ( { ...input , acceptCompactIds : true } ) ;
376+
377+ assert . notProperty ( encodeStreamItem ( plain . raw ) , "ids" ) ;
378+ assert . property ( encodeStreamItem ( table . raw ) , "ids" ) ;
379+ assert . deepStrictEqual ( table . decoded , plain . decoded ) ;
380+ } ) ,
381+ ) ;
382+
335383 it . effect ( "WS: bounded snapshots stay unchanged unless the client opts in" , ( ) =>
336384 Effect . gen ( function * ( ) {
337385 const legacy = yield * firstSnapshot ( { threadId, acceptBoundedSnapshot : true } ) ;
0 commit comments