@@ -394,6 +394,7 @@ export type ProjectionRecords<K extends ProjectionRecordField> = Pick<
394394export interface ProjectionTimelinePageOptions {
395395 readonly afterPosition ?: number ;
396396 readonly itemId ?: TurnItemId ;
397+ readonly attachmentId ?: string ;
397398 readonly view ?: "messages" | "activity" ;
398399 readonly limit : number ;
399400}
@@ -5815,6 +5816,20 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
58155816 . withTransaction (
58165817 Effect . gen ( function * ( ) {
58175818 const index = yield * readTimelineIndex ( threadId , new Set ( ) ) ;
5819+ const attachmentOwners =
5820+ options . attachmentId === undefined
5821+ ? undefined
5822+ : new Set (
5823+ ( yield * sql < { thread_id : string ; turn_item_id : string } > `
5824+ SELECT item.thread_id, item.turn_item_id
5825+ FROM orchestration_v2_projection_turn_items AS item,
5826+ json_each(item.payload_json, '$.attachments') AS attachment
5827+ WHERE item.thread_id IN ${ sql . in ( [ ...new Set ( index . visible . map ( ( row ) => row . sourceThreadId ) ) ] ) }
5828+ AND item.type = 'user_message'
5829+ AND json_extract(attachment.value, '$.id') = ${ options . attachmentId } ` ) . map (
5830+ ( row ) => `${ row . thread_id } :${ row . turn_item_id } ` ,
5831+ ) ,
5832+ ) ;
58185833 const matching = index . visible
58195834 . map ( ( row , position ) => ( { ...row , position } ) )
58205835 . filter ( ( row ) =>
@@ -5825,6 +5840,9 @@ export const layer: Layer.Layer<ProjectionStoreV2, never, SqlClient.SqlClient> =
58255840 row . item . type ,
58265841 ) )
58275842 : row . sourceItemId === options . itemId ,
5843+ )
5844+ . filter (
5845+ ( row ) => attachmentOwners ?. has ( `${ row . sourceThreadId } :${ row . sourceItemId } ` ) ?? true ,
58285846 ) ;
58295847 const page = matching . slice ( 0 , options . limit ) ;
58305848 const sources = yield * encodeTimelineSources (
0 commit comments