11import type { EnvironmentId , RunId , ThreadId } from "@t3tools/contracts" ;
2+ import * as DateTime from "effect/DateTime" ;
23
34export const REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL = "Remove queued message" ;
45
@@ -11,6 +12,8 @@ export interface ThreadQueueRowControls {
1112 readonly dismissAccessibilityLabel : string ;
1213 readonly displayText : string ;
1314 readonly isEditing : boolean ;
15+ /** "Sends at …" while a delayed message waits for its time, otherwise null. */
16+ readonly releaseLabel : string | null ;
1417}
1518
1619export function resolveThreadQueueRowControls ( input : {
@@ -21,9 +24,16 @@ export function resolveThreadQueueRowControls(input: {
2124 readonly isEditing ?: boolean ;
2225 readonly queuedCount : number ;
2326 readonly text : string ;
27+ readonly releaseAt ?: DateTime . Utc | string | null | undefined ;
2428} ) : ThreadQueueRowControls {
2529 const mutationEnabled = ! input . busy ;
2630 const isEditing = input . isEditing === true ;
31+ const releaseAt =
32+ input . releaseAt === null || input . releaseAt === undefined
33+ ? null
34+ : typeof input . releaseAt === "string"
35+ ? new Date ( input . releaseAt )
36+ : DateTime . toDate ( input . releaseAt ) ;
2737
2838 return {
2939 canDismiss : ! input . busy ,
@@ -32,10 +42,15 @@ export function resolveThreadQueueRowControls(input: {
3242 canEdit : mutationEnabled && ! isEditing ,
3343 canMoveDown : mutationEnabled && input . canReorder && input . index < input . queuedCount - 1 ,
3444 canMoveUp : mutationEnabled && input . canReorder && input . index > 0 ,
35- canSteer : mutationEnabled && input . canPromoteToSteer && ! isEditing ,
45+ // Steering would send a delayed message before the time it was scheduled for.
46+ canSteer : mutationEnabled && input . canPromoteToSteer && ! isEditing && releaseAt === null ,
3647 dismissAccessibilityLabel : REMOVE_QUEUED_MESSAGE_ACCESSIBILITY_LABEL ,
3748 displayText : input . text ,
3849 isEditing,
50+ releaseLabel :
51+ releaseAt === null || Number . isNaN ( releaseAt . getTime ( ) )
52+ ? null
53+ : `Sends at ${ releaseAt . toLocaleTimeString ( [ ] , { hour : "numeric" , minute : "2-digit" } ) } ` ,
3954 } ;
4055}
4156
0 commit comments