@@ -29,6 +29,16 @@ export type ReplyMediaAttachment = {
2929 trustedLocalMedia ?: boolean ;
3030} ;
3131
32+ export type ReplyMediaFailureCode = "file-not-found" | "unsupported-format" | "delivery-failed" ;
33+
34+ /** Producer-owned outcome for one attachment that could not be delivered. */
35+ export type ReplyMediaFailure = {
36+ code : ReplyMediaFailureCode ;
37+ kind : "image" | "audio" | "video" | "document" ;
38+ label : string ;
39+ mimeType ?: string ;
40+ } ;
41+
3242/** Channel-agnostic assistant reply payload. */
3343export type ReplyPayload = {
3444 text ?: string ;
@@ -153,18 +163,44 @@ export type ReplyDeliveryContext = {
153163 replyToMode : ReplyToMode ;
154164} ;
155165
156- const REPLY_MEDIA_FAILURE_WARNING =
157- "⚠️ Media failed. Try sending a smaller supported file or a different format." ;
166+ const REPLY_MEDIA_FAILURE_MESSAGES : Record < ReplyMediaFailureCode , string > = {
167+ "file-not-found" : "File not found. Check the path and try again." ,
168+ "unsupported-format" : "Rejected by the local attachment allowlist. Send a supported file type." ,
169+ "delivery-failed" : "Delivery failed. Try sending this file again." ,
170+ } ;
171+
172+ function formatReplyMediaFailures ( failures : readonly ReplyMediaFailure [ ] ) : string {
173+ return failures
174+ . map ( ( failure ) => `⚠️ ${ failure . label } : ${ REPLY_MEDIA_FAILURE_MESSAGES [ failure . code ] } ` )
175+ . join ( "\n" ) ;
176+ }
158177
159- /** Appends the standard media failure warning without duplicating it. */
160- export function appendReplyMediaFailureWarning ( text : string | undefined ) : string {
161- if ( ! text ?. trim ( ) ) {
162- return REPLY_MEDIA_FAILURE_WARNING ;
178+ /** Appends one named, actionable fallback receipt per failed attachment. */
179+ export function appendReplyMediaFailures (
180+ text : string | undefined ,
181+ failures : readonly ReplyMediaFailure [ ] ,
182+ ) : string | undefined {
183+ if ( failures . length === 0 ) {
184+ return text ;
163185 }
164- if ( text . includes ( REPLY_MEDIA_FAILURE_WARNING ) ) {
186+ const receipt = formatReplyMediaFailures ( failures ) ;
187+ return text ?. trim ( ) ? `${ text } \n${ receipt } ` : receipt ;
188+ }
189+
190+ /** Removes producer-authored fallback receipts when structured display cards supersede them. */
191+ export function stripReplyMediaFailureFallback (
192+ text : string | undefined ,
193+ failures : readonly ReplyMediaFailure [ ] ,
194+ ) : string | undefined {
195+ if ( ! text || failures . length === 0 ) {
165196 return text ;
166197 }
167- return `${ text } \n${ REPLY_MEDIA_FAILURE_WARNING } ` ;
198+ const receipt = formatReplyMediaFailures ( failures ) ;
199+ if ( text === receipt ) {
200+ return undefined ;
201+ }
202+ const suffix = `\n${ receipt } ` ;
203+ return text . endsWith ( suffix ) ? text . slice ( 0 , - suffix . length ) : text ;
168204}
169205
170206function hasReplyPayloadMedia ( payload : Pick < ReplyPayload , "mediaUrl" | "mediaUrls" > ) : boolean {
@@ -248,8 +284,8 @@ export type ReplyPayloadMetadata = {
248284 ttsExplicit ?: true ;
249285 /** Original runtime MEDIA references used to identify the persisted assistant row. */
250286 assistantTranscriptMediaUrls ?: string [ ] ;
251- /** Media normalization rejected at least one source before delivery . */
252- assistantMediaNormalizationFailed ?: true ;
287+ /** Ordered per-source failures retained until transcript/display projection . */
288+ assistantMediaFailures ?: ReplyMediaFailure [ ] ;
253289 /** The runtime owns the transcript decision for this assistant payload. */
254290 assistantTranscriptOwned ?: boolean ;
255291 /** Exact channel/account transform owner that already accepted this payload. */
0 commit comments