11import type { LiveFileId } from '~/common/livefile/liveFile.types' ;
22import { agiId } from '~/common/util/idUtils' ;
3+ import { ellipsizeMiddle } from '~/common/util/textUtils' ;
34
45
56/// Fragments - forward compatible ///
@@ -132,14 +133,15 @@ export type DMessageReferencePart =
132133type _DMessageReferencePartBase < TRt extends string , TRefSpecificFields = { } > = {
133134 pt : 'reference' ;
134135 rt : TRt ;
135- // altText?: string;
136136} & TRefSpecificFields ;
137137
138138type _DMessageZyncReferencePart < TZT extends ZYNC . Typename , TZTSpecificFields = { } > = _DMessageReferencePartBase < 'zync' , {
139139 zType : TZT ;
140140 zUuid : ZYNC_Entity . UUID ;
141141 // zRelationship: 'live', ...
142+ zRefSummary ?: DMessageTextPart ; // text summary of the reference for text-only models and accessibility
142143} & TZTSpecificFields > ;
144+ const MAX_ZYNC_REFERENCE_SUMMARY_LEN = 512 ; // max alt text length for Zync Asset Reference Parts
143145
144146export type DMessageZyncAssetReferencePart = _DMessageZyncReferencePart < 'asset' , {
145147 // denorm fields for quick display
@@ -330,8 +332,8 @@ export function createErrorContentFragment(error: string): DMessageContentFragme
330332 return _createContentFragment ( _create_Error_Part ( error ) ) ;
331333}
332334
333- export function createZyncAssetReferenceContentFragment ( assetUuid : ZYNC_Entity . UUID , assetType : 'image' | 'audio' , legacyImageRefPart ?: DMessageZyncAssetReferencePart [ '_legacyImageRefPart' ] ) : DMessageContentFragment {
334- return _createContentFragment ( createDMessageZyncAssetReferencePart ( assetUuid , assetType , legacyImageRefPart ) ) ;
335+ export function createZyncAssetReferenceContentFragment ( assetUuid : ZYNC_Entity . UUID , refSummary : string | undefined , assetType : 'image' | 'audio' , legacyImageRefPart ?: DMessageZyncAssetReferencePart [ '_legacyImageRefPart' ] ) : DMessageContentFragment {
336+ return _createContentFragment ( createDMessageZyncAssetReferencePart ( assetUuid , refSummary , assetType , legacyImageRefPart ) ) ;
335337}
336338
337339export function create_FunctionCallInvocation_ContentFragment ( id : string , functionName : string , args : string /*| null*/ ) : DMessageContentFragment {
@@ -357,8 +359,8 @@ function _createContentFragment(part: DMessageContentFragment['part']): DMessage
357359
358360/// Attachment Fragments - Creation & Duplication
359361
360- export function createZyncAssetReferenceAttachmentFragment ( title : string , caption : string , assetUuid : ZYNC_Entity . UUID , assetType : 'image' | 'audio' , legacyImageRefPart ?: DMessageZyncAssetReferencePart [ '_legacyImageRefPart' ] ) : DMessageAttachmentFragment {
361- return _createAttachmentFragment ( title , caption , createDMessageZyncAssetReferencePart ( assetUuid , assetType , legacyImageRefPart ) , undefined ) ;
362+ export function createZyncAssetReferenceAttachmentFragment ( title : string , caption : string , assetUuid : ZYNC_Entity . UUID , refSummary : string | undefined , assetType : 'image' | 'audio' , legacyImageRefPart ?: DMessageZyncAssetReferencePart [ '_legacyImageRefPart' ] ) : DMessageAttachmentFragment {
363+ return _createAttachmentFragment ( title , caption , createDMessageZyncAssetReferencePart ( assetUuid , refSummary , assetType , legacyImageRefPart ) , undefined ) ;
362364}
363365
364366export function createDocAttachmentFragment ( l1Title : string , caption : string , vdt : DMessageDocMimeType , data : DMessageDataInline , ref : string , version : number , meta ?: DMessageDocMeta , liveFileId ?: LiveFileId ) : DMessageAttachmentFragment {
@@ -370,7 +372,7 @@ export function specialContentPartToDocAttachmentFragment(title: string, caption
370372 case isTextPart ( contentPart ) :
371373 return createDocAttachmentFragment ( title , caption , vdt , createDMessageDataInlineText ( contentPart . text , 'text/plain' ) , ref , 2 /* As we attach our messages, we start from 2 */ , docMeta ) ;
372374 case isZyncAssetReferencePart ( contentPart ) :
373- return createZyncAssetReferenceAttachmentFragment ( title , caption , contentPart . zUuid , contentPart . assetType , contentPart . _legacyImageRefPart ) ;
375+ return createZyncAssetReferenceAttachmentFragment ( title , caption , contentPart . zUuid , contentPart . zRefSummary ?. text , contentPart . assetType , contentPart . _legacyImageRefPart ) ;
374376 default :
375377 return createDocAttachmentFragment ( 'Error' , 'Content to Attachment' , vdt , createDMessageDataInlineText ( `Conversion of '${ contentPart . pt } ' is not supported yet.` , 'text/plain' ) , ref , 1 /* error has no version really */ , docMeta ) ;
376378 }
@@ -446,8 +448,16 @@ function _create_Error_Part(error: string): DMessageErrorPart {
446448 return { pt : 'error' , error } ;
447449}
448450
449- export function createDMessageZyncAssetReferencePart ( zUuid : ZYNC_Entity . UUID , assetType : 'image' | 'audio' , legacyImageRefPart ?: DMessageZyncAssetReferencePart [ '_legacyImageRefPart' ] ) : DMessageZyncAssetReferencePart {
450- return { pt : 'reference' , rt : 'zync' , zType : 'asset' , zUuid, assetType, ...( legacyImageRefPart && { _legacyImageRefPart : { ...legacyImageRefPart } } ) } ;
451+ export function createDMessageZyncAssetReferencePart ( zUuid : ZYNC_Entity . UUID , refSummary : string | undefined , assetType : 'image' | 'audio' , legacyImageRefPart ?: DMessageZyncAssetReferencePart [ '_legacyImageRefPart' ] ) : DMessageZyncAssetReferencePart {
452+ return {
453+ pt : 'reference' ,
454+ rt : 'zync' ,
455+ zType : 'asset' ,
456+ zUuid,
457+ ...( refSummary && { zRefSummary : { pt : 'text' , text : ellipsizeMiddle ( refSummary , MAX_ZYNC_REFERENCE_SUMMARY_LEN ) } } ) ,
458+ assetType,
459+ ...( legacyImageRefPart && { _legacyImageRefPart : { ...legacyImageRefPart } } ) ,
460+ } ;
451461}
452462
453463function _create_Doc_Part ( vdt : DMessageDocMimeType , data : DMessageDataInline , ref : string , l1Title : string , version : number , meta ?: DMessageDocMeta ) : DMessageDocPart {
@@ -522,7 +532,7 @@ function _duplicate_Part<TPart extends (DMessageContentFragment | DMessageAttach
522532 switch ( part . zType ) {
523533 case 'asset' :
524534 // Zync Asset Reference: new fragment, with the exact same reference (and fallback, if still in the migration period)
525- return createDMessageZyncAssetReferencePart ( part . zUuid , part . assetType , part . _legacyImageRefPart ? { ...part . _legacyImageRefPart } : undefined ) as TPart ;
535+ return createDMessageZyncAssetReferencePart ( part . zUuid , part . zRefSummary ?. text , part . assetType , part . _legacyImageRefPart ? { ...part . _legacyImageRefPart } : undefined ) as TPart ;
526536
527537 default :
528538 const _exhaustiveCheck : never = part . zType ;
0 commit comments