@@ -156,43 +156,43 @@ const make = Effect.gen(function* () {
156156 read_thread : ( input ) =>
157157 Effect . gen ( function * ( ) {
158158 const caller = yield * source ( ) ;
159- for ( let attempt = 0 ; attempt < 3 ; attempt ++ ) {
160- const before = yield * snapshots . getSnapshotSequence ( ) . pipe ( Effect . mapError ( failed ) ) ;
161- const thread = yield * target ( input . threadId , caller ) ;
162- const detail = yield * snapshots
163- . getThreadDetailSnapshot ( thread . id , {
159+ const detail = yield * snapshots
160+ . getThreadDetailSnapshot (
161+ input . threadId ,
162+ {
164163 turnLimit : input . turnLimit ?? 10 ,
165164 ...( input . beforeCursor === undefined ? { } : { beforeCursor : input . beforeCursor } ) ,
166- } )
167- . pipe ( Effect . mapError ( failed ) ) ;
168- if ( Option . isNone ( detail ) ) return yield * failed ( ) ;
169- // Detail pages omit shell-only attention/liveness fields. A matching sequence
170- // keeps those fields and the paginated history on the same projection version.
171- if ( before . snapshotSequence !== detail . value . snapshotSequence ) continue ;
172- return {
173- thread : summary (
174- thread ,
175- detail . value . thread . activities
176- . filter (
177- ( activity ) =>
178- activity . kind === "approval.requested" ||
179- activity . kind === "user-input.requested" ,
180- )
181- . map ( ( activity ) => activity . id )
182- . sort ( ) ,
183- ) ,
184- snapshotSequence : detail . value . snapshotSequence ,
185- ...( detail . value . page === undefined ? { } : { page : detail . value . page } ) ,
186- messages : detail . value . thread . messages . map ( ( message ) => ( {
187- id : message . id ,
188- role : message . role ,
189- text : message . text . slice ( 0 , 8000 ) ,
190- truncated : message . text . length > 8000 ,
191- createdAt : message . createdAt ,
192- } ) ) ,
193- } ;
165+ } ,
166+ true ,
167+ )
168+ . pipe ( Effect . mapError ( failed ) ) ;
169+ if ( Option . isNone ( detail ) || detail . value . shell === undefined ) return yield * failed ( ) ;
170+ const thread = detail . value . shell ;
171+ if ( thread . projectId !== caller . projectId || thread . archivedAt !== null ) {
172+ return yield * new ThreadToolError ( { message : "Thread is unavailable in this project." } ) ;
194173 }
195- return yield * failed ( ) ;
174+ return {
175+ thread : summary (
176+ thread ,
177+ detail . value . thread . activities
178+ . filter (
179+ ( activity ) =>
180+ activity . kind === "approval.requested" ||
181+ activity . kind === "user-input.requested" ,
182+ )
183+ . map ( ( activity ) => activity . id )
184+ . sort ( ) ,
185+ ) ,
186+ snapshotSequence : detail . value . snapshotSequence ,
187+ ...( detail . value . page === undefined ? { } : { page : detail . value . page } ) ,
188+ messages : detail . value . thread . messages . map ( ( message ) => ( {
189+ id : message . id ,
190+ role : message . role ,
191+ text : message . text . slice ( 0 , 8000 ) ,
192+ truncated : message . text . length > 8000 ,
193+ createdAt : message . createdAt ,
194+ } ) ) ,
195+ } ;
196196 } ) ,
197197
198198 send_message_to_thread : ( input ) =>
0 commit comments