@@ -71,6 +71,8 @@ type DiscordSendOpts = {
7171 onDeliveryResult ?: ( result : DiscordSendResult ) => Promise < void > | void ;
7272 /** @internal Refresh durable custody immediately before Discord REST I/O. */
7373 onPlatformSendDispatch ?: ( ) => Promise < void > ;
74+ /** @internal Synchronously fence custody after refresh and immediately before Discord REST I/O. */
75+ assertPlatformSendAuthorized ?: ( ) => void ;
7476} ;
7577
7678type DiscordClientRequest = ReturnType < typeof createDiscordClient > [ "request" ] ;
@@ -94,6 +96,7 @@ async function sendDiscordThreadTextChunks(params: {
9496 allowedMentions ?: DiscordAllowedMentions ;
9597 onResult ?: DiscordSendProgress ;
9698 onPlatformSendDispatch ?: ( ) => Promise < void > ;
99+ assertPlatformSendAuthorized ?: ( ) => void ;
97100} ) : Promise < void > {
98101 for ( const chunk of params . chunks ) {
99102 await sendDiscordText ( {
@@ -109,6 +112,7 @@ async function sendDiscordThreadTextChunks(params: {
109112 maxChars : params . maxChars ,
110113 onResult : params . onResult ,
111114 onPlatformSendDispatch : params . onPlatformSendDispatch ,
115+ assertPlatformSendAuthorized : params . assertPlatformSendAuthorized ,
112116 } ) ;
113117 }
114118}
@@ -256,6 +260,7 @@ export async function sendMessageDiscord(
256260 threadRes = ( await request (
257261 async ( ) => {
258262 await opts . onPlatformSendDispatch ?.( ) ;
263+ opts . assertPlatformSendAuthorized ?.( ) ;
259264 return createThread < { id : string ; message ?: { id : string ; channel_id : string } } > (
260265 rest ,
261266 channelId ,
@@ -323,6 +328,7 @@ export async function sendMessageDiscord(
323328 maxChars : textLimit ,
324329 onResult : reportResult ,
325330 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
331+ assertPlatformSendAuthorized : opts . assertPlatformSendAuthorized ,
326332 } ) ;
327333 await sendDiscordThreadTextChunks ( {
328334 rest,
@@ -337,6 +343,7 @@ export async function sendMessageDiscord(
337343 allowedMentions : opts . allowedMentions ,
338344 onResult : reportResult ,
339345 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
346+ assertPlatformSendAuthorized : opts . assertPlatformSendAuthorized ,
340347 } ) ;
341348 } else {
342349 await sendDiscordThreadTextChunks ( {
@@ -352,6 +359,7 @@ export async function sendMessageDiscord(
352359 allowedMentions : opts . allowedMentions ,
353360 onResult : reportResult ,
354361 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
362+ assertPlatformSendAuthorized : opts . assertPlatformSendAuthorized ,
355363 } ) ;
356364 }
357365 } catch ( err ) {
@@ -400,6 +408,7 @@ export async function sendMessageDiscord(
400408 maxChars : textLimit ,
401409 onResult : reportResult ,
402410 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
411+ assertPlatformSendAuthorized : opts . assertPlatformSendAuthorized ,
403412 } ) ;
404413 } else {
405414 result = await sendDiscordText ( {
@@ -418,6 +427,7 @@ export async function sendMessageDiscord(
418427 maxChars : textLimit ,
419428 onResult : reportResult ,
420429 onPlatformSendDispatch : opts . onPlatformSendDispatch ,
430+ assertPlatformSendAuthorized : opts . assertPlatformSendAuthorized ,
421431 } ) ;
422432 }
423433 } catch ( err ) {
@@ -510,6 +520,7 @@ async function resolveDiscordStructuredSendContext(
510520 const result = ( await request (
511521 async ( ) => {
512522 await opts . onPlatformSendDispatch ?.( ) ;
523+ opts . assertPlatformSendAuthorized ?.( ) ;
513524 return createChannelMessage < { id : string ; channel_id : string } > ( rest , channelId , {
514525 body,
515526 } ) ;
0 commit comments