@@ -785,11 +785,28 @@ export default class SimpleTranscriptionInterface extends HTMLElement {
785785 return this . #page?. items ?. [ TPEN . activeLineIndex ] ?. id ?? null
786786 }
787787
788- #buildTPENContext( ) {
788+ /**
789+ * Resolve each item in `page.items` to a full Annotation via the vault.
790+ * Vault fetches for AnnotationPages return children as bare `{id, type}`
791+ * refs — downstream tools need hydrated targets/selectors/bodies. Returns
792+ * a shallow copy of the page with the items array replaced; errors on
793+ * individual items fall back to the original ref so partial hydration
794+ * still produces a usable payload.
795+ */
796+ async #hydratePageItems( page ) {
797+ if ( ! Array . isArray ( page ?. items ) || page . items . length === 0 ) return page
798+ const results = await Promise . allSettled (
799+ page . items . map ( item => vault . get ( item , 'annotation' ) )
800+ )
801+ const items = results . map ( ( r , i ) => r . status === 'fulfilled' ? r . value : page . items [ i ] )
802+ return { ...page , items }
803+ }
804+
805+ async #buildTPENContext( ) {
789806 return {
790807 type : 'TPEN_CONTEXT' ,
791808 project : TPEN . activeProject ?? null ,
792- page : this . #page ?? null ,
809+ page : await this . #hydratePageItems ( this . # page) ,
793810 canvas : this . #canvas ?? null ,
794811 currentLineId : this . #getCurrentLineId( )
795812 }
@@ -800,8 +817,8 @@ export default class SimpleTranscriptionInterface extends HTMLElement {
800817 targetWindow . postMessage ( message , this . _iframeOrigin )
801818 }
802819
803- #sendTPENContextToTool( targetWindow = this . #activeToolIframe?. contentWindow ) {
804- this . #postToTool( this . #buildTPENContext( ) , targetWindow )
820+ async #sendTPENContextToTool( targetWindow = this . #activeToolIframe?. contentWindow ) {
821+ this . #postToTool( await this . #buildTPENContext( ) , targetWindow )
805822 }
806823
807824 #sendIdTokenToTool( targetWindow = this . #activeToolIframe?. contentWindow ) {
0 commit comments