11import {
22 type AssistantCitation ,
3- type ChatFileAttachment ,
43 type EnvironmentId ,
54 type MessageId ,
65 type ScopedThreadRef ,
@@ -50,6 +49,7 @@ import {
5049 workLogEntryIsToolLike ,
5150} from "../../session-logic" ;
5251import {
52+ type ChatFileAttachment ,
5353 type ChatImageAttachment ,
5454 isBrowserPreviewAttachment ,
5555 isFileAttachment ,
@@ -79,7 +79,6 @@ import {
7979 MessageCircleIcon ,
8080 MousePointerClickIcon ,
8181 PaintbrushIcon ,
82- PlayIcon ,
8382 SearchIcon ,
8483 SquarePenIcon ,
8584 TerminalIcon ,
@@ -89,8 +88,14 @@ import {
8988 ZapIcon ,
9089} from "lucide-react" ;
9190import { Button } from "../ui/button" ;
91+ import { useAssetUrlRefresh , useAssetUrlState } from "../../assets/assetUrls" ;
92+ import { MediaVideoPlayer } from "../media/MediaVideoPlayer" ;
9293import { getVirtualizedScrollFadeClassName } from "../ui/scroll-area" ;
93- import { buildExpandedImagePreview , ExpandedImagePreview } from "./ExpandedImagePreview" ;
94+ import {
95+ buildAttachmentVideoAsset ,
96+ buildExpandedImagePreview ,
97+ ExpandedImagePreview ,
98+ } from "./ExpandedImagePreview" ;
9499import { ProposedPlanCard } from "./ProposedPlanCard" ;
95100import { ChangedFilesCard } from "./ChangedFilesTree" ;
96101import { shouldAutoExpandChangedFiles } from "./changedFilesPresentation" ;
@@ -1117,6 +1122,45 @@ const TimelineRowContent = memo(function TimelineRowContent({ row }: { row: Time
11171122 ) ;
11181123} ) ;
11191124
1125+ function UserVideoAttachment ( { file } : { readonly file : ChatFileAttachment } ) {
1126+ const ctx = use ( TimelineRowCtx ) ;
1127+ const asset = useMemo (
1128+ ( ) =>
1129+ file . downloadable === false
1130+ ? null
1131+ : buildAttachmentVideoAsset ( ctx . activeThreadEnvironmentId , file ) ,
1132+ [ ctx . activeThreadEnvironmentId , file . downloadable , file . id , file . mimeType , file . name ] ,
1133+ ) ;
1134+ const resource = asset ?. resource ?? null ;
1135+ const assetUrl = useAssetUrlState ( ctx . activeThreadEnvironmentId , resource ) ;
1136+ const refreshAssetUrl = useAssetUrlRefresh ( ctx . activeThreadEnvironmentId , resource ) ;
1137+ const src = assetUrl . _tag === "Success" ? assetUrl . url : ( file . previewUrl ?? null ) ;
1138+
1139+ if ( asset === null && src === null ) {
1140+ return (
1141+ < div className = "flex aspect-[4/3] w-full items-center justify-center rounded-lg border border-border/80 bg-black px-2 py-3 text-center text-[11px] text-white/70" >
1142+ { file . name }
1143+ </ div >
1144+ ) ;
1145+ }
1146+
1147+ return (
1148+ < MediaVideoPlayer
1149+ src = { src }
1150+ sourceFailed = {
1151+ file . previewUrl === undefined && resource !== null && assetUrl . _tag === "Failure"
1152+ }
1153+ label = { file . name }
1154+ preload = "visible"
1155+ className = "block aspect-[4/3] w-full"
1156+ videoClassName = "aspect-auto size-full rounded-lg border border-border/80"
1157+ stateClassName = "aspect-auto min-h-full rounded-lg border border-border/80 bg-black text-white"
1158+ onRetry = { asset ? refreshAssetUrl : undefined }
1159+ actionsSource = { asset ? { kind : "video" , name : file . name , src, asset } : undefined }
1160+ />
1161+ ) ;
1162+ }
1163+
11201164function UserTimelineRow ( { row } : { row : Extract < TimelineRow , { kind : "message" } > } ) {
11211165 const ctx = use ( TimelineRowCtx ) ;
11221166 // The attachment union has an open member, so guards (not literal type
@@ -1155,12 +1199,12 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
11551199 { regularImages . map ( ( image ) => (
11561200 < div
11571201 key = { image . id }
1158- className = "overflow-hidden rounded-lg border border-border/80 bg-background/70"
1202+ className = "aspect-[4/3] overflow-hidden rounded-lg border border-border/80 bg-background/70"
11591203 >
11601204 { image . previewUrl ? (
11611205 < button
11621206 type = "button"
1163- className = "h-full w-full cursor-zoom-in"
1207+ className = "block h-full w-full cursor-zoom-in"
11641208 aria-label = { `Preview ${ image . name } ` }
11651209 onClick = { ( ) => {
11661210 const preview = buildExpandedImagePreview ( regularImages , image . id ) ;
@@ -1171,7 +1215,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
11711215 < img
11721216 src = { image . previewUrl }
11731217 alt = { image . name }
1174- className = "block h-auto max-h-[220px] w -full object-cover"
1218+ className = "block size -full object-cover"
11751219 />
11761220 </ button >
11771221 ) : (
@@ -1182,21 +1226,7 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
11821226 </ div >
11831227 ) ) }
11841228 { userVideos . map ( ( file ) => (
1185- < div
1186- key = { file . id }
1187- className = "overflow-hidden rounded-lg border border-border/80 bg-black"
1188- >
1189- < button
1190- type = "button"
1191- disabled = { file . downloadable === false }
1192- className = "flex min-h-[72px] w-full cursor-zoom-in flex-col items-center justify-center gap-1 px-2 py-2 text-white disabled:cursor-default disabled:opacity-50"
1193- aria-label = { `Play ${ file . name } ` }
1194- onClick = { ( ) => ctx . onFileOpen ( file ) }
1195- >
1196- < PlayIcon className = "size-8 fill-current" />
1197- < span className = "max-w-full truncate text-[11px]" > { file . name } </ span >
1198- </ button >
1199- </ div >
1229+ < UserVideoAttachment key = { file . id } file = { file } />
12001230 ) ) }
12011231 </ div >
12021232 ) }
0 commit comments