@@ -212,17 +212,20 @@ async function createCurrentPageContextPart(): Promise<ChatPart> {
212212 throw new Error ( "Could not extract page content." ) ;
213213 }
214214
215+ const tabTitle = tab . title || page . title || "Current tab" ;
216+ const articleTitle = page . title ;
215217 const pageContext : ParsedPageContext = {
216218 ...page ,
217- title : page . title || tab . title || "Current tab" ,
219+ title : articleTitle || tabTitle ,
218220 url : page . url || tab . url ,
219221 faviconUrl : page . faviconUrl || tab . favIconUrl ,
220222 } ;
221223
222224 return {
223225 id : generateId ( ) ,
224226 type : "page-context" ,
225- title : pageContext . title ,
227+ title : tabTitle ,
228+ articleTitle,
226229 url : pageContext . url ,
227230 faviconUrl : pageContext . faviconUrl ,
228231 content : buildPageContextMarkdown ( pageContext ) ,
@@ -862,44 +865,14 @@ const ComposerContextBar: FC<ComposerContextBarProps> = ({
862865 onDetachContext,
863866} ) => {
864867 const label = contextError || tabContext ?. title || "Current tab" ;
865-
866- return (
867- < div
868- className = { [
869- "mr-3 flex min-w-0 max-w-[min(360px,calc(100%-120px))] items-center gap-1.5 rounded-lg bg-[#fffaf4]/80 px-1.5 py-1 pr-3 shadow-[0_6px_18px_rgba(64,48,31,0.06)] transition-colors" ,
870- contextAttached
871- ? "border border-solid border-[#d8cfbf]"
872- : "border border-dashed border-[#d8b18d]" ,
873- ] . join ( " " ) }
874- >
875- < div className = "flex h-6 w-6 shrink-0 items-center justify-center" >
876- { contextAttached ? (
877- < button
878- type = "button"
879- aria-label = "Remove attached context"
880- title = "Remove attached context"
881- className = "flex h-6 w-6 items-center justify-center rounded-md text-[#75695b] transition-colors hover:bg-[#f1e8da] hover:text-[#2f261f]"
882- onClick = { onDetachContext }
883- >
884- < X className = "size-3.5" />
885- </ button >
886- ) : (
887- < button
888- type = "button"
889- aria-label = "Add current tab context"
890- title = "Add current tab context"
891- disabled = { contextLoading || ! tabContext }
892- className = "flex h-6 w-6 items-center justify-center rounded-md text-[#8a7e70] transition-colors hover:bg-[#f1e8da] hover:text-[#2f261f] disabled:cursor-not-allowed disabled:opacity-60"
893- onClick = { onAttachContext }
894- >
895- { contextLoading ? (
896- < Loader2 className = "size-3.5 animate-spin" />
897- ) : (
898- < Plus className = "size-3.5" />
899- ) }
900- </ button >
901- ) }
902- </ div >
868+ const containerClassName = [
869+ "mr-3 flex min-w-0 max-w-[min(360px,calc(100%-120px))] items-center gap-1.5 rounded-lg bg-[#fffaf4]/80 px-1.5 py-1 pr-3 shadow-[0_6px_18px_rgba(64,48,31,0.06)] transition-colors" ,
870+ contextAttached
871+ ? "border border-solid border-[#d8cfbf]"
872+ : "border border-dashed border-[#d8b18d]" ,
873+ ] . join ( " " ) ;
874+ const tabContextDetails = (
875+ < >
903876 < TabFavicon
904877 faviconUrl = { tabContext ?. faviconUrl }
905878 muted = { ! contextAttached }
@@ -917,6 +890,48 @@ const ComposerContextBar: FC<ComposerContextBarProps> = ({
917890 >
918891 { label }
919892 </ span >
893+ </ >
894+ ) ;
895+
896+ if ( ! contextAttached ) {
897+ return (
898+ < button
899+ type = "button"
900+ aria-label = "Add current tab context"
901+ title = "Add current tab context"
902+ disabled = { contextLoading || ! tabContext }
903+ className = { [
904+ containerClassName ,
905+ "cursor-pointer text-left hover:bg-[#fff5e8] disabled:cursor-not-allowed disabled:opacity-70" ,
906+ ] . join ( " " ) }
907+ onClick = { onAttachContext }
908+ >
909+ < div className = "flex h-6 w-6 shrink-0 items-center justify-center rounded-md text-[#8a7e70]" >
910+ { contextLoading ? (
911+ < Loader2 className = "size-3.5 animate-spin" />
912+ ) : (
913+ < Plus className = "size-3.5" />
914+ ) }
915+ </ div >
916+ { tabContextDetails }
917+ </ button >
918+ ) ;
919+ }
920+
921+ return (
922+ < div className = { containerClassName } >
923+ < div className = "flex h-6 w-6 shrink-0 items-center justify-center" >
924+ < button
925+ type = "button"
926+ aria-label = "Remove attached context"
927+ title = "Remove attached context"
928+ className = "flex h-6 w-6 items-center justify-center rounded-md text-[#75695b] transition-colors hover:bg-[#f1e8da] hover:text-[#2f261f]"
929+ onClick = { onDetachContext }
930+ >
931+ < X className = "size-3.5" />
932+ </ button >
933+ </ div >
934+ { tabContextDetails }
920935 </ div >
921936 ) ;
922937} ;
0 commit comments